提交 1128fb3d 编写于 作者: G Gen Lu

Fix exception when trying to introduce a variable for expression of undeclared type

上级 95619c56
......@@ -5930,5 +5930,23 @@ void Test()
await TestInRegularAndScriptAsync(code, expected, index: 1);
}
[WorkItem(30207, "http://github.com/dotnet/roslyn/issues/30207")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
public async Task TestExpressionOfUndeclaredType()
{
var code =
@"class C
{
void Test()
{
A[] array = [|A|].Foo();
foreach (A a in array)
{
}
}
}";
await TestMissingAsync(code);
}
}
}
......@@ -3166,5 +3166,17 @@ End Class
"
Await TestInRegularAndScriptAsync(source, expected, index:=1)
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)>
<WorkItem(30207, "https://github.com/dotnet/roslyn/issues/30207")>
Public Async Function TestExpressionOfUndeclaredType() As Task
Dim source = "
Class C
Sub Test
Dim array As A() = [|A|].Bar()
End Sub
End Class"
Await TestMissingAsync(source)
End Function
End Class
End Namespace
......@@ -70,6 +70,12 @@ public State(TService service, SemanticDocument document)
return false;
}
var expressionType = this.Document.SemanticModel.GetTypeInfo(this.Expression, cancellationToken).Type;
if (expressionType is IErrorTypeSymbol)
{
return false;
}
var containingType = this.Expression.AncestorsAndSelf()
.Select(n => this.Document.SemanticModel.GetDeclaredSymbol(n, cancellationToken))
.OfType<INamedTypeSymbol>()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册