提交 478fb6af 编写于 作者: P pgavlin

Fix a bug in the adjusted Color Color code that failed to correctly account...

Fix a bug in the adjusted Color Color code that failed to correctly account for instance members on base types.
***NO_CI***
 (changeset 1404916)
上级 4754991d
......@@ -597,7 +597,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' <summary>
''' Adjusts receiver of a call or a member access if the receiver is an
''' ambiguous BoundTypeOrValueExpression. This can only hapen if the
''' ambiguous BoundTypeOrValueExpression. This can only happen if the
''' receiver is the LHS of a member access expression in which the
''' RHS cannot be resolved (i.e. the RHS is an error or a late-bound
''' invocation/access).
......@@ -2387,7 +2387,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim boundType = Me.BindNamespaceOrTypeExpression(node, typeDiagnostics)
If boundType.Type = leftType Then
Dim err As ERRID = Nothing
If isInstanceMember AndAlso (Not CanAccessMe(implicitReference:=True, errorId:=err) OrElse ContainingType <> leftSymbol.ContainingType) Then
If isInstanceMember AndAlso (Not CanAccessMe(implicitReference:=True, errorId:=err) OrElse Not ContainingType.IsOrDerivedFrom(leftSymbol.ContainingType, Nothing)) Then
diagnostics.AddRange(typeDiagnostics)
leftDiagnostics.Free()
......
......@@ -3422,5 +3422,49 @@ End Class </file>
CompileAndVerify(compilation, expectedOutput:="42")
End Sub
<WorkItem(1114969, "DevDiv")>
<Fact()>
Public Sub Bug1114969()
Dim compilation = CompilationUtils.CreateCompilationWithMscorlibAndVBRuntime(
<compilation>
<file name="a.vb">
Class Color
Public Function M() As Integer
Return 42
End Function
End Class
Class Base
Protected Dim Color As Color = New Color()
End Class
Class Derived
Inherits Base
Sub M()
System.Console.WriteLine(Color.M())
End Sub
Shared Sub Main()
Dim d = New Derived()
d.M()
End Sub
End Class </file>
</compilation>, TestOptions.ReleaseExe)
Dim tree = compilation.SyntaxTrees(0)
Dim model = compilation.GetSemanticModel(tree)
Dim node = tree.GetRoot().DescendantNodes.OfType(Of MemberAccessExpressionSyntax)().Select(Function(e) e.Expression).Where(Function(e) e.ToString() = "Color").Single()
Dim symbol = model.GetSymbolInfo(node).Symbol
Assert.NotNull(symbol)
Assert.Equal("Color", symbol.Name)
Assert.Equal(SymbolKind.Field, symbol.Kind)
AssertTheseDiagnostics(compilation, <expected></expected>)
CompileAndVerify(compilation, expectedOutput:="42")
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册