-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dictionary expressions: initial binding and lowering support #76257
Dictionary expressions: initial binding and lowering support #76257
Conversation
5da632a
to
74a425d
Compare
6b7dd35
to
767c1c9
Compare
1fba2ac
to
006323a
Compare
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit3/Semantics/DictionaryExpressionTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit3/Semantics/DictionaryExpressionTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with review pass (iteration 11)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 14)
@@ -235,6 +259,8 @@ internal Conversion GetCollectionExpressionSpreadElementConversion( | |||
{ | |||
return Conversion.NoConversion; | |||
} | |||
// This should be conversion from type rather than conversion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PROTOTYPE
comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using conversion from expression rather than conversion from type is a bug. The one case that I'm aware of where this is observable is when the spread element type is dynamic
. Unfortunately, fixing this would be a breaking change for that case.
For instance, the following is currently allowed but would be an error when using conversion from type:
dynamic[] x = [1, 2, 3];
int[] y = [..x];
I could log a bug and reference that here if that seems useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the comment to include the example.
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs
Show resolved
Hide resolved
{ | ||
string source = """ | ||
using System.Collections.Generic; | ||
IDictionary<int, string> d = [1:"one"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider testing var x = [1:"one"];
as well. #Resolved
// (12,16): error CS9215: Collection expression type 'Dictionary<int, string>' must have an instance or extension method 'Add' that can be called with a single argument. | ||
// return [1:"one", x, ..y]; | ||
Diagnostic(ErrorCode.ERR_CollectionExpressionMissingAdd, @"[1:""one"", x, ..y]").WithArguments("System.Collections.Generic.Dictionary<int, string>").WithLocation(12, 16), | ||
// (12,17): error CS9268: Collection expression type 'Dictionary<int, string>' does not support key-value pair elements. | ||
// return [1:"one", x, ..y]; | ||
Diagnostic(ErrorCode.ERR_CollectionExpressionKeyValuePairNotSupported, @"1:""one""").WithArguments("System.Collections.Generic.Dictionary<int, string>").WithLocation(12, 17)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why there are errors here. Am I missing something about the feature? I would expect all of these to be fine. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR implements support for dictionary interface target types only. It does not include support for concrete types such as Dictionary<K, V>
.
} | ||
|
||
[Fact] | ||
public void EvaluationOrder_01() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider some examples with complex sub-flow (like ternaries or switch expressions) in the key and value positions. #Resolved
5439dd5
into
dotnet:features/dictionary-expressions
Binding and lowering for
IDictionary<K, V>
andIReadOnlyDictionary<K, V>
target types.See proposals/dictionary-expressions.md
Relates to test plan #76310