Skip to content

Commit

Permalink
Don't try to add [NotNullWhen] attributes to local functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Jun 13, 2020
1 parent 695a759 commit e58a738
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion NullabilityInference/NodeBuildingSyntaxVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public override TypeWithNode VisitParameter(ParameterSyntax node)
parameterTypes.Add(symbol, type);
typeSystem.AddSymbolType(symbol, type);

if (symbol.RefKind == RefKind.Out && (symbol.ContainingSymbol as IMethodSymbol)?.EffectiveReturnType().SpecialType == SpecialType.System_Boolean) {
if (symbol.RefKind == RefKind.Out && CanUseOutParamFlow(symbol.ContainingSymbol as IMethodSymbol)) {
typeSystem.RegisterOutParamFlowNodes(symbol);
}
}
Expand All @@ -302,6 +302,19 @@ public override TypeWithNode VisitParameter(ParameterSyntax node)
return typeSystem.VoidType;
}

private bool CanUseOutParamFlow(IMethodSymbol? method)
{
if (method == null)
return false;
if (method.ContainingSymbol is IMethodSymbol) {
var compilation = (CSharpCompilation)semanticModel.Compilation;
if (compilation.LanguageVersion <= LanguageVersion.CSharp8)
return false; // C# 8 does not support attributes on local function parameters
}
return method.EffectiveReturnType().SpecialType == SpecialType.System_Boolean;
}


public override TypeWithNode VisitNameMemberCref(NameMemberCrefSyntax node)
{
Mapping.AddCrefNode(node);
Expand Down

0 comments on commit e58a738

Please sign in to comment.