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
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
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
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.

Original file line number Diff line number Diff line change
Expand Up @@ -2174,10 +2174,7 @@ static void Main()
}
}";
var compilation = CreateCompilation(source, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9);
compilation.VerifyDiagnostics(
// (14,4): error CS8773: Feature 'caller argument expression' is not available in C# 9.0. Please use language version 10.0 or greater.
// [My(1+2)]
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "(1+2)").WithArguments("caller argument expression", "10.0").WithLocation(14, 4));
CompileAndVerify(compilation, expectedOutput: "'3', '1+2'").VerifyDiagnostics();
}

[ConditionalFact(typeof(CoreClrOnly))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3126,6 +3126,11 @@ ProduceBoundNode:

Dim isCallerArgumentExpression = callerArgumentExpressionParameterIndex > -1 OrElse (reducedExtensionReceiverOpt IsNot Nothing AndAlso callerArgumentExpressionParameterIndex > -2)

If isCallerArgumentExpression AndAlso Not SyntaxTree.Options.Features.ContainsKey(InternalSyntax.GetFeatureFlag(InternalSyntax.Feature.CallerArgumentExpression)) Then
' Silently require feature flag for this feature until Aleksey approves.
isCallerArgumentExpression = False
End If

If isCallerLineNumber OrElse isCallerMemberName OrElse isCallerFilePath OrElse isCallerArgumentExpression Then
Dim callerInfoValue As ConstantValue = Nothing

Expand Down Expand Up @@ -3177,10 +3182,6 @@ ProduceBoundNode:
End If

If argumentSyntax IsNot Nothing Then
InternalSyntax.Parser.CheckFeatureAvailability(diagnostics,
argumentSyntax.Location,
DirectCast(argumentSyntax.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion,
InternalSyntax.Feature.CallerArgumentExpression)
callerInfoValue = ConstantValue.Create(argumentSyntax.ToString())
End If
End If
Expand Down
16 changes: 4 additions & 12 deletions src/Compilers/VisualBasic/Portable/LanguageVersion.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
VisualBasic15_5 = 1505
VisualBasic16 = 1600
VisualBasic16_9 = 1609
VisualBasic17 = 1700

Latest = Integer.MaxValue
End Enum
Expand All @@ -40,8 +39,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
LanguageVersion.VisualBasic15_3,
LanguageVersion.VisualBasic15_5,
LanguageVersion.VisualBasic16,
LanguageVersion.VisualBasic16_9,
LanguageVersion.VisualBasic17
LanguageVersion.VisualBasic16_9

Return True
End Select
Expand Down Expand Up @@ -73,8 +71,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return "16"
Case LanguageVersion.VisualBasic16_9
Return "16.9"
Case LanguageVersion.VisualBasic17
Return "17"
Case Else
Throw ExceptionUtilities.UnexpectedValue(value)
End Select
Expand All @@ -91,17 +87,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public Function MapSpecifiedToEffectiveVersion(version As LanguageVersion) As LanguageVersion
Select Case version
Case LanguageVersion.Latest
Return LanguageVersion.VisualBasic17
Return LanguageVersion.VisualBasic16_9
Case LanguageVersion.Default
Return LanguageVersion.VisualBasic17
Return LanguageVersion.VisualBasic16
Case Else
Return version
End Select
End Function

Friend ReadOnly Property CurrentVersion As LanguageVersion
Get
Return LanguageVersion.VisualBasic17
Return LanguageVersion.VisualBasic16_9
End Get
End Property

Expand Down Expand Up @@ -132,8 +128,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return "16"
Case LanguageVersion.VisualBasic16_9
Return "16.9"
Case LanguageVersion.VisualBasic17
Return "17"
Case LanguageVersion.Default
Return "default"
Case LanguageVersion.Latest
Expand Down Expand Up @@ -173,8 +167,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
result = LanguageVersion.VisualBasic16
Case "16.9"
result = LanguageVersion.VisualBasic16_9
Case "17", "17.0"
result = LanguageVersion.VisualBasic17
Case "default"
result = LanguageVersion.Default
Case "latest"
Expand Down
6 changes: 2 additions & 4 deletions src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
<Extension>
Friend Function GetFeatureFlag(feature As Feature) As String
Select Case feature
Case Feature.CallerArgumentExpression
Return NameOf(Feature.CallerArgumentExpression)
Case Else
Return Nothing
End Select
Expand Down Expand Up @@ -106,10 +108,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax

Case Feature.InitOnlySettersUsage
Return LanguageVersion.VisualBasic16_9

Case Feature.CallerArgumentExpression
Return LanguageVersion.VisualBasic17

Case Else
Throw ExceptionUtilities.UnexpectedValue(feature)
End Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.

Imports System.Collections.Generic
Imports System.Collections.Immutable
Imports System.Runtime.InteropServices
Imports System.Threading
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Binder
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports TypeKind = Microsoft.CodeAnalysis.TypeKind

Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
''' <summary>
Expand Down Expand Up @@ -253,6 +249,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols

Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer
Get
If Not _syntaxRef.SyntaxTree.Options.Features.ContainsKey(InternalSyntax.GetFeatureFlag(InternalSyntax.Feature.CallerArgumentExpression)) Then
' Silently require feature flag for this feature until Aleksey approves.
Return -1
End If

Dim attributeSource As SourceParameterSymbol = If(Me.BoundAttributesSource, Me)

Dim data = attributeSource.GetEarlyDecodedWellKnownAttributeData()
Expand Down
Loading