提交 508c2290 编写于 作者: T Ty Overby

Bail in GetDependenceChain if typesymbol isn't found (#10331)

harden both DetectTypeCircularity and GetDependenceChain
上级 4eb39ed0
......@@ -2101,6 +2101,32 @@ void M(int x)
VerifySpeculativeSemanticModelForMethodBody(blockStatement, speculativeModel);
}
[Fact()]
[WorkItem(10211, "https://github.com/dotnet/roslyn/issues/10211")]
public void GetDependenceChainRegression_10211_working()
{
var compilation = CreateCompilation(@"
class Parent {}
class Child : Parent {}
");
var semanticModel = compilation.GetSemanticModel(compilation.SyntaxTrees[0]);
// Ensure that we don't crash here.
semanticModel.GetMethodBodyDiagnostics();
}
[Fact()]
[WorkItem(10211, "https://github.com/dotnet/roslyn/issues/10211")]
public void GetDependenceChainRegression_10211()
{
var compilation = CreateCompilation(@"
class Child : Parent {}
class Parent {}
");
var semanticModel = compilation.GetSemanticModel(compilation.SyntaxTrees[0]);
// Ensure that we don't crash here.
semanticModel.GetMethodBodyDiagnostics();
}
private static void VerifySpeculativeSemanticModelForMethodBody(BlockSyntax blockStatement, SemanticModel speculativeModel)
{
var localDecl = (LocalDeclarationStatementSyntax)blockStatement.Statements[0];
......
......@@ -187,10 +187,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Private Function GetDependenceChain(visited As HashSet(Of Symbol),
root As SourceNamedTypeSymbol,
current As TypeSymbol) As ConsList(Of DependencyDesc)
Debug.Assert(root.OriginalDefinition = root, "root must not be a substitution")
If current Is Nothing Then
If current Is Nothing OrElse current.Kind = SymbolKind.ErrorType Then
Return Nothing
End If
......
......@@ -2230,8 +2230,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return True
End If
' We can not get the relative order of a declaration without a source location
If typeToTest.Locations.IsEmpty Then
Return True
End If
' We use simple comparison based on source location
Debug.Assert(typeToTest.Locations.Length > 0)
Dim typeToTestLocation = typeToTest.Locations(0)
Debug.Assert(Me.Locations.Length > 0)
......
......@@ -4061,6 +4061,48 @@ End Class
Assert.Equal(2, treeErrs.Length())
End Sub
<Fact()>
<WorkItem(10211, "https://github.com/dotnet/roslyn/issues/10211")>
Public Sub GetDependenceChainRegression_10211_working()
Dim source = <compilation>
<file name="a.vb"><![CDATA[
Public Class Parent
End Class
Public Class Child
Inherits Parent
End Class
]]></file>
</compilation>
Dim compilation = CreateCompilationWithoutReferences(source)
Dim semanticModel = compilation.GetSemanticModel(compilation.SyntaxTrees(0))
' Ensuring that this doesn't throw
semanticModel.GetMethodBodyDiagnostics()
End Sub
<Fact()>
<WorkItem(10211, "https://github.com/dotnet/roslyn/issues/10211")>
Public Sub GetDependenceChainRegression_10211()
Dim source = <compilation>
<file name="a.vb"><![CDATA[
Public Class Child
Inherits Parent
End Class
Public Class Parent
End Class
]]></file>
</compilation>
Dim compilation = CreateCompilationWithoutReferences(source)
Dim semanticModel = compilation.GetSemanticModel(compilation.SyntaxTrees(0))
' Ensuring that this doesn't throw
semanticModel.GetMethodBodyDiagnostics()
End Sub
<WorkItem(859721, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/859721")>
<Fact()>
Public Sub TestMethodBodyDiagnostics()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册