Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get CallerArgumentExpression ready #54839

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,6 @@ private TypedConstant GetDefaultValueArgument(ParameterSymbol parameter, Attribu
getCallerArgumentArgumentIndex(parameter, argumentsToParams) is int argumentIndex && argumentIndex > -1 && argumentIndex < argumentsCount)
{
Debug.Assert(argumentsCount <= syntax.ArgumentList.Arguments.Count);
CheckFeatureAvailability(syntax.ArgumentList, MessageID.IDS_FeatureCallerArgumentExpression, diagnostics);
parameterType = GetSpecialType(SpecialType.System_String, diagnostics, syntax);
kind = TypedConstantKind.Primitive;
defaultValue = syntax.ArgumentList.Arguments[argumentIndex].Expression.ToString();
Expand Down
2 changes: 0 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,8 +1388,6 @@ BoundExpression bindDefaultArgument(SyntaxNode syntax, ParameterSymbol parameter
else if (callerSourceLocation is object && getArgumentIndex(parameter.CallerArgumentExpressionParameterIndex, argsToParamsOpt) is int argumentIndex &&
argumentIndex > -1 && argumentIndex < argumentsCount)
{
CheckFeatureAvailability(syntax, MessageID.IDS_FeatureCallerArgumentExpression, diagnostics);

var argument = argumentsBuilder[argumentIndex];
defaultValue = new BoundLiteral(syntax, ConstantValue.Create(argument.Syntax.ToString()), Compilation.GetSpecialType(SpecialType.System_String)) { WasCompilerGenerated = true };
}
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6706,9 +6706,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="WRN_CallerArgumentExpressionAttributeSelfReferential_Title" xml:space="preserve">
<value>The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-refential.</value>
</data>
<data name="IDS_FeatureCallerArgumentExpression" xml:space="preserve">
<value>caller argument expression</value>
</data>
<data name="IDS_FeatureSealedToStringInRecord" xml:space="preserve">
<value>sealed ToString in record</value>
</data>
Expand Down
18 changes: 8 additions & 10 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,16 +1981,14 @@ internal enum ErrorCode
ERR_FileScopedAndNormalNamespace = 8955,
ERR_FileScopedNamespaceNotBeforeAllMembers = 8956,
ERR_NoImplicitConvTargetTypedConditional = 8957,

// PROTOTYPE: Compact these before merge
WRN_CallerArgumentExpressionParamForUnconsumedLocation = 9000,
ERR_NoConversionForCallerArgumentExpressionParam = 9001,
WRN_CallerLineNumberPreferredOverCallerArgumentExpression = 9002,
WRN_CallerFilePathPreferredOverCallerArgumentExpression = 9003,
WRN_CallerMemberNamePreferredOverCallerArgumentExpression = 9004,
WRN_CallerArgumentExpressionAttributeHasInvalidParameterName = 9005,
ERR_BadCallerArgumentExpressionParamWithoutDefaultValue = 9006,
WRN_CallerArgumentExpressionAttributeSelfReferential = 9007,
WRN_CallerArgumentExpressionParamForUnconsumedLocation = 8958,
ERR_NoConversionForCallerArgumentExpressionParam = 8959,
WRN_CallerLineNumberPreferredOverCallerArgumentExpression = 8960,
WRN_CallerFilePathPreferredOverCallerArgumentExpression = 8961,
WRN_CallerMemberNamePreferredOverCallerArgumentExpression = 8962,
WRN_CallerArgumentExpressionAttributeHasInvalidParameterName = 8963,
ERR_BadCallerArgumentExpressionParamWithoutDefaultValue = 8964,
WRN_CallerArgumentExpressionAttributeSelfReferential = 8965,

#endregion

Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ internal enum MessageID
IDS_FeatureLineSpanDirective = MessageBase + 12807,
IDS_FeatureImprovedInterpolatedStrings = MessageBase + 12808,
IDS_FeatureFileScopedNamespace = MessageBase + 12809,
// PROTOTYPE: compact before merge
IDS_FeatureCallerArgumentExpression = MessageBase + 13000,
}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -347,7 +345,6 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)

// C# 10.0 features.
case MessageID.IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction: // semantic check
case MessageID.IDS_FeatureCallerArgumentExpression: // semantic check
case MessageID.IDS_FeatureSealedToStringInRecord: // semantic check
case MessageID.IDS_FeatureImprovedInterpolatedStrings: // semantic check
case MessageID.IDS_FeatureRecordStructs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,47 +1071,47 @@ private void ValidateCallerArgumentExpressionAttribute(AttributeSyntax node, CSh

if (!IsValidCallerInfoContext(node))
{
// CS9000: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it applies to a
// CS8958: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it applies to a
// member that is used in contexts that do not allow optional arguments
diagnostics.Add(ErrorCode.WRN_CallerArgumentExpressionParamForUnconsumedLocation, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
}
else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
{
// CS9001: CallerArgumentExpressionAttribute cannot be applied because there are no standard conversions from type '{0}' to type '{1}'
// CS8959: CallerArgumentExpressionAttribute cannot be applied because there are no standard conversions from type '{0}' to type '{1}'
TypeSymbol stringType = compilation.GetSpecialType(SpecialType.System_String);
diagnostics.Add(ErrorCode.ERR_NoConversionForCallerArgumentExpressionParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
}
else if (!HasExplicitDefaultValue && !ContainingSymbol.IsPartialImplementation()) // attribute applied to parameter without default
{
// Unconsumed location checks happen first, so we require a default value.

// CS9006: The CallerArgumentExpressionAttribute may only be applied to parameters with default values
// CS8964: The CallerArgumentExpressionAttribute may only be applied to parameters with default values
diagnostics.Add(ErrorCode.ERR_BadCallerArgumentExpressionParamWithoutDefaultValue, node.Name.Location);
}
else if (IsCallerLineNumber)
{
// CS9002: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is overridden by the CallerLineNumberAttribute.
// CS8960: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is overridden by the CallerLineNumberAttribute.
diagnostics.Add(ErrorCode.WRN_CallerLineNumberPreferredOverCallerArgumentExpression, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
}
else if (IsCallerFilePath)
{
// CS9003: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is overridden by the CallerFilePathAttribute.
// CS8961: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is overridden by the CallerFilePathAttribute.
diagnostics.Add(ErrorCode.WRN_CallerFilePathPreferredOverCallerArgumentExpression, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
}
else if (IsCallerMemberName)
{
// CS9004: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is overriden by the CallerMemberNameAttribute.
// CS8962: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is overriden by the CallerMemberNameAttribute.
diagnostics.Add(ErrorCode.WRN_CallerMemberNamePreferredOverCallerArgumentExpression, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
}
else if (attribute.CommonConstructorArguments.Length == 1 &&
GetEarlyDecodedWellKnownAttributeData()?.CallerArgumentExpressionParameterIndex == -1)
{
// CS9005: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name.
// CS8963: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name.
diagnostics.Add(ErrorCode.WRN_CallerArgumentExpressionAttributeHasInvalidParameterName, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
}
else if (GetEarlyDecodedWellKnownAttributeData()?.CallerArgumentExpressionParameterIndex == Ordinal)
{
// CS9006: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential.
// CS8965: The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential.
diagnostics.Add(ErrorCode.WRN_CallerArgumentExpressionAttributeSelfReferential, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
}

Expand Down
5 changes: 0 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.

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

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

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

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

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

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

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

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

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

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