Dictionary expressions: initial binding and lowering support#76257
Dictionary expressions: initial binding and lowering support#76257cston merged 17 commits intodotnet:features/dictionary-expressionsfrom
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
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 11)
| { | ||
| return Conversion.NoConversion; | ||
| } | ||
| // This should be conversion from type rather than conversion |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Consider some examples with complex sub-flow (like ternaries or switch expressions) in the key and value positions. #Resolved
Binding and lowering for
IDictionary<K, V>andIReadOnlyDictionary<K, V>target types.See proposals/dictionary-expressions.md
Relates to test plan #76310