Fix conversions on default literals#37596
Conversation
d039e5d to
28a2b18
Compare
f1306f6 to
3176689
Compare
|
I'm investigating some test failures. Marking PR as "personal" for now. #Closed |
c9c8419 to
b498181
Compare
There was a problem hiding this comment.
@mavasani for review of the change to CustomDataFlowAnalysis.cs, DataFlowAnalyzer.cs and BasicBlockReachabilityDataFlowAnalyzer.cs.
For background, the comparison of default to an unconstrained type was improperly allowed (and interpreted as a comparison against null). With this PR, this becomes an error. #Resolved
There was a problem hiding this comment.
Hum, I just realized my fix is wrong :-( I'll take another look #Closed
There was a problem hiding this comment.
Yes, the intent is to allow the type parameter to be either a struct or class, and if it is default value then initialize it by invoking the GetEmptyAnalysisData API. What would be the recommended alternative here? #Resolved
There was a problem hiding this comment.
I see that you updated the comment on the abstract method GetCurrentAnalysisData, but did not change the override which may return null.
Can you change the override to _analysisData.GetBlockAnalysisData(basicBlock) ?? GetEmptyAnalysisData();? #Resolved
|
after this goes in I'll try to sync target-typed-new branch with 16.4p1. let me know if there's other considerations. thanks. #Closed |
0f8b9da to
9980615
Compare
|
@alrz Sounds good. Thanks! #Closed |
RikkiGibson
left a comment
There was a problem hiding this comment.
I read the diff from starting my last review to now. LGTM.
|
I've rebased to resolve conflict. |
|
@mavasani Did you have any other feedback? Thanks |
There was a problem hiding this comment.
Is the input source valid code now, hence CSharpReplaceDefaultLiteralCodeFixProvider is not triggered?
There was a problem hiding this comment.
No, case default: is still illegal. The behavior change here is a casualty of binding change: the compiler no longer tries to give default a type via conversion, so the IDE doesn't get a type to to drive the refactoring.
I took another look and managed to tweak that, which allowed to revert most of the IDE test changes. Thanks!
mavasani
left a comment
There was a problem hiding this comment.
Thanks, IDE changes LGTM!
| testData = new CompilationTestData(); | ||
| context.CompileExpression("default", DkmEvaluationFlags.None, ImmutableArray<Alias>.Empty, out error, testData); | ||
| Assert.Equal(error, "error CS8716: No target type was found for the default literal."); | ||
| Assert.Equal(error, "error CS8716: No target type was found found for the default literal."); |
There was a problem hiding this comment.
This is really what the test wants? Strange..
dotnet/roslyn#37596 includes a breaking change in the 5.0 branch. This function is intended to ensure reads happen from the array, so the test isn't strictly necessary. Fixes dotnet#865
dotnet/roslyn#37596 includes a breaking change in the 5.0 branch. This function is intended to ensure reads happen from the array, so the test isn't strictly necessary. Fixes #865
Since updating to Microsoft.CodeAnalysis 3.3.1, the default keyword is resolved to a vaule instead of the a default expression. Probably comes from dotnet/roslyn#37596
* Update to Microsoft.CodeAnalysis 3.3.1 This updates to the latest Microsoft.CodeAnalysis packages for C#8 support. Fixes the following error on a project that uses nullable reference types: Microsoft.DocAsCode.Exceptions.DocfxException: Unable to generate spec reference for !: ---> System.IO.InvalidDataException: Fail to parse id for symbol in namespace . at Microsoft.DocAsCode.Metadata.ManagedReference.YamlModelGenerator.AddSpecReference (Microsoft.CodeAnalysis.ISymbol symbol, System.Collections.Generic.IReadOnlyList`1[T] typeGenericParameters, System.Collections.Generic.IReadOnlyList`1[T] methodGenericParameters, System.Collections.Generic.Dictionary`2[TKey,TValue] references, Microsoft.DocAsCode.Metadata.ManagedReference.SymbolVisitorAdapter adapter) [0x0005e] in <27b606b838ab45b788854d5e45efa610>:0 at Microsoft.DocAsCode.Metadata.ManagedReference.SymbolVisitorAdapter.AddSpecReference (Microsoft.CodeAnalysis.ISymbol symbol, System.Collections.Generic.IReadOnlyList`1[T] typeGenericParameters, System.Collections.Generic.IReadOnlyList`1[T] methodGenericParameters) [0x00000] in <27b606b838ab45b788854d5e45efa610>:0 * Fix TODO for space after tuple Since updating Microsoft.CodeAnalysis to 3.3.1, the automatic formatting for tuples in C# has been fixed, so update tests accordingly. dotnet/roslyn#29405 * Fix TestCSharpFeature_Default_7_1Class Since updating to Microsoft.CodeAnalysis 3.3.1, the default keyword is resolved to a vaule instead of the a default expression. Probably comes from dotnet/roslyn#37596
This PR fixes two problems with
defaultliteral (from C# 7.1):nullliteral to a nullable value type), so I'm introducing a "default literal conversion" (conversion from thedefaultliteral to any type)defaultwas getting converted, we would incorrectly give it a natural type. This PR follows Neal's recent PRs by having aBoundDefaultExpressionand aBoundConvertedDefaultExpression. This affects some scenariosdefault as TClass: becomes an error$"{default}": useobjectas target-type for expressions that don't have a natural typeusing (default) ...: becomes an errorAlso, during return type inference of lambdas, expressions are neither required to be target-typed or to have a natural type.
x == defaultwill no longer bind as object equality.But I reverted the part of this PR which affected public APIs (
.Typein particular) because it had significant effect on the IDE (and therefore likely other consumers).Fixes #31029
Fixes #18609
Fixes #35684 and #36492 (incorrectly emitting
defaultasnull, missing error, fix is a breaking change)Fixes #30384
Relates to #22125
Opened issue tracking spec changes: #37821
Update: this breaking change was later adjusted in 16.4p2.