Skip to content

Commit

Permalink
The annotation on the output type is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed Nov 10, 2021
1 parent a128b59 commit f856097
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 144 deletions.
9 changes: 6 additions & 3 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6730,9 +6730,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureListPattern" xml:space="preserve">
<value>list pattern</value>
</data>
<data name="IDS_FeatureLengthPattern" xml:space="preserve">
<value>length pattern</value>
</data>
<data name="ERR_UnsupportedTypeForListPattern" xml:space="preserve">
<value>List patterns may not be used for a value of type '{0}'.</value>
</data>
Expand Down Expand Up @@ -6893,4 +6890,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureNewLinesInInterpolations" xml:space="preserve">
<value>newlines in interpolations</value>
</data>
<data name="WRN_AnnotationOnSliceReturnType" xml:space="preserve">
<value>The annotation on the output type '{0}' is ignored.</value>
</data>
<data name="WRN_AnnotationOnSliceReturnType_Title" xml:space="preserve">
<value>The annotation on the output type is ignored.</value>
</data>
</root>
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,8 @@ internal enum ErrorCode
ERR_UnsupportedTypeForSlicePattern,
ERR_MisplacedSlicePattern,

WRN_AnnotationOnSliceReturnType = 8978,

#endregion

// Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd)
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static ErrorFacts()
nullableWarnings.Add(GetId(ErrorCode.WRN_ParameterDisallowsNull));
nullableWarnings.Add(GetId(ErrorCode.WRN_ParameterNotNullIfNotNull));
nullableWarnings.Add(GetId(ErrorCode.WRN_ReturnNotNullIfNotNull));
nullableWarnings.Add(GetId(ErrorCode.WRN_AnnotationOnSliceReturnType));

NullableWarnings = nullableWarnings.ToImmutable();
}
Expand Down Expand Up @@ -486,6 +487,7 @@ internal static int GetWarningLevel(ErrorCode code)
case ErrorCode.WRN_InterpolatedStringHandlerArgumentAttributeIgnoredOnLambdaParameters:
case ErrorCode.WRN_CompileTimeCheckedOverflow:
case ErrorCode.WRN_MethGrpToNonDel:
case ErrorCode.WRN_AnnotationOnSliceReturnType:
return 1;
default:
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ public PossiblyConditionalState Clone()
var output = new BoundDagTemp(e.Syntax, type.Type, e);
var outputSlot = makeDagTempSlot(type, output);
Debug.Assert(outputSlot > 0);
ignoreAnnotationAndReport(outputSlot, type, ref this.State, e);
addToTempMap(output, outputSlot, type.Type);
break;
}
Expand Down Expand Up @@ -719,6 +720,18 @@ public PossiblyConditionalState Clone()
nodeStateMap.Free();
return labelStateMap;

void ignoreAnnotationAndReport(int outputSlot, TypeWithAnnotations outputType, ref LocalState state, BoundDagSliceEvaluation e)
{
if (PossiblyNullableType(outputType.Type))
{
if (state[outputSlot] == NullableFlowState.MaybeNull)
{
ReportDiagnostic(ErrorCode.WRN_AnnotationOnSliceReturnType, e.Syntax, outputType);
state[outputSlot] = NullableFlowState.NotNull;
}
}
}

void learnFromNonNullTest(int inputSlot, ref LocalState state)
{
if (stateWhenNotNullOpt is { } stateWhenNotNull && inputSlot == originalInputSlot)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f856097

Please sign in to comment.