diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs index 74727f1f6864f..1d26162344618 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs @@ -1375,7 +1375,6 @@ BoundExpression bindDefaultArgument(SyntaxNode syntax, ParameterSymbol parameter argumentIndex > -1 && argumentIndex < argumentsCount) { CheckFeatureAvailability(syntax, MessageID.IDS_FeatureCallerArgumentExpression, diagnostics); - // PROTOTYPE(caller-expr): Do we need to support VB? var argument = argumentsBuilder[argumentIndex]; defaultValue = new BoundLiteral(syntax, ConstantValue.Create(argument.Syntax.ToString()), Compilation.GetSpecialType(SpecialType.System_String)) { WasCompilerGenerated = true }; diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs index c195c8ecdcae4..966460896f441 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs @@ -686,7 +686,7 @@ internal override int CallerArgumentExpressionParameterIndex var parameters = ContainingSymbol.GetParameters(); for (int i = 0; i < parameters.Length; i++) { - if (parameters[i].Name == parameterName) + if (parameters[i].Name.Equals(parameterName, StringComparison.Ordinal)) { _lazyCallerArgumentExpressionParameterIndex = i; return i; diff --git a/src/Compilers/CSharp/Portable/Symbols/NativeIntegerTypeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/NativeIntegerTypeSymbol.cs index 6ccfcef201f1d..3d0a20a468569 100644 --- a/src/Compilers/CSharp/Portable/Symbols/NativeIntegerTypeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/NativeIntegerTypeSymbol.cs @@ -371,6 +371,14 @@ internal NativeIntegerParameterSymbol(NativeIntegerTypeSymbol containingType, Na public override ImmutableArray RefCustomModifiers => _underlyingParameter.RefCustomModifiers; + internal override bool IsCallerLineNumber => _underlyingParameter.IsCallerLineNumber; + + internal override bool IsCallerFilePath => _underlyingParameter.IsCallerFilePath; + + internal override bool IsCallerMemberName => _underlyingParameter.IsCallerMemberName; + + internal override int CallerArgumentExpressionParameterIndex => _underlyingParameter.CallerArgumentExpressionParameterIndex; + public override bool Equals(Symbol? other, TypeCompareKind comparison) => NativeIntegerTypeSymbol.EqualsHelper(this, other, comparison, symbol => symbol._underlyingParameter); public override int GetHashCode() => _underlyingParameter.GetHashCode(); diff --git a/src/Compilers/CSharp/Portable/Symbols/ReducedExtensionMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/ReducedExtensionMethodSymbol.cs index 3d3e9c4236c67..ddae4c7dbf423 100644 --- a/src/Compilers/CSharp/Portable/Symbols/ReducedExtensionMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/ReducedExtensionMethodSymbol.cs @@ -621,6 +621,30 @@ public override ImmutableArray RefCustomModifiers } } + internal override bool IsCallerLineNumber + { + // ReducedExtensionMethodParameterSymbol is only exposed to semantic model. + get { throw ExceptionUtilities.Unreachable; } + } + + internal override bool IsCallerFilePath + { + // ReducedExtensionMethodParameterSymbol is only exposed to semantic model. + get { throw ExceptionUtilities.Unreachable; } + } + + internal override bool IsCallerMemberName + { + // ReducedExtensionMethodParameterSymbol is only exposed to semantic model. + get { throw ExceptionUtilities.Unreachable; } + } + + internal override int CallerArgumentExpressionParameterIndex + { + // ReducedExtensionMethodParameterSymbol is only exposed to semantic model. + get { throw ExceptionUtilities.Unreachable; } + } + public sealed override bool Equals(Symbol obj, TypeCompareKind compareKind) { if ((object)this == obj) diff --git a/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs index 0bc0df65a9f2c..e8e4d06a87672 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs @@ -142,6 +142,26 @@ protected override RetargetingModuleSymbol RetargetingModule { get { return _retargetingMethod.RetargetingModule; } } + + internal override bool IsCallerLineNumber + { + get { return _underlyingParameter.IsCallerLineNumber; } + } + + internal override bool IsCallerFilePath + { + get { return _underlyingParameter.IsCallerFilePath; } + } + + internal override bool IsCallerMemberName + { + get { return _underlyingParameter.IsCallerMemberName; } + } + + internal override int CallerArgumentExpressionParameterIndex + { + get { return _underlyingParameter.CallerArgumentExpressionParameterIndex; } + } } internal sealed class RetargetingPropertyParameterSymbol : RetargetingParameterSymbol @@ -162,5 +182,25 @@ protected override RetargetingModuleSymbol RetargetingModule { get { return _retargetingProperty.RetargetingModule; } } + + internal override bool IsCallerLineNumber + { + get { return _underlyingParameter.IsCallerLineNumber; } + } + + internal override bool IsCallerFilePath + { + get { return _underlyingParameter.IsCallerFilePath; } + } + + internal override bool IsCallerMemberName + { + get { return _underlyingParameter.IsCallerMemberName; } + } + + internal override int CallerArgumentExpressionParameterIndex + { + get { return _underlyingParameter.CallerArgumentExpressionParameterIndex; } + } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceClonedParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceClonedParameterSymbol.cs index 3071a34f5fee1..e81beb713b545 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceClonedParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceClonedParameterSymbol.cs @@ -10,6 +10,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols { + + // PROTOTYPE(caller-expr): Make SourceClonedParameterSymbol abstract and introduce new specialized types (same as being done in VB). + /// /// Represents a source parameter cloned from another , when they must share attribute data and default constant value. /// For example, parameters on a property symbol are cloned to generate parameters on accessors. diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs index 43cf905a420b6..859d6c7a4ae8c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs @@ -611,7 +611,7 @@ internal override CSharpAttributeData EarlyDecodeWellKnownAttribute(ref EarlyDec var parameters = ContainingSymbol.GetParameters(); for (int i = 0; i < parameters.Length; i++) { - if (parameters[i].Name == parameterName) + if (parameters[i].Name.Equals(parameterName, StringComparison.Ordinal)) { index = i; break; diff --git a/src/Compilers/CSharp/Portable/Symbols/SubstitutedParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/SubstitutedParameterSymbol.cs index 00422c0fab1c2..d6c68d6f7d9e7 100644 --- a/src/Compilers/CSharp/Portable/Symbols/SubstitutedParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/SubstitutedParameterSymbol.cs @@ -77,6 +77,26 @@ public override ImmutableArray RefCustomModifiers } } + internal override bool IsCallerLineNumber + { + get { return _underlyingParameter.IsCallerLineNumber; } + } + + internal override bool IsCallerFilePath + { + get { return _underlyingParameter.IsCallerFilePath; } + } + + internal override bool IsCallerMemberName + { + get { return _underlyingParameter.IsCallerMemberName; } + } + + internal override int CallerArgumentExpressionParameterIndex + { + get { return _underlyingParameter.CallerArgumentExpressionParameterIndex; } + } + public sealed override bool Equals(Symbol obj, TypeCompareKind compareKind) { if ((object)this == obj) diff --git a/src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedParameterSymbol.cs index 7d1109df50fdb..512e978ab86c3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedParameterSymbol.cs @@ -138,26 +138,6 @@ internal override bool IsIUnknownConstant get { return _underlyingParameter.IsIUnknownConstant; } } - internal override bool IsCallerLineNumber - { - get { return _underlyingParameter.IsCallerLineNumber; } - } - - internal override bool IsCallerFilePath - { - get { return _underlyingParameter.IsCallerFilePath; } - } - - internal override bool IsCallerMemberName - { - get { return _underlyingParameter.IsCallerMemberName; } - } - - internal override int CallerArgumentExpressionParameterIndex - { - get { return _underlyingParameter.CallerArgumentExpressionParameterIndex; } - } - internal override FlowAnalysisAnnotations FlowAnalysisAnnotations { // https://github.com/dotnet/roslyn/issues/30073: Consider moving to leaf types diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs index 0b5b2ffcd7dde..f2b23b88cc35e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_CallerInfoAttributes.cs @@ -1307,6 +1307,217 @@ static void Main() } #endregion + #region CallerArgumentExpression - Test various symbols + [ConditionalFact(typeof(CoreClrOnly))] + public void TestIndexers() + { + string source = @" +using System; +using System.Runtime.CompilerServices; + +class Program +{ + const string i = nameof(i); + public int this[int i, [CallerArgumentExpression(i)] string s = """"] + { + get => i; + set => Console.WriteLine($""{i}, {s}""); + } + + public static void Main() + { + new Program()[1+ 1] = 5; + new Program()[2+ 2, ""explicit-value""] = 5; + } +} +"; + + var compilation = CreateCompilation(source, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview); + CompileAndVerify(compilation, expectedOutput: @"2, 1+ 1 +4, explicit-value").VerifyDiagnostics(); + } + + [ConditionalFact(typeof(CoreClrOnly))] + public void TestDelegate() + { + string source = @" +using System; +using System.Runtime.CompilerServices; + +class Program +{ + const string s1 = nameof(s1); + delegate void D(string s1, ref string s2, out string s3, [CallerArgumentExpression(s1)] string s4 = """"); + + static void M(string s1, ref string s2, out string s3, string s4 = """") + { + s3 = """"; + Console.WriteLine($""s1: {s1}""); + Console.WriteLine($""s2: {s2}""); + Console.WriteLine($""s3: {s3}""); + Console.WriteLine($""s4: {s4}""); + } + + public static void Main() + { + D d = M; + string s2 = ""s2-arg""; + d.Invoke(""s1-arg"", ref s2, out _); + //d.EndInvoke(ref s2, out _, null); + } +} +"; + + var compilation = CreateCompilation(source, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview); + CompileAndVerify(compilation, expectedOutput: @"s1: s1-arg +s2: s2-arg +s3: +s4: ""s1-arg""").VerifyDiagnostics(); + } + + [ConditionalFact(typeof(CoreClrOnly))] + public void TestDelegate2() + { + string source = @" +using System; +using System.Runtime.CompilerServices; + +class Program +{ + const string s3 = nameof(s3); + delegate void D(string s1, ref string s2, out string s3, [CallerArgumentExpression(s3)] string s4 = """"); + + static void M(string s1, ref string s2, out string s3, string s4 = """") + { + s3 = """"; + Console.WriteLine($""s1: {s1}""); + Console.WriteLine($""s2: {s2}""); + Console.WriteLine($""s3: {s3}""); + Console.WriteLine($""s4: {s4}""); + } + + public static void Main() + { + D d = M; + string s2 = ""s2-arg""; + d.Invoke(""s1-arg"", ref s2, out _); + //d.EndInvoke(ref s2, out _, null); + } +} +"; + + var compilation = CreateCompilation(source, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview); + CompileAndVerify(compilation, expectedOutput: @"s1: s1-arg +s2: s2-arg +s3: +s4: _").VerifyDiagnostics(); // PROTOTYPE(caller-arg): Should 'out' keyword be included? + } + + + + [ConditionalFact(typeof(CoreClrOnly))] + public void TestDelegate3() + { + string source = @" +using System; +using System.Runtime.CompilerServices; + +class Program +{ + const string s1 = nameof(s1); + delegate void D(string s1, ref string s2, out string s3, [CallerArgumentExpression(s1)] string s4 = """"); + + static void M(string s1, ref string s2, out string s3, string s4 = """") + { + s3 = """"; + Console.WriteLine($""s1: {s1}""); + Console.WriteLine($""s2: {s2}""); + Console.WriteLine($""s3: {s3}""); + Console.WriteLine($""s4: {s4}""); + } + + public static void Main() + { + D d = M; + string s2 = ""s2-arg""; + d.EndInvoke(ref s2, out _, null); + } +} +"; + + var compilation = CreateCompilation(source, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview); + CompileAndVerify(compilation).VerifyDiagnostics().VerifyIL("Program.Main", @" +{ + // Code size 29 (0x1d) + .maxstack 4 + .locals init (string V_0, //s2 + string V_1) + IL_0000: ldnull + IL_0001: ldftn ""void Program.M(string, ref string, out string, string)"" + IL_0007: newobj ""Program.D..ctor(object, System.IntPtr)"" + IL_000c: ldstr ""s2-arg"" + IL_0011: stloc.0 + IL_0012: ldloca.s V_0 + IL_0014: ldloca.s V_1 + IL_0016: ldnull + IL_0017: callvirt ""void Program.D.EndInvoke(ref string, out string, System.IAsyncResult)"" + IL_001c: ret +} +"); + } + + [ConditionalFact(typeof(CoreClrOnly))] + public void TestDelegate4() + { + string source = @" +using System; +using System.Runtime.CompilerServices; + +class Program +{ + const string s3 = nameof(s3); + delegate void D(string s1, ref string s2, out string s3, [CallerArgumentExpression(s3)] string s4 = """"); + + static void M(string s1, ref string s2, out string s3, string s4 = """") + { + s3 = """"; + Console.WriteLine($""s1: {s1}""); + Console.WriteLine($""s2: {s2}""); + Console.WriteLine($""s3: {s3}""); + Console.WriteLine($""s4: {s4}""); + } + + public static void Main() + { + D d = M; + string s2 = ""s2-arg""; + d.EndInvoke(ref s2, out _, null); + } +} +"; + + var compilation = CreateCompilation(source, targetFramework: TargetFramework.NetCoreApp, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview); + CompileAndVerify(compilation).VerifyDiagnostics().VerifyIL("Program.Main", @" +{ + // Code size 29 (0x1d) + .maxstack 4 + .locals init (string V_0, //s2 + string V_1) + IL_0000: ldnull + IL_0001: ldftn ""void Program.M(string, ref string, out string, string)"" + IL_0007: newobj ""Program.D..ctor(object, System.IntPtr)"" + IL_000c: ldstr ""s2-arg"" + IL_0011: stloc.0 + IL_0012: ldloca.s V_0 + IL_0014: ldloca.s V_1 + IL_0016: ldnull + IL_0017: callvirt ""void Program.D.EndInvoke(ref string, out string, System.IAsyncResult)"" + IL_001c: ret +} +"); + } + #endregion + [Fact] public void TestCallerInfoAttributesWithSaneDefaultValues() { diff --git a/src/Compilers/Core/Portable/Symbols/Attributes/CommonParameterEarlyWellKnownAttributeData.cs b/src/Compilers/Core/Portable/Symbols/Attributes/CommonParameterEarlyWellKnownAttributeData.cs index ea66129f8d09a..4751910d1ec42 100644 --- a/src/Compilers/Core/Portable/Symbols/Attributes/CommonParameterEarlyWellKnownAttributeData.cs +++ b/src/Compilers/Core/Portable/Symbols/Attributes/CommonParameterEarlyWellKnownAttributeData.cs @@ -81,8 +81,6 @@ public bool HasCallerMemberNameAttribute } } - // PROTOTYPE(caller-expr): If VB won't be supported, this should be moved into a C#-specific type. - private int _argumentExpressionParameterIndex = -1; public int CallerArgumentExpressionParameterIndex { diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb index 0c748753281a0..b8788604bf51e 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb @@ -2424,7 +2424,9 @@ ProduceBoundNode: ' Deal with Optional arguments ' Need to handle optional arguments here, there could be conversion errors, etc. - argument = GetArgumentForParameterDefaultValue(param, node, diagnostics, callerInfoOpt) + ' reducedExtensionReceiverOpt is used to determine the default value of a CallerArgumentExpression when it refers to the first parameter of an extension method. + ' Don't bother with correctly determining the correct value for this case since we're in an error case anyway. + argument = GetArgumentForParameterDefaultValue(param, node, diagnostics, callerInfoOpt, parameterToArgumentMap, arguments, reducedExtensionReceiverOpt:=Nothing) If argument Is Nothing Then If Not includeMethodNameInErrorMessages Then @@ -3098,7 +3100,13 @@ ProduceBoundNode: End Sub - Friend Function GetArgumentForParameterDefaultValue(param As ParameterSymbol, syntax As SyntaxNode, diagnostics As BindingDiagnosticBag, callerInfoOpt As SyntaxNode) As BoundExpression + Friend Function GetArgumentForParameterDefaultValue(param As ParameterSymbol, + syntax As SyntaxNode, + diagnostics As BindingDiagnosticBag, + callerInfoOpt As SyntaxNode, + parameterToArgumentMap As ArrayBuilder(Of Integer), + arguments As ImmutableArray(Of BoundExpression), + reducedExtensionReceiverOpt As BoundExpression) As BoundExpression Dim defaultArgument As BoundExpression = Nothing ' See Section 3 of §11.8.2 Applicable Methods @@ -3114,8 +3122,11 @@ ProduceBoundNode: Dim isCallerLineNumber As Boolean = param.IsCallerLineNumber Dim isCallerMemberName As Boolean = param.IsCallerMemberName Dim isCallerFilePath As Boolean = param.IsCallerFilePath + Dim callerArgumentExpressionParameterIndex As Integer = param.CallerArgumentExpressionParameterIndex - If isCallerLineNumber OrElse isCallerMemberName OrElse isCallerFilePath Then + Dim isCallerArgumentExpression = callerArgumentExpressionParameterIndex > -1 OrElse (reducedExtensionReceiverOpt IsNot Nothing AndAlso callerArgumentExpressionParameterIndex > -2) + + If isCallerLineNumber OrElse isCallerMemberName OrElse isCallerFilePath OrElse isCallerArgumentExpression Then Dim callerInfoValue As ConstantValue = Nothing If isCallerLineNumber Then @@ -3149,9 +3160,29 @@ ProduceBoundNode: If container IsNot Nothing AndAlso container.Name IsNot Nothing Then callerInfoValue = ConstantValue.Create(container.Name) End If - Else - Debug.Assert(isCallerFilePath) + ElseIf isCallerFilePath Then callerInfoValue = ConstantValue.Create(callerInfoOpt.SyntaxTree.GetDisplayPath(callerInfoOpt.Span, Me.Compilation.Options.SourceReferenceResolver)) + Else + Debug.Assert(callerArgumentExpressionParameterIndex > -1 OrElse (reducedExtensionReceiverOpt IsNot Nothing AndAlso callerArgumentExpressionParameterIndex > -2)) + + Dim argumentSyntax As SyntaxNode = Nothing + If callerArgumentExpressionParameterIndex = -1 Then + argumentSyntax = reducedExtensionReceiverOpt.Syntax + Else + Dim argumentIndex = parameterToArgumentMap(callerArgumentExpressionParameterIndex) + Debug.Assert(argumentIndex < arguments.Length) + If argumentIndex > -1 Then + argumentSyntax = arguments(argumentIndex).Syntax + End If + 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 If callerInfoValue IsNot Nothing Then diff --git a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb index 3798f0a7aecb0..c7767908f7094 100644 --- a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb +++ b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb @@ -1985,6 +1985,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic WRN_GeneratorFailedDuringGeneration = 42502 WRN_AnalyzerReferencesFramework = 42503 + WRN_CallerArgumentExpressionAttributeSelfReferential = 42504 + WRN_CallerArgumentExpressionAttributeHasInvalidParameterName = 42505 + ' // AVAILABLE 42600 - 49998 ERRWRN_NextAvailable = 42600 @@ -2044,5 +2047,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic FEATURE_UnconstrainedTypeParameterInConditional FEATURE_CommentsAfterLineContinuation FEATURE_InitOnlySettersUsage + FEATURE_CallerArgumentExpression End Enum End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Generated/ErrorFacts.Generated.vb b/src/Compilers/VisualBasic/Portable/Generated/ErrorFacts.Generated.vb index 81cad21849fa2..b32ca85040dd9 100644 --- a/src/Compilers/VisualBasic/Portable/Generated/ErrorFacts.Generated.vb +++ b/src/Compilers/VisualBasic/Portable/Generated/ErrorFacts.Generated.vb @@ -173,7 +173,9 @@ ERRID.WRN_AttributeNotSupportedInVB, ERRID.WRN_GeneratorFailedDuringInitialization, ERRID.WRN_GeneratorFailedDuringGeneration, - ERRID.WRN_AnalyzerReferencesFramework + ERRID.WRN_AnalyzerReferencesFramework, + ERRID.WRN_CallerArgumentExpressionAttributeSelfReferential, + ERRID.WRN_CallerArgumentExpressionAttributeHasInvalidParameterName Return True Case Else Return False diff --git a/src/Compilers/VisualBasic/Portable/LanguageVersion.vb b/src/Compilers/VisualBasic/Portable/LanguageVersion.vb index 3b1b9698ad173..806fb59903df4 100644 --- a/src/Compilers/VisualBasic/Portable/LanguageVersion.vb +++ b/src/Compilers/VisualBasic/Portable/LanguageVersion.vb @@ -21,6 +21,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic VisualBasic15_5 = 1505 VisualBasic16 = 1600 VisualBasic16_9 = 1609 + ' PROTOTYPE(caller-expr): Map to language version matching whatever VS version the feature will be shipped in. + VisualBasic17 = 1700 Latest = Integer.MaxValue End Enum @@ -39,7 +41,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic LanguageVersion.VisualBasic15_3, LanguageVersion.VisualBasic15_5, LanguageVersion.VisualBasic16, - LanguageVersion.VisualBasic16_9 + LanguageVersion.VisualBasic16_9, + LanguageVersion.VisualBasic17 Return True End Select @@ -71,6 +74,8 @@ 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 @@ -87,9 +92,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Public Function MapSpecifiedToEffectiveVersion(version As LanguageVersion) As LanguageVersion Select Case version Case LanguageVersion.Latest - Return LanguageVersion.VisualBasic16_9 + Return LanguageVersion.VisualBasic17 Case LanguageVersion.Default - Return LanguageVersion.VisualBasic16 + Return LanguageVersion.VisualBasic17 Case Else Return version End Select @@ -97,7 +102,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Friend ReadOnly Property CurrentVersion As LanguageVersion Get - Return LanguageVersion.VisualBasic16_9 + Return LanguageVersion.VisualBasic17 End Get End Property @@ -128,6 +133,8 @@ 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 @@ -167,6 +174,8 @@ 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" diff --git a/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb b/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb index db503ccb6d48d..daf2b35628e7a 100644 --- a/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb +++ b/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb @@ -41,6 +41,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax UnconstrainedTypeParameterInConditional CommentsAfterLineContinuation InitOnlySettersUsage + CallerArgumentExpression End Enum Friend Module FeatureExtensions @@ -106,6 +107,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Case Feature.InitOnlySettersUsage Return LanguageVersion.VisualBasic16_9 + Case Feature.CallerArgumentExpression + ' PROTOTYPE(caller-expr): Map to language version matching whatever VS version the feature will be shipped in. + Return LanguageVersion.VisualBasic17 + Case Else Throw ExceptionUtilities.UnexpectedValue(feature) End Select @@ -179,6 +184,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return ERRID.FEATURE_CommentsAfterLineContinuation Case Feature.InitOnlySettersUsage Return ERRID.FEATURE_InitOnlySettersUsage + Case Feature.CallerArgumentExpression + Return ERRID.FEATURE_CallerArgumentExpression Case Else Throw ExceptionUtilities.UnexpectedValue(feature) End Select diff --git a/src/Compilers/VisualBasic/Portable/PublicAPI.Unshipped.txt b/src/Compilers/VisualBasic/Portable/PublicAPI.Unshipped.txt index 264737b55b170..3b30cdbe89642 100644 --- a/src/Compilers/VisualBasic/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/VisualBasic/Portable/PublicAPI.Unshipped.txt @@ -1,4 +1,5 @@ Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.VisualBasic16_9 = 1609 -> Microsoft.CodeAnalysis.VisualBasic.LanguageVersion +Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.VisualBasic17 = 1700 -> Microsoft.CodeAnalysis.VisualBasic.LanguageVersion Microsoft.CodeAnalysis.VisualBasic.VisualBasicGeneratorDriver Overrides Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.GetLineMappings(cancellationToken As System.Threading.CancellationToken = Nothing) -> System.Collections.Generic.IEnumerable(Of Microsoft.CodeAnalysis.LineMapping) Shared Microsoft.CodeAnalysis.VisualBasic.VisualBasicGeneratorDriver.Create(generators As System.Collections.Immutable.ImmutableArray(Of Microsoft.CodeAnalysis.ISourceGenerator), additionalTexts As System.Collections.Immutable.ImmutableArray(Of Microsoft.CodeAnalysis.AdditionalText) = Nothing, parseOptions As Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions = Nothing, analyzerConfigOptionsProvider As Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider = Nothing) -> Microsoft.CodeAnalysis.VisualBasic.VisualBasicGeneratorDriver diff --git a/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb b/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb index f793dfd09ea42..a9d943013e408 100644 --- a/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb +++ b/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb @@ -3404,6 +3404,12 @@ Next_i: End Get End Property + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Throw ExceptionUtilities.Unreachable + End Get + End Property + Public Overrides ReadOnly Property IsParamArray As Boolean Get Return _parameterToLift.IsParamArray diff --git a/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb b/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb index 9989be22064f3..f21d0d490de97 100644 --- a/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb +++ b/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb @@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax +Imports Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree Imports TypeKind = Microsoft.CodeAnalysis.TypeKind Namespace Microsoft.CodeAnalysis.VisualBasic @@ -2866,6 +2867,7 @@ Bailout: Debug.Assert(argumentNames.IsDefault OrElse (argumentNames.Length > 0 AndAlso argumentNames.Length = arguments.Length)) Debug.Assert(Not candidate.ArgumentMatchingDone) Debug.Assert(candidate.State = CandidateAnalysisResultState.Applicable) + Debug.Assert(Not candidate.Candidate.UnderlyingSymbol.IsReducedExtensionMethod() OrElse methodOrPropertyGroup.ReceiverOpt IsNot Nothing OrElse TypeOf methodOrPropertyGroup.SyntaxTree Is DummySyntaxTree) Dim parameterToArgumentMap As ArrayBuilder(Of Integer) = Nothing Dim paramArrayItems As ArrayBuilder(Of Integer) = Nothing @@ -3073,7 +3075,12 @@ Bailout: defaultValueDiagnostics.Clear() End If - defaultArgument = binder.GetArgumentForParameterDefaultValue(param, If(argument, methodOrPropertyGroup).Syntax, defaultValueDiagnostics, callerInfoOpt) + Dim receiverOpt As BoundExpression = Nothing + If candidateSymbol.IsReducedExtensionMethod() Then + receiverOpt = methodOrPropertyGroup.ReceiverOpt + End If + + defaultArgument = binder.GetArgumentForParameterDefaultValue(param, If(argument, methodOrPropertyGroup).Syntax, defaultValueDiagnostics, callerInfoOpt, parameterToArgumentMap, arguments, receiverOpt) If defaultArgument IsNot Nothing AndAlso Not defaultValueDiagnostics.HasAnyErrors Then Debug.Assert(Not defaultValueDiagnostics.DiagnosticBag.AsEnumerable().Any()) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb index 7f9751ba6c461..cd58a8b4b1be4 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb @@ -2,17 +2,13 @@ ' 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 System.Reflection Imports System.Reflection.Metadata Imports Microsoft.CodeAnalysis.PooledObjects -Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax -Imports TypeKind = Microsoft.CodeAnalysis.TypeKind Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE @@ -51,6 +47,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Private _lazyHasCallerMemberNameAttribute As ThreeState = ThreeState.Unknown Private _lazyHasCallerFilePathAttribute As ThreeState = ThreeState.Unknown + Private Const UninitializedCallerArgumentExpressionParameterIndex As Integer = Integer.MinValue + + ''' + ''' The index of a CallerArgumentExpression. The value means uninitialized, -1 means + ''' Not found. Otherwise, the index of the CallerArgumentExpression. + ''' + Private _lazyCallerArgumentExpressionParameterIndex As Integer = UninitializedCallerArgumentExpressionParameterIndex + Private _lazyIsParamArray As ThreeState ''' @@ -174,6 +178,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE _lazyHasCallerLineNumberAttribute = ThreeState.False _lazyHasCallerMemberNameAttribute = ThreeState.False _lazyHasCallerFilePathAttribute = ThreeState.False + _lazyCallerArgumentExpressionParameterIndex = -1 _lazyIsParamArray = ThreeState.False Else Try @@ -605,6 +610,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End Get End Property + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + If _lazyCallerArgumentExpressionParameterIndex = UninitializedCallerArgumentExpressionParameterIndex Then + Debug.Assert(Not _handle.IsNil) + + Dim attribute = PEModule.FindTargetAttribute(_handle, AttributeDescription.CallerArgumentExpressionAttribute) + Dim parameterName As String = Nothing + If attribute.HasValue AndAlso PEModule.TryExtractStringValueFromAttribute(attribute.Handle, parameterName) Then + Dim parameters = ContainingSymbol.GetParameters() + For i = 0 To parameters.Length - 1 + If IdentifierComparison.Equals(parameters(i).Name, parameterName) Then + _lazyCallerArgumentExpressionParameterIndex = i + Exit For + End If + Next + Else + _lazyCallerArgumentExpressionParameterIndex = -1 + End If + End If + + Return _lazyCallerArgumentExpressionParameterIndex + End Get + End Property + ''' ''' This is for perf, not for correctness. ''' diff --git a/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb index d3e8483d4c1df..9a726b552ca70 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb @@ -266,6 +266,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Friend MustOverride ReadOnly Property IsCallerFilePath As Boolean + ''' + ''' The index of the parameter which CallerArgumentExpressionAttribute points to. + ''' + ''' + ''' Returns -1 if there is no valid CallerArgumentExpressionAttribute. + ''' The situation is different for reduced extension method parameters, where a value + ''' of -2 is returned for no valid attribute, -1 for 'Me' parameter, and the reduced index (i.e, the original index minus 1) otherwise. + ''' + Friend MustOverride ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer Get Return ERRID.ERR_UnsupportedType1 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb index 0acda5dda7f23..9738bb19cf14d 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb @@ -947,6 +947,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend NotOverridable Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return m_CurriedFromParameter.CallerArgumentExpressionParameterIndex - 1 + End Get + End Property + Public Overrides ReadOnly Property HasExplicitDefaultValue As Boolean Get Return m_CurriedFromParameter.HasExplicitDefaultValue diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingParameterSymbol.vb index 806b6e8c6825d..d3ff256fc8c4a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingParameterSymbol.vb @@ -2,14 +2,9 @@ ' 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 -Imports System.Collections.Generic Imports System.Collections.Immutable Imports System.Globalization Imports System.Threading -Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Retargeting @@ -193,6 +188,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Retargeting End Get End Property + Friend NotOverridable Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return _underlyingParameter.CallerArgumentExpressionParameterIndex + End Get + End Property + Public Overrides ReadOnly Property ContainingSymbol As Symbol Get Return RetargetingTranslator.Retarget(_underlyingParameter.ContainingSymbol) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyParameterSymbol.vb index 8790a3ced3a6d..84fcb36903a31 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyParameterSymbol.vb @@ -187,6 +187,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Throw ExceptionUtilities.Unreachable End Get End Property + + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Throw ExceptionUtilities.Unreachable + End Get + End Property #End Region End Class End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaParameterSymbol.vb index 3790bf0b6c344..174cd4099ded3 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaParameterSymbol.vb @@ -2,13 +2,7 @@ ' 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.Collections.ObjectModel -Imports System.Threading - -Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols @@ -128,6 +122,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend NotOverridable Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return -1 + End Get + End Property + Public NotOverridable Overrides ReadOnly Property IsParamArray As Boolean Get Return False diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/MeParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/MeParameterSymbol.vb index faa931cfd7a42..e2ef066f6f7dc 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/MeParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/MeParameterSymbol.vb @@ -166,6 +166,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return -1 + End Get + End Property + Public Overrides ReadOnly Property IsMe As Boolean Get Return True diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceClonedParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceClonedParameterSymbol.vb index 5c4b07ae9a5f5..4a26e203596e0 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceClonedParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceClonedParameterSymbol.vb @@ -3,10 +3,6 @@ ' See the LICENSE file in the project root for more information. Imports System.Collections.Immutable -Imports System.Diagnostics -Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols @@ -17,12 +13,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' ''' For example, parameters on delegate Invoke method are cloned to delegate BeginInvoke, EndInvoke methods. ''' - Friend Class SourceClonedParameterSymbol + Friend MustInherit Class SourceClonedParameterSymbol Inherits SourceParameterSymbolBase - Private ReadOnly _originalParam As SourceParameterSymbol + Protected ReadOnly _originalParam As SourceParameterSymbolBase - Friend Sub New(originalParam As SourceParameterSymbol, newOwner As MethodSymbol, newOrdinal As Integer) + Friend Sub New(originalParam As SourceParameterSymbolBase, newOwner As MethodSymbol, newOrdinal As Integer) MyBase.New(newOwner, newOrdinal) Debug.Assert(originalParam IsNot Nothing) _originalParam = originalParam @@ -131,24 +127,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property - Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean - Get - Return _originalParam.IsCallerLineNumber - End Get - End Property - - Friend Overrides ReadOnly Property IsCallerMemberName As Boolean - Get - Return _originalParam.IsCallerMemberName - End Get - End Property - - Friend Overrides ReadOnly Property IsCallerFilePath As Boolean - Get - Return _originalParam.IsCallerFilePath - End Get - End Property - Public Overrides ReadOnly Property IsByRef As Boolean Get Return _originalParam.IsByRef @@ -181,7 +159,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols #End Region Friend Overrides Function WithTypeAndCustomModifiers(type As TypeSymbol, customModifiers As ImmutableArray(Of CustomModifier), refCustomModifiers As ImmutableArray(Of CustomModifier)) As ParameterSymbol - Return New SourceClonedParameterSymbolWithCustomModifiers(_originalParam, DirectCast(Me.ContainingSymbol, MethodSymbol), Me.Ordinal, type, customModifiers, refCustomModifiers) + Return New SourceClonedParameterSymbolWithCustomModifiers(Me, DirectCast(Me.ContainingSymbol, MethodSymbol), Me.Ordinal, type, customModifiers, refCustomModifiers) End Function Friend NotInheritable Class SourceClonedParameterSymbolWithCustomModifiers @@ -192,7 +170,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Private ReadOnly _refCustomModifiers As ImmutableArray(Of CustomModifier) Friend Sub New( - originalParam As SourceParameterSymbol, + originalParam As SourceClonedParameterSymbol, newOwner As MethodSymbol, newOrdinal As Integer, type As TypeSymbol, @@ -225,6 +203,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean + Get + Return _originalParam.IsCallerLineNumber + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerMemberName As Boolean + Get + Return _originalParam.IsCallerMemberName + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerFilePath As Boolean + Get + Return _originalParam.IsCallerFilePath + End Get + End Property + + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return _originalParam.CallerArgumentExpressionParameterIndex + End Get + End Property + Friend Overrides Function WithTypeAndCustomModifiers(type As TypeSymbol, customModifiers As ImmutableArray(Of CustomModifier), refCustomModifiers As ImmutableArray(Of CustomModifier)) As ParameterSymbol Throw ExceptionUtilities.Unreachable End Function diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb index 07357864d8069..448082e89ab57 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb @@ -251,6 +251,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Dim attributeSource As SourceParameterSymbol = If(Me.BoundAttributesSource, Me) + + Dim data = attributeSource.GetEarlyDecodedWellKnownAttributeData() + If data Is Nothing Then + Return -1 + End If + + Return data.CallerArgumentExpressionParameterIndex + End Get + End Property + ''' ''' Is parameter explicitly declared ByRef. Can be different from IsByRef only for ''' String parameters of Declare methods. diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateClonedParameterSymbolForBeginAndEndInvoke.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateClonedParameterSymbolForBeginAndEndInvoke.vb new file mode 100644 index 0000000000000..dd5abb8069988 --- /dev/null +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateClonedParameterSymbolForBeginAndEndInvoke.vb @@ -0,0 +1,42 @@ +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols + Friend NotInheritable Class SourceDelegateClonedParameterSymbolForBeginAndEndInvoke + Inherits SourceClonedParameterSymbol + + Public Sub New(originalParam As SourceParameterSymbol, newOwner As MethodSymbol, ordinal As Integer) + MyBase.New(originalParam, newOwner, ordinal) + Debug.Assert(Not originalParam.IsOptional) + End Sub + + Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean + Get + ' This parameter cannot be optional. Hence, this property shouldn't be accessed. + Throw ExceptionUtilities.Unreachable + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerMemberName As Boolean + Get + ' This parameter cannot be optional. Hence, this property shouldn't be accessed. + Throw ExceptionUtilities.Unreachable + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerFilePath As Boolean + Get + ' This parameter cannot be optional. Hence, this property shouldn't be accessed. + Throw ExceptionUtilities.Unreachable + End Get + End Property + + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + ' This parameter cannot be optional. Hence, this property shouldn't be accessed. + Throw ExceptionUtilities.Unreachable + End Get + End Property + End Class +End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateMethodSymbol.vb index 9359b8f8f2dc0..1b3792c0a2848 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceDelegateMethodSymbol.vb @@ -288,7 +288,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim ordinal As Integer = 0 For Each parameter In invoke.Parameters - parameters.Add(New SourceClonedParameterSymbol(DirectCast(parameter, SourceParameterSymbol), Me, ordinal)) + ' Delegate parameters cannot be optional in VB. + ' In error cases where the parameter is specified optional in source, the parameter + ' will not have a True .IsOptional. + ' This is ensured by 'CheckDelegateParameterModifier' + Debug.Assert(Not parameter.IsOptional) + parameters.Add(New SourceDelegateClonedParameterSymbolForBeginAndEndInvoke(DirectCast(parameter, SourceParameterSymbol), Me, ordinal)) ordinal += 1 Next @@ -330,8 +335,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim ordinal = 0 For Each parameter In invoke.Parameters + ' Delegate parameters cannot be optional in VB. + ' In error cases where the parameter is specified optional in source, the parameter + ' will not have a True .IsOptional. + ' This is ensured by 'CheckDelegateParameterModifier' + Debug.Assert(Not parameter.IsOptional) If parameter.IsByRef Then - parameters.Add(New SourceClonedParameterSymbol(DirectCast(parameter, SourceParameterSymbol), Me, ordinal)) + parameters.Add(New SourceDelegateClonedParameterSymbolForBeginAndEndInvoke(DirectCast(parameter, SourceParameterSymbol), Me, ordinal)) ordinal += 1 End If Next diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb index f387b3120efac..2841a81e8c809 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb @@ -5,13 +5,9 @@ Imports System.Collections.Immutable Imports System.Runtime.InteropServices Imports Microsoft.CodeAnalysis.PooledObjects -Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax -Imports TypeKind = Microsoft.CodeAnalysis.TypeKind Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols - Partial Friend Class SourceNamedTypeSymbol ''' @@ -1340,7 +1336,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return attributes.ToImmutableAndFree() End Function - Friend Overrides Sub AddSynthesizedAttributes(compilationState as ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData)) + Friend Overrides Sub AddSynthesizedAttributes(compilationState As ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData)) MyBase.AddSynthesizedAttributes(compilationState, attributes) If _synthesizedDispId = ReservedDispId.None Then @@ -1548,31 +1544,25 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean Get - If IsComEventParameter Then - Return False - End If - - Return _clonedFrom.IsCallerLineNumber + Throw ExceptionUtilities.Unreachable End Get End Property Friend Overrides ReadOnly Property IsCallerMemberName As Boolean Get - If IsComEventParameter Then - Return False - End If - - Return _clonedFrom.IsCallerMemberName + Throw ExceptionUtilities.Unreachable End Get End Property Friend Overrides ReadOnly Property IsCallerFilePath As Boolean Get - If IsComEventParameter Then - Return False - End If + Throw ExceptionUtilities.Unreachable + End Get + End Property - Return _clonedFrom.IsCallerFilePath + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Throw ExceptionUtilities.Unreachable End Get End Property @@ -1622,7 +1612,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return _clonedFrom.GetAttributes() End Function - Friend Overrides Sub AddSynthesizedAttributes(compilationState as ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData)) + Friend Overrides Sub AddSynthesizedAttributes(compilationState As ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData)) MyBase.AddSynthesizedAttributes(compilationState, attributes) If IsComEventParameter Then @@ -1842,7 +1832,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return _clonedFrom.GetAttributes() End Function - Friend Overrides Sub AddSynthesizedAttributes(compilationState as ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData)) + Friend Overrides Sub AddSynthesizedAttributes(compilationState As ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData)) MyBase.AddSynthesizedAttributes(compilationState, attributes) If _synthesizedDispId = ReservedDispId.None Then diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb index 5be5ccb714d96..80870794bd34d 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb @@ -2,17 +2,10 @@ ' 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.Collections.ObjectModel Imports System.Runtime.InteropServices -Imports System.Threading -Imports Microsoft.CodeAnalysis.CodeGen -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 Friend MustInherit Class SourceParameterSymbol @@ -249,6 +242,23 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols arguments.GetOrCreateData(Of ParameterEarlyWellKnownAttributeData).HasCallerFilePathAttribute = True ElseIf VisualBasicAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.CallerMemberNameAttribute) Then arguments.GetOrCreateData(Of ParameterEarlyWellKnownAttributeData).HasCallerMemberNameAttribute = True + ElseIf VisualBasicAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.CallerArgumentExpressionAttribute) Then + Dim index = -1 + Dim attribute = arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, False) + If Not attribute.HasErrors Then + Dim parameterName As String = Nothing + If attribute.ConstructorArguments.Single().TryDecodeValue(SpecialType.System_String, parameterName) Then + Dim parameters = containingSymbol.GetParameters() + For i = 0 To parameters.Length - 1 + If IdentifierComparison.Equals(parameters(i).Name, parameterName) Then + index = i + Exit For + End If + Next + End If + End If + + arguments.GetOrCreateData(Of ParameterEarlyWellKnownAttributeData).CallerArgumentExpressionParameterIndex = index End If Return MyBase.EarlyDecodeWellKnownAttribute(arguments) @@ -322,6 +332,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols arguments.GetOrCreateData(Of CommonParameterWellKnownAttributeData)().HasOutAttribute = True ElseIf attrData.IsTargetAttribute(Me, AttributeDescription.MarshalAsAttribute) Then MarshalAsAttributeDecoder(Of CommonParameterWellKnownAttributeData, AttributeSyntax, VisualBasicAttributeData, AttributeLocation).Decode(arguments, AttributeTargets.Parameter, MessageProvider.Instance) + ElseIf attrData.IsTargetAttribute(Me, AttributeDescription.CallerArgumentExpressionAttribute) Then + Dim index = GetEarlyDecodedWellKnownAttributeData()?.CallerArgumentExpressionParameterIndex + If index = Ordinal Then + DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.WRN_CallerArgumentExpressionAttributeSelfReferential, arguments.AttributeSyntaxOpt.Location, Me.Name) + ElseIf index = -1 Then + DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.WRN_CallerArgumentExpressionAttributeHasInvalidParameterName, arguments.AttributeSyntaxOpt.Location, Me.Name) + End If End If MyBase.DecodeWellKnownAttribute(arguments) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyClonedParameterSymbolForAccessors.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyClonedParameterSymbolForAccessors.vb new file mode 100644 index 0000000000000..a6d37742cf9d8 --- /dev/null +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyClonedParameterSymbolForAccessors.vb @@ -0,0 +1,37 @@ +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols + Friend NotInheritable Class SourcePropertyClonedParameterSymbolForAccessors + Inherits SourceClonedParameterSymbol + + Public Sub New(originalParam As SourceParameterSymbol, newOwner As MethodSymbol) + MyBase.New(originalParam, newOwner, originalParam.Ordinal) + End Sub + + Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean + Get + Throw ExceptionUtilities.Unreachable + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerMemberName As Boolean + Get + Throw ExceptionUtilities.Unreachable + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerFilePath As Boolean + Get + Throw ExceptionUtilities.Unreachable + End Get + End Property + + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Throw ExceptionUtilities.Unreachable + End Get + End Property + End Class +End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb index 0899a220a0334..23019fe70facf 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb @@ -288,7 +288,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim overriddenMethod As MethodSymbol = method.OverriddenMethod For Each parameter In Me.Parameters - Dim clone As ParameterSymbol = New SourceClonedParameterSymbol(DirectCast(parameter, SourceParameterSymbol), method, parameter.Ordinal) + Dim clone As ParameterSymbol = New SourcePropertyClonedParameterSymbolForAccessors(DirectCast(parameter, SourceParameterSymbol), method) If overriddenMethod IsNot Nothing Then CustomModifierUtils.CopyParameterCustomModifiers(overriddenMethod.Parameters(parameter.Ordinal), clone) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceSimpleParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceSimpleParameterSymbol.vb index 42e76980383db..253708a7046f6 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceSimpleParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceSimpleParameterSymbol.vb @@ -129,6 +129,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Dim data = GetEarlyDecodedWellKnownAttributeData() + If data Is Nothing Then + Return -1 + End If + + Return data.CallerArgumentExpressionParameterIndex + End Get + End Property + Friend Overrides ReadOnly Property IsExplicitByRef As Boolean Get ' SourceSimpleParameterSymbol is never created for a parameter with ByRef modifier. diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedParameterSymbol.vb index 66553a2dff4ea..d5c1213ca5a60 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedParameterSymbol.vb @@ -2,14 +2,9 @@ ' 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.Globalization Imports System.Threading -Imports Microsoft.CodeAnalysis -Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols @@ -166,6 +161,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend NotOverridable Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return _originalDefinition.CallerArgumentExpressionParameterIndex + End Get + End Property + Public Overrides ReadOnly Property RefCustomModifiers As ImmutableArray(Of CustomModifier) Get Return TypeSubstitution.SubstituteCustomModifiers(_originalDefinition.RefCustomModifiers) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SymbolExtensions.vb b/src/Compilers/VisualBasic/Portable/Symbols/SymbolExtensions.vb index 80a9e602cec8a..6d33c4ecdbcbd 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SymbolExtensions.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SymbolExtensions.vb @@ -332,6 +332,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Select End Function + ''' + ''' Returns the parameters of a given method or property. + ''' + + Friend Function GetParameters(sym As Symbol) As ImmutableArray(Of ParameterSymbol) + Select Case sym.Kind + Case SymbolKind.Method + Return DirectCast(sym, MethodSymbol).Parameters + Case SymbolKind.Property + Return DirectCast(sym, PropertySymbol).Parameters + Case Else + Return ImmutableArray(Of ParameterSymbol).Empty + End Select + End Function + Friend Function OfMinimalArity(symbols As IEnumerable(Of NamespaceOrTypeSymbol)) As NamespaceOrTypeSymbol Dim minAritySymbol As NamespaceOrTypeSymbol = Nothing diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedParameterSymbol.vb index ff2b5ae732b7b..21ab1995a5b1a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedParameterSymbol.vb @@ -164,6 +164,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return -1 + End Get + End Property + ''' ''' True if the argument value must be included in the marshalled arguments passed to a remote callee only if it is different from the default value (if there is one). ''' diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleParameterSymbol.vb index 155620412e2b2..eedef53ce4882 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleParameterSymbol.vb @@ -2,10 +2,6 @@ ' 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.Immutable -Imports System.Globalization -Imports System.Threading - Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' ''' Represents a parameter of a method or a property of a tuple type @@ -21,6 +17,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean + Get + Return Me._underlyingParameter.IsCallerLineNumber + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerFilePath As Boolean + Get + Return Me._underlyingParameter.IsCallerFilePath + End Get + End Property + + Friend Overrides ReadOnly Property IsCallerMemberName As Boolean + Get + Return Me._underlyingParameter.IsCallerMemberName + End Get + End Property + + Friend Overrides ReadOnly Property CallerArgumentExpressionParameterIndex As Integer + Get + Return Me._underlyingParameter.CallerArgumentExpressionParameterIndex + End Get + End Property + Public Sub New(container As Symbol, underlyingParameter As ParameterSymbol) MyBase.New(underlyingParameter) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedParameterSymbol.vb index cfc13f51016ec..173c53d3f71df 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedParameterSymbol.vb @@ -135,24 +135,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property - Friend Overrides ReadOnly Property IsCallerLineNumber As Boolean - Get - Return Me._underlyingParameter.IsCallerLineNumber - End Get - End Property - - Friend Overrides ReadOnly Property IsCallerFilePath As Boolean - Get - Return Me._underlyingParameter.IsCallerFilePath - End Get - End Property - - Friend Overrides ReadOnly Property IsCallerMemberName As Boolean - Get - Return Me._underlyingParameter.IsCallerMemberName - End Get - End Property - Friend Overrides ReadOnly Property IsExplicitByRef As Boolean Get Return Me._underlyingParameter.IsExplicitByRef diff --git a/src/Compilers/VisualBasic/Portable/VBResources.resx b/src/Compilers/VisualBasic/Portable/VBResources.resx index 6017f003425ab..e66a4e886a1c0 100644 --- a/src/Compilers/VisualBasic/Portable/VBResources.resx +++ b/src/Compilers/VisualBasic/Portable/VBResources.resx @@ -5629,4 +5629,19 @@ 'UnmanagedCallersOnly' attribute is not supported. + + caller argument expression + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf index 9f83a032adb3a..9ef50793c37de 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf @@ -62,6 +62,11 @@ Atribut UnmanagedCallersOnly se nepodporuje. + + caller argument expression + caller argument expression + + comments after line continuation komentáře po pokračování řádku @@ -503,6 +508,26 @@ Načtené sestavení se odkazuje na architekturu .NET Framework, což se nepodporuje + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Generátor {0} nemohl vygenerovat zdroj. V důsledku toho může docházet k chybám kompilace a generátor nebude přispívat na výstup. Výjimka měla typ {1} se zprávou {2}. diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf index f51f52e925693..801bcc34abc4c 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf @@ -62,6 +62,11 @@ Das Attribut "UnmanagedCallersOnly" wird nicht unterstützt. + + caller argument expression + caller argument expression + + comments after line continuation Kommentare nach Zeilenfortsetzung @@ -503,6 +508,26 @@ Die geladene Assembly verweist auf das .NET Framework. Dies wird nicht unterstützt. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Fehler beim Generieren der Quelle durch den Generator "{0}". Dieser wird bei der Ausgabe nicht berücksichtigt, deshalb kann es zu Kompilierungsfehlern kommen. Ausnahmetyp: {1}. Meldung: {2} diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf index 8b6dc9d3f257f..c53f312eb7e32 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf @@ -62,6 +62,11 @@ No se admite el atributo "UnmanagedCallersOnly". + + caller argument expression + caller argument expression + + comments after line continuation comentarios después de la continuación de línea @@ -503,6 +508,26 @@ El ensamblado que se ha cargado hace referencia a .NET Framework, lo cual no se admite. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Error del generador "{0}" al crear código fuente. No contribuirá a la salida y pueden producirse errores de compilación como resultado. Se produjo la excepción de tipo "{1}" con el mensaje "{2}" diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf index a93959fe4783e..b4393b064585f 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf @@ -62,6 +62,11 @@ L'attribut 'UnmanagedCallersOnly' n'est pas pris en charge. + + caller argument expression + caller argument expression + + comments after line continuation commentaires après la continuation de la ligne @@ -503,6 +508,26 @@ L'assembly chargé référence le .NET Framework, ce qui n'est pas pris en charge. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Le générateur '{0}' n'a pas pu générer la source. Dans la mesure où il ne va pas contribuer à la sortie, des erreurs de compilation peuvent se produire. Exception levée de type '{1}' avec le message '{2}' diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf index 4f1d8849ce630..9574f919d9e13 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf @@ -62,6 +62,11 @@ L'attributo 'UnmanagedCallersOnly' non è supportato. + + caller argument expression + caller argument expression + + comments after line continuation commenti dopo la continuazione di riga @@ -503,6 +508,26 @@ L'assembly caricato fa riferimento a .NET Framework, che non è supportato. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Il generatore '{0}' non è riuscito a generare l'origine. Non verrà aggiunto come contributo all'output e potrebbero verificarsi errori di compilazione. Eccezione di tipo '{1}'. Messaggio '{2}' diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf index 681b5b63cc41f..bc16a985a23e2 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf @@ -62,6 +62,11 @@ 'UnmanagedCallersOnly' 属性はサポートされていません。 + + caller argument expression + caller argument expression + + comments after line continuation 行連結後のコメント @@ -503,6 +508,26 @@ 読み込まれたアセンブリが .NET Framework を参照しています。これはサポートされていません。 + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' ジェネレーター '{0}' でソースを生成できませんでした。出力には寄与しません。結果として、コンパイル エラーが発生する可能性があります。例外の型: '{1}'。メッセージ: '{2}' diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf index 5681d90608c47..5f9a561a4edce 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf @@ -62,6 +62,11 @@ 'UnmanagedCallersOnly' 특성은 지원되지 않습니다. + + caller argument expression + caller argument expression + + comments after line continuation 줄 연속 뒤 주석 @@ -503,6 +508,26 @@ 로드된 어셈블리가 지원되지 않는 .NET Framework를 참조합니다. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' 생성기 '{0}'이(가) 소스를 생성하지 못했습니다. 출력에 기여하지 않으므로 컴파일 오류가 발생할 수 있습니다. 예외의 형식은 '{1}'이고 메시지는 '{2}'입니다. diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf index 4aa6463cce289..2df78c729184e 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf @@ -62,6 +62,11 @@ Atrybut „UnmanagedCallersOnly” jest nieobsługiwany. + + caller argument expression + caller argument expression + + comments after line continuation komentarze po kontynuacji wiersza @@ -503,6 +508,26 @@ Załadowany zestaw odwołuje się do platformy .NET Framework, co nie jest obsługiwane. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Generator „{0}” nie mógł wygenerować źródła. W rezultacie nie będzie on współtworzyć danych wyjściowych i mogą wystąpić błędy kompilacji. Typ wyjątku: „{1}”, komunikat: „{2}” diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf index a82071ee08b67..73bb1b1bf7098 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf @@ -62,6 +62,11 @@ Não há suporte para o atributo 'UnmanagedCallersOnly'. + + caller argument expression + caller argument expression + + comments after line continuation comentários após a continuação da linha @@ -503,6 +508,26 @@ O assembly carregado referencia o .NET Framework, mas não há suporte para isso. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' O gerador '{0}' não pôde gerar a origem. Ele não contribuirá com a saída e poderão ocorrer erros de compilação como resultado. A exceção foi do tipo '{1}', com a mensagem '{2}' diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf index 2aeb50903813b..c22350b9e7dbc 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf @@ -62,6 +62,11 @@ Атрибут "UnmanagedCallersOnly" не поддерживается. + + caller argument expression + caller argument expression + + comments after line continuation комментарии после продолжения строки @@ -503,6 +508,26 @@ Загруженная сборка ссылается на платформу .NET Framework, которая не поддерживается. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' Генератору "{0}" не удалось создать источник. Это не повлияет на выходные данные и ошибки компиляции, которые могут возникнуть в результате. Тип возникшего исключения: "{1}", сообщение: "{2}" diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf index 9068dad971eb6..e3047859521ad 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf @@ -62,6 +62,11 @@ 'UnmanagedCallersOnly' özniteliği desteklenmez. + + caller argument expression + caller argument expression + + comments after line continuation satır devamı sonrası açıklamalar @@ -503,6 +508,26 @@ Yüklenen bütünleştirilmiş kod, desteklenmeyen .NET Framework'e başvuruyor. + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' '{0}' oluşturucusu kaynak oluşturamadı. Oluşturucu çıkışa katkıda bulunmayacağından, bunun sonucunda derleme hataları oluşabilir. Özel durum '{2}' iletisi ile '{1}' türündeydi diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf index 25e84d8a1afc5..af27d5f17fa0d 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf @@ -62,6 +62,11 @@ 不支持 "UnmanagedCallersOnly" 属性。 + + caller argument expression + caller argument expression + + comments after line continuation 行继续符之后的注释 @@ -503,6 +508,26 @@ 加载的程序集引用了 .NET Framework,而此操作不受支持。 + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' 生成器“{0}”未能生成源。它不会影响输出,因此可能会造成编译错误。异常的类型为“{1}”,显示消息“{2}” diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf index f8fc335555d01..72b2de9fb1b44 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf @@ -62,6 +62,11 @@ 不支援 'UnmanagedCallersOnly' 屬性。 + + caller argument expression + caller argument expression + + comments after line continuation 行接續符號後註解 @@ -503,6 +508,26 @@ 載入的組件參考了 .NET Framework,此情形不受支援。 + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name. + + + + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter '{0}' will have no effect because it's self-referential. + + + + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential. + + Generator '{0}' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type '{1}' with message '{2}' 產生器 '{0}' 無法產生來源。其不會提供給輸出,並可能導致編譯錯誤。例外狀況的類型為 '{1}',訊息為 '{2}' diff --git a/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb b/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb index 907e01fc7e04f..146e6dec801ae 100644 --- a/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb +++ b/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb @@ -1504,6 +1504,14 @@ End Module").Path parsedArgs.Errors.Verify() Assert.Equal(LanguageVersion.VisualBasic16_9, parsedArgs.ParseOptions.LanguageVersion) + parsedArgs = DefaultParse({"/langVERSION:17", "a.vb"}, _baseDirectory) + parsedArgs.Errors.Verify() + Assert.Equal(LanguageVersion.VisualBasic17, parsedArgs.ParseOptions.LanguageVersion) + + parsedArgs = DefaultParse({"/langVERSION:17.0", "a.vb"}, _baseDirectory) + parsedArgs.Errors.Verify() + Assert.Equal(LanguageVersion.VisualBasic17, parsedArgs.ParseOptions.LanguageVersion) + ' The canary check is a reminder that this test needs to be updated when a language version is added LanguageVersionAdded_Canary() @@ -2029,7 +2037,7 @@ End Module").Path ' - update the "UpgradeProject" codefixer (not yet supported in VB) ' - update all the tests that call this canary ' - update the command-line documentation (CommandLine.md) - AssertEx.SetEqual({"default", "9", "10", "11", "12", "14", "15", "15.3", "15.5", "16", "16.9", "latest"}, + AssertEx.SetEqual({"default", "9", "10", "11", "12", "14", "15", "15.3", "15.5", "16", "16.9", "17", "latest"}, System.Enum.GetValues(GetType(LanguageVersion)).Cast(Of LanguageVersion)().Select(Function(v) v.ToDisplayString())) ' For minor versions, the format should be "x.y", such as "15.3" End Sub @@ -2051,7 +2059,8 @@ End Module").Path "15.3", "15.5", "16", - "16.9" + "16.9", + "17" } AssertEx.SetEqual(versions, errorCodes) @@ -2072,8 +2081,9 @@ End Module").Path Assert.Equal(LanguageVersion.VisualBasic15_5, LanguageVersion.VisualBasic15_5.MapSpecifiedToEffectiveVersion()) Assert.Equal(LanguageVersion.VisualBasic16, LanguageVersion.VisualBasic16.MapSpecifiedToEffectiveVersion()) Assert.Equal(LanguageVersion.VisualBasic16_9, LanguageVersion.VisualBasic16_9.MapSpecifiedToEffectiveVersion()) - Assert.Equal(LanguageVersion.VisualBasic16, LanguageVersion.Default.MapSpecifiedToEffectiveVersion()) - Assert.Equal(LanguageVersion.VisualBasic16_9, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()) + Assert.Equal(LanguageVersion.VisualBasic17, LanguageVersion.VisualBasic17.MapSpecifiedToEffectiveVersion()) + Assert.Equal(LanguageVersion.VisualBasic17, LanguageVersion.Default.MapSpecifiedToEffectiveVersion()) + Assert.Equal(LanguageVersion.VisualBasic17, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()) ' The canary check is a reminder that this test needs to be updated when a language version is added LanguageVersionAdded_Canary() @@ -2097,6 +2107,8 @@ End Module").Path InlineData("16", True, LanguageVersion.VisualBasic16), InlineData("16.0", True, LanguageVersion.VisualBasic16), InlineData("16.9", True, LanguageVersion.VisualBasic16_9), + InlineData("17", True, LanguageVersion.VisualBasic17), + InlineData("17.0", True, LanguageVersion.VisualBasic17), InlineData("DEFAULT", True, LanguageVersion.Default), InlineData("default", True, LanguageVersion.Default), InlineData("LATEST", True, LanguageVersion.Latest), diff --git a/src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_CallerArgumentExpression.vb b/src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_CallerArgumentExpression.vb new file mode 100644 index 0000000000000..2ebebd2e96b5c --- /dev/null +++ b/src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_CallerArgumentExpression.vb @@ -0,0 +1,1254 @@ +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Imports Microsoft.CodeAnalysis +Imports Microsoft.CodeAnalysis.Test.Utilities +Imports Roslyn.Test.Utilities +Imports Roslyn.Test.Utilities.TestMetadata + +Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics + + Public Class AttributeTests_CallerArgumentExpression + Inherits BasicTestBase + +#Region "CallerArgumentExpression - Invocations" + + Public Sub TestGoodCallerArgumentExpressionAttribute() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log(123) + End Sub + + Private Const p As String = NameOf(p) + Sub Log(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="123").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_CaseInsensitivity() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log(123) + End Sub + + Private Const P As String = NameOf(P) + Sub Log(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="123").VerifyDiagnostics() + ' PROTOTYPE(caller-expr): Confirm whether this should be case-sensitive or case-insensitive. + ' compilation.AssertTheseDiagnostics( + ' Optional arg As String = "") + ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ']]>) + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_CaseInsensitivity_Metadata() + Dim il = " +.class private auto ansi '' +{ +} // end of class + +.class public auto ansi C + extends [mscorlib]System.Object +{ + // Methods + .method public specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2050 + // Code size 7 (0x7) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + + .method public static + void M ( + int32 i, + [opt] string s + ) cil managed + { + .param [2] = ""default"" + .custom instance void [mscorlib]System.Runtime.CompilerServices.CallerArgumentExpressionAttribute::.ctor(string) = ( + 01 00 01 49 00 00 // I + ) + // Method begins at RVA 0x2058 + // Code size 9 (0x9) + .maxstack 8 + + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: call void [mscorlib]System.Console::WriteLine(string) + IL_0007: nop + IL_0008: ret + } // end of method C::M + +} // end of class C +" + + Dim source = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(source, il, options:=TestOptions.ReleaseExe, includeVbRuntime:=True, parseOptions:=TestOptions.RegularLatest) + ' PROTOTYPE(caller-expr): Confirm whether this should be case-sensitive or case-insensitive. + CompileAndVerify(compilation, expectedOutput:="0 + 1").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_Version16_9() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log(123) + End Sub + + Private Const p As String = NameOf(p) + Sub Log(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.Regular16_9) + compilation.AssertTheseDiagnostics( + +BC36716: Visual Basic 16.9 does not support caller argument expression. + Log(123) + ~~~ +) + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_ExpressionHasTrivia() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log(' comment _ + 123 + _ + 5 ' comment + ) + End Sub + + Private Const p As String = NameOf(p) + Sub Log(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="123 + _ + 5").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_SwapArguments() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log(q:=123, p:=124) + End Sub + + Private Const p As String = NameOf(p) + Sub Log(p As Integer, q As Integer, Optional arg As String = """") + Console.WriteLine($""{p}, {q}, {arg}"") + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="124, 123, 124").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_DifferentAssembly() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices + +Public Module FromFirstAssembly + Private Const p As String = NameOf(p) + Public Sub Log(p As Integer, q As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + Dim comp1 = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, parseOptions:=TestOptions.Regular16_9) + comp1.VerifyDiagnostics() + Dim ref1 = comp1.EmitToImageReference() + + Dim source2 = " +Module Program + Public Sub Main() + FromFirstAssembly.Log(2 + 2, 3 + 1) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source2, references:={ref1, Net451.MicrosoftVisualBasic}, targetFramework:=TargetFramework.NetCoreApp, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="2 + 2").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_ExtensionMethod_ThisParameter() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Dim myIntegerExpression As Integer = 5 + myIntegerExpression.M() + End Sub + + Private Const p As String = NameOf(p) + + + Public Sub M(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="myIntegerExpression").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_ExtensionMethod_NotThisParameter() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Dim myIntegerExpression As Integer = 5 + myIntegerExpression.M(myIntegerExpression * 2) + End Sub + + Private Const q As String = NameOf(q) + + + Public Sub M(p As Integer, q As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="myIntegerExpression * 2").VerifyDiagnostics() + End Sub + + + Public Sub TestCallerArgumentExpressionAttribute_ExtensionMethod_IncorrectParameter() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Dim myIntegerExpression As Integer = 5 + myIntegerExpression.M(myIntegerExpression * 2) + End Sub + + Private Const qq As String = NameOf(qq) + + + Public Sub M(p As Integer, q As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="") + compilation.AssertTheseDiagnostics( + Optional arg As String = "") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestIncorrectParameterNameInCallerArgumentExpressionAttribute() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log() + End Sub + + Private Const pp As String = NameOf(pp) + + Sub Log( Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.Regular16_9) + CompileAndVerify(compilation, expectedOutput:="") + compilation.AssertTheseDiagnostics( + Optional arg As String = "") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestCallerArgumentWithMemberNameAttributes() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Log(0+ 0) + End Sub + + Private Const p As String = NameOf(p) + + Sub Log(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.Regular16_9) + CompileAndVerify(compilation, expectedOutput:="Main").VerifyDiagnostics() + End Sub + + + Public Sub TestCallerArgumentExpressionWithOptionalTargetParameter() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Dim callerTargetExp = ""caller target value"" + Log(0) + Log(0, callerTargetExp) + End Sub + + Private Const target As String = NameOf(target) + + Sub Log(p As Integer, Optional target As String = ""target default value"", Optional arg As String = ""arg default value"") + Console.WriteLine(target) + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="target default value +arg default value +caller target value +callerTargetExp").VerifyDiagnostics() + End Sub + + + Public Sub TestCallerArgumentExpressionWithMultipleOptionalAttribute() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + Dim callerTargetExp = ""caller target value"" + Log(0) + Log(0, callerTargetExp) + Log(0, target:=callerTargetExp) + Log(0, notTarget:=""Not target value"") + Log(0, notTarget:=""Not target value"", target:=callerTargetExp) + End Sub + + Private Const target As String = NameOf(target) + + Sub Log(p As Integer, Optional target As String = ""target default value"", Optional notTarget As String = ""not target default value"", Optional arg As String = ""arg default value"") + Console.WriteLine(target) + Console.WriteLine(arg) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="target default value +arg default value +caller target value +callerTargetExp +caller target value +callerTargetExp +target default value +arg default value +caller target value +callerTargetExp").VerifyDiagnostics() + End Sub + + + Public Sub TestCallerArgumentExpressionWithDifferentParametersReferringToEachOther() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + M() + M(""param1_value"") + M(param1:=""param1_value"") + M(param2:=""param2_value"") + M(param1:=""param1_value"", param2:=""param2_value"") + M(param2:=""param2_value"", param1:=""param1_value"") + End Sub + + Sub M( Optional param1 As String = ""param1_default"", Optional param2 As String = ""param2_default"") + Console.WriteLine($""param1: {param1}, param2: {param2}"") + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="param1: param1_default, param2: param2_default +param1: param1_value, param2: ""param1_value"" +param1: param1_value, param2: ""param1_value"" +param1: ""param2_value"", param2: param2_value +param1: param1_value, param2: param2_value +param1: param1_value, param2: param2_value").VerifyDiagnostics() + End Sub + + + Public Sub TestArgumentExpressionIsCallerMember() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + M() + End Sub + + Sub M( Optional callerName As String = """", Optional argumentExp As String = """") + Console.WriteLine(callerName) + Console.WriteLine(argumentExp) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="Main +").VerifyDiagnostics() + End Sub + + + Public Sub TestArgumentExpressionIsSelfReferential() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Module Program + Sub Main() + M() + M(""value"") + End Sub + + Sub M( Optional p As String = """") + Console.WriteLine(p) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:=" +value") + compilation.AssertTheseDiagnostics( + Optional p As String = "") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestArgumentExpressionIsSelfReferential_Metadata() + Dim il = ".class private auto ansi '' +{ +} // end of class + +.class public auto ansi abstract sealed beforefieldinit C + extends [mscorlib]System.Object +{ + // Methods + .method public hidebysig static + void M ( + [opt] string p + ) cil managed + { + .param [1] = """" + .custom instance void [mscorlib]System.Runtime.CompilerServices.CallerArgumentExpressionAttribute::.ctor(string) = ( + 01 00 01 70 00 00 + ) + // Method begins at RVA 0x2050 + // Code size 9 (0x9) + .maxstack 8 + + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: call void [mscorlib]System.Console::WriteLine(string) + IL_0007: nop + IL_0008: ret + } // end of method C::M + +} // end of class C" + + Dim source = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(source, il, options:=TestOptions.ReleaseExe, includeVbRuntime:=True, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:=" +value").VerifyDiagnostics() + End Sub +#End Region + +#Region "CallerArgumentExpression - Attributes" + + Public Sub TestGoodCallerArgumentExpressionAttribute_Attribute() + Dim source = " +Imports System +Imports System.Reflection +Imports System.Runtime.CompilerServices +Public Class MyAttribute : Inherits Attribute + Private Const p As String = ""p"" + Sub New(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Class + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttribute(GetType(MyAttribute)) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="123").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_ExpressionHasTrivia_Attribute() + Dim source = " +Imports System +Imports System.Reflection +Imports System.Runtime.CompilerServices +Public Class MyAttribute : Inherits Attribute + Private Const p As String = ""p"" + Sub New(p As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Class + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttribute(GetType(MyAttribute)) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="123 _ ' comment + + 5").VerifyDiagnostics() + End Sub + + + Public Sub TestGoodCallerArgumentExpressionAttribute_DifferentAssembly_AttributeConstructor() + Dim source = " +Imports System +Imports System.Runtime.CompilerServices +Public Class MyAttribute : Inherits Attribute + Private Const p As String = ""p"" + Sub New(p As Integer, q As Integer, Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Class +" + Dim comp1 = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp) + comp1.VerifyDiagnostics() + Dim ref1 = comp1.EmitToImageReference() + + Dim source2 = " +Imports System.Reflection + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttribute(GetType(MyAttribute)) + End Sub +End Module +" + Dim compilation = CreateCompilation(source2, references:={ref1, Net451.MicrosoftVisualBasic}, targetFramework:=TargetFramework.NetCoreApp, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="2 + 2").VerifyDiagnostics() + End Sub + + + Public Sub TestIncorrectParameterNameInCallerArgumentExpressionAttribute_AttributeConstructor() + Dim source = " +Imports System +Imports System.Reflection +Imports System.Runtime.CompilerServices +Public Class MyAttribute : Inherits Attribute + Private Const p As String = ""p"" + Sub New( Optional arg As String = """") + Console.WriteLine(arg) + End Sub +End Class + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttribute(GetType(MyAttribute)) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="") + compilation.AssertTheseDiagnostics( + Optional arg As String = "") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestCallerArgumentExpressionWithOptionalTargetParameter_AttributeConstructor() + Dim source = " +Imports System +Imports System.Reflection +Imports System.Runtime.CompilerServices + + +Public Class MyAttribute : Inherits Attribute + Private Const target As String = NameOf(target) + Sub New(p As Integer, Optional target As String = ""target default value"", Optional arg As String = ""arg default value"") + Console.WriteLine(target) + Console.WriteLine(arg) + End Sub +End Class + + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttributes(GetType(MyAttribute)) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="target default value +arg default value +caller target value +""caller target value""").VerifyDiagnostics() + End Sub + + + Public Sub TestArgumentExpressionIsReferingToItself_AttributeConstructor() + Dim source = " +Imports System +Imports System.Reflection +Imports System.Runtime.CompilerServices + + +Public Class MyAttribute : Inherits Attribute + Private Const p As String = NameOf(p) + Sub New( Optional p As String = ""default"") + Console.WriteLine(p) + End Sub +End Class + + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttributes(GetType(MyAttribute)) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="default +value") + compilation.AssertTheseDiagnostics( + Optional p As String = "default") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestArgumentExpressionInAttributeConstructor_OptionalAndFieldInitializer() + Dim source = " +Imports System +Imports System.Reflection +Imports System.Runtime.CompilerServices + +Public Class MyAttribute : Inherits Attribute + Private Const a As String = NameOf(a) + Sub New( Optional expr_a As String = """", Optional a As String = """") + Console.WriteLine($""'{a}', '{expr_a}'"") + End Sub + + Public I1 As Integer + Public I2 As Integer + Public I3 As Integer +End Class + + +Public Module Program + Sub Main() + GetType(Program).GetCustomAttribute(GetType(MyAttribute)) + End Sub +End Module +" + + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="'', ''").VerifyDiagnostics() + End Sub +#End Region + +#Region "CallerArgumentExpression - Test various symbols" + + Public Sub TestIndexers() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Const i As String = NameOf(i) + + Default Public Property Item(i As Integer, Optional s As String = """") As Integer + Get + Return i + End Get + Set(value As Integer) + Console.WriteLine($""{i}, {s}"") + End Set + End Property + + Public Shared Sub Main() + Dim p As New Program() + p(1+ 1) = 5 + p(2+ 2, ""explicit-value"") = 5 + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="2, 1+ 1 +4, explicit-value").VerifyDiagnostics() + End Sub + + + Public Sub TestDelegate1() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Delegate Sub M(s1 As String, ByRef s2 as String) + + Shared Sub MImpl(s1 As String, ByRef s2 As String) + Console.WriteLine(s1) + Console.WriteLine(s2) + End Sub + + Public Shared Sub Main() + Dim x As M = AddressOf MImpl + x.EndInvoke("""", Nothing) + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation).VerifyDiagnostics().VerifyIL("Program.Main", " +{ + // Code size 27 (0x1b) + .maxstack 3 + .locals init (String V_0) + IL_0000: ldnull + IL_0001: ldftn ""Sub Program.MImpl(String, ByRef String)"" + IL_0007: newobj ""Sub Program.M..ctor(Object, System.IntPtr)"" + IL_000c: ldstr """" + IL_0011: stloc.0 + IL_0012: ldloca.s V_0 + IL_0014: ldnull + IL_0015: callvirt ""Sub Program.M.EndInvoke(ByRef String, System.IAsyncResult)"" + IL_001a: ret +} +") + End Sub + + + Public Sub TestDelegate2() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Delegate Sub M(s1 As String, Optional ByRef s2 as String = """") + + Shared Sub MImpl(s1 As String, ByRef s2 As String) + Console.WriteLine(s1) + Console.WriteLine(s2) + End Sub + + Public Shared Sub Main() + Dim x As M = AddressOf MImpl + x.EndInvoke("""", Nothing) + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + compilation.AssertTheseDiagnostics( + Optional ByRef s2 as String = "") + ~~~~~~~~ +]]>) + + End Sub + + + Public Sub ComClass() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices +Imports Microsoft.VisualBasic + +Namespace System.Runtime.InteropServices + + Public NotInheritable Class GuidAttribute + Inherits Attribute + + Public Sub New(guid As String) + Value = guid + End Sub + + Public ReadOnly Property Value As String + End Class + + + Public NotInheritable Class ClassInterfaceAttribute + Inherits Attribute + + Public Sub New(classInterfaceType As ClassInterfaceType) + Value = classInterfaceType + End Sub + + Public Sub New(classInterfaceType As Short) + Value = CType(classInterfaceType, ClassInterfaceType) + End Sub + + Public ReadOnly Property Value As ClassInterfaceType + End Class + + + Public NotInheritable Class DispIdAttribute + Inherits Attribute + + Public Sub New(dispId As Integer) + Value = dispId + End Sub + + Public ReadOnly Property Value As Integer + End Class + + Public Enum ClassInterfaceType + None = 0 + AutoDispatch = 1 + AutoDual = 2 + End Enum +End Namespace + + +Public Class ComClass1 + ' Use the Region directive to define a section named COM Guids. +#Region ""COM GUIDs"" + ' These GUIDs provide the COM identity for this class + ' and its COM interfaces. You can generate + ' these guids using guidgen.exe + Public Const ClassId As String = ""7666AC25-855F-4534-BC55-27BF09D49D46"" + Public Const InterfaceId As String = ""54388137-8A76-491e-AA3A-853E23AC1217"" + Public Const EventsId As String = ""EA329A13-16A0-478d-B41F-47583A761FF2"" +#End Region + + Public Sub New() + MyBase.New() + End Sub + + Public Sub M(x As Integer, Optional y As String = """") + Console.WriteLine(y) + End Sub +End Class +" + Dim comp1 = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseDll, parseOptions:=TestOptions.RegularLatest) + comp1.VerifyDiagnostics() + + Dim source2 = " +Module Program + Sub Main() + Dim x As ComClass1._ComClass1 = New ComClass1() + x.M(1 + 2) + End Sub +End Module +" + Dim comp2 = CreateCompilation(source2, references:={comp1.EmitToImageReference()}, TestOptions.ReleaseExe, TestOptions.RegularLatest) + CompileAndVerify(comp2, expectedOutput:="1 + 2").VerifyDiagnostics() + End Sub + + + Public Sub Tuple() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + + +Namespace System.Runtime.CompilerServices + Public Interface ITuple + ReadOnly Property Length As Integer + Default ReadOnly Property Item(index As Integer) As Object + End Interface +End Namespace + +Namespace System + Public Structure ValueTuple(Of T1, T2) : Implements ITuple + Public Item1 As T1 + Public Item2 As T2 + + Public Sub New(item1 As T1, item2 As T2) + item1 = item1 + item2 = item2 + End Sub + + Default Public ReadOnly Property Item(index As Integer) As Object Implements ITuple.Item + Get + Throw New NotImplementedException() + End Get + End Property + + Public ReadOnly Property Length As Integer Implements ITuple.Length + Get + Throw New NotImplementedException() + End Get + End Property + + Public Sub M(s1 As String, Optional s2 As String = """") + Console.WriteLine(s2) + End Sub + End Structure +End Namespace + + +Module Program + Sub Main() + Dim x = New ValueTuple(Of Integer, Integer)(0, 0) + x.M(1 + 2) + End Sub +End Module +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="1 + 2").VerifyDiagnostics() + End Sub + + + Public Sub TestOperator() + Dim il = ".class private auto ansi '' +{ +} // end of class + +.class public auto ansi C + extends [mscorlib]System.Object +{ + // Methods + .method public specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2050 + // Code size 7 (0x7) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method C::.ctor + + .method public specialname static + class C op_Addition ( + class C left, + [opt] int32 right + ) cil managed + { + .param [2] = int32(0) + .custom instance void [mscorlib]System.Runtime.CompilerServices.CallerArgumentExpressionAttribute::.ctor(string) = ( + 01 00 04 6c 65 66 74 00 00 + ) + // Method begins at RVA 0x2058 + // Code size 7 (0x7) + .maxstack 1 + .locals init ( + [0] class C + ) + + IL_0000: nop + IL_0001: ldnull + IL_0002: stloc.0 + IL_0003: br.s IL_0005 + + IL_0005: ldloc.0 + IL_0006: ret + } // end of method C::op_Addition + +} // end of class C +" + + Dim source = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(source, il, options:=TestOptions.ReleaseExe, includeVbRuntime:=True, parseOptions:=TestOptions.RegularLatest) + compilation.VerifyDiagnostics() + End Sub + + + Public Sub TestSetter1() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Public Property P As String + Get + Return ""Return getter"" + End Get + Set( value As String) + Console.WriteLine(value) + End Set + End Property + + Public Shared Sub Main() + Dim prog As New Program() + prog.P = ""New value"" + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="New value") + compilation.AssertTheseDiagnostics( + value As String) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestSetter2() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Public Property P As String + Get + Return ""Return getter"" + End Get + Set( value As String) + Console.WriteLine(value) + End Set + End Property + + Public Shared Sub Main() + Dim prog As New Program() + prog.P = ""New value"" + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="New value") + compilation.AssertTheseDiagnostics( + value As String) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +]]>) + End Sub + + + Public Sub TestSetter3() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Public Property P As String + Get + Return ""Return getter"" + End Get + Set( Optional value As String = ""default"") + Console.WriteLine(value) + End Set + End Property + + Public Shared Sub Main() + Dim prog As New Program() + prog.P = ""New value"" + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + compilation.AssertTheseDiagnostics( + Optional value As String = "default") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC31065: 'Set' parameter cannot be declared 'Optional'. + Set( Optional value As String = "default") + ~~~~~~~~ +]]>) + End Sub + + + Public Sub TestSetter4() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Public Property P As String + Get + Return ""Return getter"" + End Get + Set( Optional value As String = ""default"") + Console.WriteLine(value) + End Set + End Property + + Public Shared Sub Main() + Dim prog As New Program() + prog.P = ""New value"" + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + compilation.AssertTheseDiagnostics( + Optional value As String = "default") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC31065: 'Set' parameter cannot be declared 'Optional'. + Set( Optional value As String = "default") + ~~~~~~~~ +]]>) + End Sub + + + Public Sub TestSetter5() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Public Property P(x As String) As String + Get + Return ""Return getter"" + End Get + Set( Optional value As String = ""default"") + Console.WriteLine(value) + End Set + End Property + + Public Shared Sub Main() + Dim prog As New Program() + prog.P(""xvalue"") = ""New value"" + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + compilation.AssertTheseDiagnostics( + Optional value As String = "default") + ~~~~~~~~ +]]>) + End Sub + + + Public Sub TestSetter6() + Dim source As String = " +Imports System +Imports System.Runtime.CompilerServices + +Class Program + Public Property P(x As String) As String + Get + Return ""Return getter"" + End Get + Set( value As String) + Console.WriteLine(value) + End Set + End Property + + Public Shared Sub Main() + Dim prog As New Program() + prog.P(""xvalue"") = ""New value"" + End Sub +End Class +" + Dim compilation = CreateCompilation(source, targetFramework:=TargetFramework.NetCoreApp, references:={Net451.MicrosoftVisualBasic}, options:=TestOptions.ReleaseExe, parseOptions:=TestOptions.RegularLatest) + CompileAndVerify(compilation, expectedOutput:="New value").VerifyDiagnostics() + End Sub +#End Region + End Class +End Namespace