Skip to content

Commit

Permalink
Disallow applying RequiresLocationAttribute to parameters in source (
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored Jul 7, 2023
1 parent e3ed9a4 commit 644742d
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5878,6 +5878,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_OutAttrOnInParam" xml:space="preserve">
<value>An in parameter cannot have the Out attribute.</value>
</data>
<data name="ERR_OutAttrOnRefReadonlyParam" xml:space="preserve">
<value>A ref readonly parameter cannot have the Out attribute.</value>
</data>
<data name="ICompoundAssignmentOperationIsNotCSharpCompoundAssignment" xml:space="preserve">
<value>{0} is not a valid C# compound assignment operation</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,7 @@ internal enum ErrorCode
ERR_UnsupportedPrimaryConstructorParameterCapturingRefAny = 9136,

ERR_RefReadOnlyWrongOrdering = 9501, // PROTOTYPE: Pack numbers
ERR_OutAttrOnRefReadonlyParam = 9520,

#endregion

Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2311,6 +2311,7 @@ internal static bool IsBuildOnlyDiagnostic(ErrorCode code)
case ErrorCode.ERR_ConstantValueOfTypeExpected:
case ErrorCode.ERR_UnsupportedPrimaryConstructorParameterCapturingRefAny:
case ErrorCode.ERR_RefReadOnlyWrongOrdering:
case ErrorCode.ERR_OutAttrOnRefReadonlyParam:
return false;
default:
// NOTE: All error codes must be explicitly handled in this switch statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttribut
else if (ReportExplicitUseOfReservedAttributes(in arguments,
ReservedAttributes.DynamicAttribute |
ReservedAttributes.IsReadOnlyAttribute |
// PROTOTYPE: RequiresLocationAttribute
ReservedAttributes.RequiresLocationAttribute |
ReservedAttributes.IsUnmanagedAttribute |
ReservedAttributes.IsByRefLikeAttribute |
ReservedAttributes.TupleElementNamesAttribute |
Expand Down Expand Up @@ -1412,6 +1412,13 @@ internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttrib
diagnostics.Add(ErrorCode.ERR_OutAttrOnInParam, this.GetFirstLocation());
}
break;
case RefKind.RefReadOnlyParameter:
if (data.HasOutAttribute)
{
// error: A ref readonly parameter cannot have the Out attribute.
diagnostics.Add(ErrorCode.ERR_OutAttrOnRefReadonlyParam, this.GetFirstLocation());
}
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ internal enum ReservedAttributes
RequiredMemberAttribute = 1 << 11,
ScopedRefAttribute = 1 << 12,
RefSafetyRulesAttribute = 1 << 13,
RequiresLocationAttribute = 1 << 14,
}

internal bool ReportExplicitUseOfReservedAttributes(in DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments, ReservedAttributes reserved)
Expand All @@ -1449,6 +1450,10 @@ internal bool ReportExplicitUseOfReservedAttributes(in DecodeWellKnownAttributeA
reportExplicitUseOfReservedAttribute(attribute, arguments, AttributeDescription.IsReadOnlyAttribute))
{
}
else if ((reserved & ReservedAttributes.RequiresLocationAttribute) != 0 &&
reportExplicitUseOfReservedAttribute(attribute, arguments, AttributeDescription.RequiresLocationAttribute))
{
}
else if ((reserved & ReservedAttributes.IsUnmanagedAttribute) != 0 &&
reportExplicitUseOfReservedAttribute(attribute, arguments, AttributeDescription.IsUnmanagedAttribute))
{
Expand Down
5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

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

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf

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

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf

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

Loading

0 comments on commit 644742d

Please sign in to comment.