Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add ConditionalWeakTable.AddOrUpdate to contract and add tests#14661

Merged
safern merged 1 commit into
dotnet:masterfrom
safern:ConditionalWeakTable
Dec 21, 2016
Merged

Add ConditionalWeakTable.AddOrUpdate to contract and add tests#14661
safern merged 1 commit into
dotnet:masterfrom
safern:ConditionalWeakTable

Conversation

@safern
Copy link
Copy Markdown
Member

@safern safern commented Dec 21, 2016

Fixes #8429
Add test and update contract for pull dotnet/coreclr#8490

/cc @jkotas @stephentoub

@safern safern added api-approved API was approved in API review, it can be implemented area-System.Runtime.CompilerServices labels Dec 21, 2016
@safern safern added this to the 2.0.0 milestone Dec 21, 2016
@safern safern self-assigned this Dec 21, 2016
@safern
Copy link
Copy Markdown
Member Author

safern commented Dec 21, 2016

Thanks for reviewing @jkotas :)

@safern safern merged commit 23072f4 into dotnet:master Dec 21, 2016
@safern safern deleted the ConditionalWeakTable branch December 21, 2016 20:14
@karelz karelz removed the api-approved API was approved in API review, it can be implemented label Dec 21, 2016
@karelz
Copy link
Copy Markdown
Member

karelz commented Dec 21, 2016

It fixes #8429 (which was api-approved).
@safern please don't use api-approved label directly, leave it for API review group ;-)

@safern
Copy link
Copy Markdown
Member Author

safern commented Dec 21, 2016

Sounds good :) @karelz

Assert.True(cwt.TryGetValue(key, out value));
Assert.Equal(value, "value1");
Assert.Equal(value, cwt.GetOrCreateValue(key));
Assert.Equal(value, cwt.GetValue(key, k => "value1"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert isn't necessarily testing what you want it to test. GetValue will look up key and return its value if it exists; if it doesn't exist, it'll call the specified lambda to create the value for the key, add it to the table, and then return that added value. But the value returned from the lambda is the same as the one previously stored and expected for the key; if there was a bug that caused GetValue to invoke the lambda even if the key was in the table, this assert would still pass. The lambda should really return some other value.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants