Fix AttributeSemanticModel assert.

上级 dea653e1
......@@ -157,7 +157,7 @@ protected virtual NullableWalker.SnapshotManager GetSnapshotManager()
internal ImmutableDictionary<Symbol, Symbol> GetRemappedSymbols()
{
EnsureNullabilityAnalysisPerformedIfNecessary();
Debug.Assert(_lazyRemappedSymbols is object || !Compilation.NullableSemanticAnalysisEnabled);
Debug.Assert(_lazyRemappedSymbols is object || this is AttributeSemanticModel || !Compilation.NullableSemanticAnalysisEnabled);
return _lazyRemappedSymbols;
}
......
......@@ -3597,7 +3597,6 @@ class D<T>
var root = syntaxTree.GetRoot();
var model = comp.GetSemanticModel(syntaxTree);
var lambda = root.DescendantNodes().OfType<LambdaExpressionSyntax>().First();
var lambdaSymbol = model.GetSymbolInfo(lambda).Symbol;
var localFunction = lambda.DescendantNodes().OfType<LocalFunctionStatementSyntax>().First();
......@@ -3607,5 +3606,39 @@ class D<T>
var typeParameters = localFunctionSymbol.TypeParameters[0];
Assert.Same(localFunctionSymbol, typeParameters.ContainingSymbol);
}
[Fact]
public void SpeculativeModel_InAttribute()
{
var source = @"
using System;
[AttributeUsage(AttributeTargets.ReturnValue)]
class Attr : Attribute
{
public Attr(string Test) {}
}
class Test
{
const string Constant = ""Test"";
[return: Attr(""Test"")]
void M() {}
}
";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
var syntaxTree = comp.SyntaxTrees[0];
var root = syntaxTree.GetRoot();
var model = comp.GetSemanticModel(syntaxTree);
var attributeUsage = root.DescendantNodes().OfType<AttributeSyntax>().ElementAt(1);
var newAttributeUsage = SyntaxFactory.Attribute(SyntaxFactory.ParseName("Attr"), SyntaxFactory.ParseAttributeArgumentList("(Constant)"));
Assert.True(model.TryGetSpeculativeSemanticModel(attributeUsage.SpanStart, newAttributeUsage, out var specModel));
Assert.NotNull(specModel);
var symbolInfo = specModel.GetSymbolInfo(newAttributeUsage.ArgumentList.Arguments[0].Expression);
Assert.Equal(SpecialType.System_String, ((IFieldSymbol)symbolInfo.Symbol).Type.SpecialType);
}
}
}
......@@ -8220,14 +8220,16 @@ interface IFoo<T>
class A : [|IFoo<int>|]
{{
public int Bar(int bar)
[return: NotNull]
public int Bar([DisallowNull] int bar)
{{
throw new NotImplementedException();
throw new System.NotImplementedException();
}}
public int Baz(int bar)
[return: MaybeNull]
public int Baz([AllowNull] int bar)
{{
throw new NotImplementedException();
throw new System.NotImplementedException();
}}
}}");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册