Fix inference when tuple names differ#25738
Conversation
|
|
||
| var tree = comp.SyntaxTrees.First(); | ||
| var model = comp.GetSemanticModel(tree); | ||
| var varType = tree.GetCompilationUnitRoot().DescendantNodes().OfType<LocalDeclarationStatementSyntax>().Single().Declaration.Type; |
There was a problem hiding this comment.
var varType [](start = 12, length = 11)
it is hard to reason what this node is. #Closed
| var tree = comp.SyntaxTrees.First(); | ||
| var model = comp.GetSemanticModel(tree); | ||
| var varType = tree.GetCompilationUnitRoot().DescendantNodes().OfType<LocalDeclarationStatementSyntax>().Single().Declaration.Type; | ||
| Assert.Equal("IResult<System.Int32>", model.GetTypeInfo(varType).Type.ToTestDisplayString()); |
There was a problem hiding this comment.
GetTypeInfo [](start = 56, length = 11)
It we are testing method type argument inference, why not assert the method symbol? #Closed
| var tree = comp.SyntaxTrees.First(); | ||
| var model = comp.GetSemanticModel(tree); | ||
| var varType = tree.GetCompilationUnitRoot().DescendantNodes().OfType<LocalDeclarationStatementSyntax>().Single().Declaration.Type; | ||
| Assert.Equal("IResult<System.Int32>", model.GetTypeInfo(varType).Type.ToTestDisplayString()); |
There was a problem hiding this comment.
Assert.Equal("IResult<System.Int32>", model.GetTypeInfo(varType).Type.ToTestDisplayString()); [](start = 12, length = 93)
Same comments #Closed
|
|
||
| public class Class1 | ||
| { | ||
| public void Test1(IDo<(int, int)> impl) |
There was a problem hiding this comment.
(int, int) [](start = 26, length = 10)
Consider also testing scenario when there are names here and they do not match those specified in a lambda #Closed
| Dim nodes = tree.GetCompilationUnitRoot().DescendantNodes() | ||
| Dim case3 = nodes.OfType(Of LocalDeclarationStatementSyntax)().Single().Declarators.Single().Names.Single() | ||
|
|
||
| Assert.Equal("case3 As IResult(Of System.Int32)", model.GetDeclaredSymbol(case3).ToTestDisplayString()) |
There was a problem hiding this comment.
Assert.Equal("case3 As IResult(Of System.Int32)", model.GetDeclaredSymbol(case3).ToTestDisplayString()) [](start = 12, length = 103)
Same comments #Closed
|
Done with review pass (iteration 1) #Closed |
|
@jaredpar for ask-mode approval for 15.7. Thanks The CI errors are not related to this PR (PDBUsingTests issue) and I'll re-run tests once the workaround is merged. |
|
approved |
|
test windows_debug_unit32_prtest please |
|
test windows_release_unit64_prtest please |
|
@dotnet/roslyn-infrastructure FYI I'll re-run |
|
test windows_debug_unit32_prtest please |
…features/dataflow * dotnet/dev15.7.x: Fix inference when tuple names differ (dotnet#25738) Avoid crash with 'new ref[]' (dotnet#25505) Skip some PDBUsingTests tests to unblock CI (dotnet#25753) Disable Spanish queue Tuple equality: Optimize cases where nullable always has value (dotnet#25644) Bump prerelease version to beta4 Fix failure to initialize RemoteWorkspace in the out-of-process host remove whitespace Removing package dependency for Microsoft.VisualStudio.Text.UI.Wpf in EditorFeatures Removing package dependency for Microsoft.VisualStudio.Text.UI.Wpf in CSharpEditorFeatures
Customer scenario
Use a lambda in a method type inference, but have the element names between the lambda and the
Func<... tuple ...>differ. This will fail the inference.There is a similar bug with difference in dynamic-ness (ie.
dynamicvs.object), which this PR also fixes.Bugs this fixes
Fixes #24781
Workarounds, if any
Specify type arguments to avoid relying on type inference.
Risk
Performance impact
Low. One line fix.
Is this a regression from a previous update?
No.
Root cause analysis
This bug has been there since the tuples feature shipped. It stems from using the
==comparison between type symbols (which compares everything), instead of theEqualsmethod with comparison options.We have an issue to remove usage of this
==(and!=) in the compiler code: #22067How was the bug found?
Reported by customer.