diff --git a/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs index d38b35d93cad7..6ffbd50e0b6c9 100644 --- a/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs @@ -933,7 +933,7 @@ internal bool CalculateUseSiteDiagnostic(ref DiagnosticInfo result) // Check return type, custom modifiers, parameters if (DeriveUseSiteDiagnosticFromType(ref result, this.ReturnTypeWithAnnotations, - MethodKind == MethodKind.PropertySet ? + IsInitOnly ? AllowedRequiredModifierType.System_Runtime_CompilerServices_IsExternalInit : AllowedRequiredModifierType.None) || DeriveUseSiteDiagnosticFromCustomModifiers(ref result, this.RefCustomModifiers, AllowedRequiredModifierType.System_Runtime_InteropServices_InAttribute) || diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs index e7575128d4093..10438c3636301 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs @@ -3269,6 +3269,65 @@ void M2() Assert.True(method.HasUnsupportedMetadata); } + [Fact] + public void ModReqOnStaticSet() + { + string il = @" +.class public auto ansi beforefieldinit C extends System.Object +{ + .method public hidebysig newslot specialname + static void modreq(System.Runtime.CompilerServices.IsExternalInit) set_P(int32 x) cil managed + { + IL_0000: ldnull + IL_0001: throw + } + + .property instance int32 P() + { + .set void modreq(System.Runtime.CompilerServices.IsExternalInit) C::set_P(int32) + } + + .method public hidebysig specialname rtspecialname instance void .ctor () cil managed + { + IL_0000: ldnull + IL_0001: throw + } +} + +.class public auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsExternalInit extends System.Object +{ + .method public hidebysig specialname rtspecialname instance void .ctor () cil managed + { + IL_0000: ldnull + IL_0001: throw + } +} +"; + string source = @" +public class D +{ + void M2() + { + C.P = 2; + } +} +"; + + var reference = CreateMetadataReferenceFromIlSource(il); + var comp = CreateCompilation(source, references: new[] { reference }, parseOptions: TestOptions.Regular9); + comp.VerifyEmitDiagnostics( + // (6,11): error CS0570: 'C.P.set' is not supported by the language + // C.P = 2; + Diagnostic(ErrorCode.ERR_BindToBogus, "P").WithArguments("C.P.set").WithLocation(6, 11) + ); + + var method = (PEMethodSymbol)comp.GlobalNamespace.GetMember("C.set_P"); + Assert.False(method.IsInitOnly); + Assert.False(method.GetPublicSymbol().IsInitOnly); + Assert.True(method.HasUseSiteError); + Assert.True(method.HasUnsupportedMetadata); + } + [Fact] public void ModReqOnMethodParameter() { diff --git a/src/Compilers/Test/Utilities/VisualBasic/MockSymbols.vb b/src/Compilers/Test/Utilities/VisualBasic/MockSymbols.vb index c8d4c9e358dbe..9ef344d1a45c6 100644 --- a/src/Compilers/Test/Utilities/VisualBasic/MockSymbols.vb +++ b/src/Compilers/Test/Utilities/VisualBasic/MockSymbols.vb @@ -534,6 +534,12 @@ Friend Class MockMethodSymbol End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Public Overrides ReadOnly Property IsVararg As Boolean Get Return False diff --git a/src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb b/src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb index 3e4402171cd48..15fac0d085b5d 100644 --- a/src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb +++ b/src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb @@ -11,6 +11,9 @@ Public Class TestOptions Public Shared ReadOnly Script As New VisualBasicParseOptions(kind:=SourceCodeKind.Script) Public Shared ReadOnly Regular As New VisualBasicParseOptions(kind:=SourceCodeKind.Regular) Public Shared ReadOnly Regular15_5 As VisualBasicParseOptions = Regular.WithLanguageVersion(LanguageVersion.VisualBasic15_5) + Public Shared ReadOnly Regular16 As VisualBasicParseOptions = Regular.WithLanguageVersion(LanguageVersion.VisualBasic16) + Public Shared ReadOnly Regular16_9 As VisualBasicParseOptions = Regular.WithLanguageVersion(LanguageVersion.VisualBasic16_9) + Public Shared ReadOnly RegularLatest As VisualBasicParseOptions = Regular.WithLanguageVersion(LanguageVersion.Latest) Public Shared ReadOnly RegularWithLegacyStrongName As VisualBasicParseOptions = Regular.WithFeature("UseLegacyStrongNameProvider") Public Shared ReadOnly ReleaseDll As VisualBasicCompilationOptions = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel:=OptimizationLevel.Release).WithParseOptions(Regular) diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Attributes.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Attributes.vb index eb7b91291bce7..6816cd39dfbf0 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Attributes.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Attributes.vb @@ -484,6 +484,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic AccessCheck.GetAccessibilityForErrorMessage(setMethod, Me.Compilation.Assembly)) hasErrors = True End If + + If setMethod.IsInitOnly Then + InternalSyntax.Parser.CheckFeatureAvailability(diagnostics, + identifierName.Location, + DirectCast(identifierName.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion, + InternalSyntax.Feature.InitOnlySettersUsage) + End If End If Case Else diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb index d6c2d4459f4fd..71bde61d69d60 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb @@ -978,7 +978,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic [property], propertyGroup, PropertyAccessKind.Unknown, - [property].IsWritable(receiver, Me), + [property].IsWritable(receiver, Me, isKnownTargetOfObjectMemberInintializer:=False), receiver, boundArguments, argumentInfo.DefaultArguments, @@ -2905,6 +2905,18 @@ ProduceBoundNode: outConversion, outPlaceholder, targetType, copyBackExpression.HasErrors).MakeCompilerGenerated() Else + Dim propertyAccess = TryCast(argument, BoundPropertyAccess) + + If propertyAccess IsNot Nothing AndAlso propertyAccess.AccessKind <> PropertyAccessKind.Get AndAlso + propertyAccess.PropertySymbol.SetMethod?.IsInitOnly Then + + Debug.Assert(Not propertyAccess.IsWriteable) ' Used to be writable prior to VB 16.9, which caused a use-site error while binding an assignment above. + InternalSyntax.Parser.CheckFeatureAvailability(diagnostics, + argument.Syntax.Location, + DirectCast(argument.Syntax.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion, + InternalSyntax.Feature.InitOnlySettersUsage) + End If + ' Need to allocate a temp of the target type, ' init it with argument's value, ' pass it ByRef. Code gen will do this. diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb index 8573932c52141..172969b770035 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb @@ -663,12 +663,28 @@ Namespace Microsoft.CodeAnalysis.VisualBasic target, diagnostics) + Dim propertyAccess = TryCast(target, BoundPropertyAccess) + + If propertyAccess IsNot Nothing Then + Debug.Assert(propertyAccess.AccessKind = PropertyAccessKind.Unknown) + ' See if we can reclassify access as writable given that this is an object initializer. + ' This is needed to accommodate init-only properties. + If propertyAccess.AccessKind <> PropertyAccessKind.Get AndAlso Not propertyAccess.IsWriteable AndAlso + propertyAccess.PropertySymbol.IsWritable(propertyAccess.ReceiverOpt, Me, isKnownTargetOfObjectMemberInintializer:=True) Then + + propertyAccess = propertyAccess.Update(propertyAccess.PropertySymbol, propertyAccess.PropertyGroupOpt, propertyAccess.AccessKind, isWriteable:=True, + propertyAccess.IsLValue, propertyAccess.ReceiverOpt, propertyAccess.Arguments, propertyAccess.DefaultArguments, + propertyAccess.Type) + target = propertyAccess + End If + End If + If Not target.HasErrors Then Dim isShared As Boolean If target.Kind = BoundKind.FieldAccess Then isShared = DirectCast(target, BoundFieldAccess).FieldSymbol.IsShared Else - Dim [property] = DirectCast(target, BoundPropertyAccess).PropertySymbol + Dim [property] = propertyAccess.PropertySymbol ' Treat extension properties as Shared in this context so we generate ' an error (BC30991) that such properties cannot be used in an initializer. ' Currently, there is only one extension property, InternalXmlHelper.Value: diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Statements.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Statements.vb index 18b7d93e48859..83c8b7e4bfa33 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Statements.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Statements.vb @@ -1914,33 +1914,47 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Debug.Assert(propertyAccess.AccessKind <> PropertyAccessKind.Get) + Dim setMethod = propertySymbol.GetMostDerivedSetMethod() + If Not propertyAccess.IsWriteable Then - ReportDiagnostic(diagnostics, node, ERRID.ERR_NoSetProperty1, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol)) + If setMethod Is Nothing Then + ReportDiagnostic(diagnostics, node, ERRID.ERR_NoSetProperty1, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol)) + Else + Debug.Assert(setMethod.IsInitOnly) + ReportDiagnostic(diagnostics, node, ERRID.ERR_AssignmentInitOnly, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol)) + End If + isError = True - Else - Dim setMethod = propertySymbol.GetMostDerivedSetMethod() + End If - ' NOTE: the setMethod could not be present, while it would still be - ' possible to write to the property in a case - ' where the property is a getter-only autoproperty - ' and the writing is happening in the corresponding constructor or initializer - If setMethod IsNot Nothing Then - ReportDiagnosticsIfObsoleteOrNotSupportedByRuntime(diagnostics, setMethod, node) + ' NOTE: the setMethod could not be present, while it would still be + ' possible to write to the property in a case + ' where the property is a getter-only autoproperty + ' and the writing is happening in the corresponding constructor or initializer + If setMethod IsNot Nothing Then + + If propertyAccess.IsWriteable AndAlso setMethod.IsInitOnly Then + InternalSyntax.Parser.CheckFeatureAvailability(diagnostics, + node.Location, + DirectCast(node.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion, + InternalSyntax.Feature.InitOnlySettersUsage) + End If - If ReportUseSiteError(diagnostics, op1.Syntax, setMethod) Then - isError = True - Else - Dim accessThroughType = GetAccessThroughType(propertyAccess.ReceiverOpt) - Dim useSiteDiagnostics As HashSet(Of DiagnosticInfo) = Nothing + ReportDiagnosticsIfObsoleteOrNotSupportedByRuntime(diagnostics, setMethod, node) - If Not IsAccessible(setMethod, useSiteDiagnostics, accessThroughType) AndAlso - IsAccessible(propertySymbol, useSiteDiagnostics, accessThroughType) Then - ReportDiagnostic(diagnostics, node, ERRID.ERR_NoAccessibleSet, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol)) - isError = True - End If + If ReportUseSiteError(diagnostics, op1.Syntax, setMethod) Then + isError = True + Else + Dim accessThroughType = GetAccessThroughType(propertyAccess.ReceiverOpt) + Dim useSiteDiagnostics As HashSet(Of DiagnosticInfo) = Nothing - diagnostics.Add(node, useSiteDiagnostics) + If Not IsAccessible(setMethod, useSiteDiagnostics, accessThroughType) AndAlso + IsAccessible(propertySymbol, useSiteDiagnostics, accessThroughType) Then + ReportDiagnostic(diagnostics, node, ERRID.ERR_NoAccessibleSet, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol)) + isError = True End If + + diagnostics.Add(node, useSiteDiagnostics) End If End If diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_XmlLiterals.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_XmlLiterals.vb index 59a6fe626db06..9dc6318182ce1 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_XmlLiterals.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_XmlLiterals.vb @@ -1881,6 +1881,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return _originalDefinition.IsInitOnly + End Get + End Property + Public Overrides ReadOnly Property IsVararg As Boolean Get Return _originalDefinition.IsVararg diff --git a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb index b31a08f1ab5a8..68b862577dd81 100644 --- a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb +++ b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb @@ -1752,6 +1752,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ERR_RuntimeDoesNotSupportDefaultInterfaceImplementation = 37309 ERR_RuntimeDoesNotSupportProtectedAccessForInterfaceMember = 37310 + ERR_AssignmentInitOnly = 37311 + ERR_OverridingInitOnlyProperty = 37312 + ERR_PropertyDoesntImplementInitOnly = 37313 + '// WARNINGS BEGIN HERE WRN_UseOfObsoleteSymbol2 = 40000 WRN_InvalidOverrideDueToTupleNames2 = 40001 @@ -2038,5 +2042,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic FEATURE_InterpolatedStrings FEATURE_UnconstrainedTypeParameterInConditional FEATURE_CommentsAfterLineContinuation + FEATURE_InitOnlySettersUsage End Enum End Namespace diff --git a/src/Compilers/VisualBasic/Portable/LanguageVersion.vb b/src/Compilers/VisualBasic/Portable/LanguageVersion.vb index 4722b31904890..3b1b9698ad173 100644 --- a/src/Compilers/VisualBasic/Portable/LanguageVersion.vb +++ b/src/Compilers/VisualBasic/Portable/LanguageVersion.vb @@ -20,6 +20,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic VisualBasic15_3 = 1503 VisualBasic15_5 = 1505 VisualBasic16 = 1600 + VisualBasic16_9 = 1609 Latest = Integer.MaxValue End Enum @@ -37,7 +38,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic LanguageVersion.VisualBasic15, LanguageVersion.VisualBasic15_3, LanguageVersion.VisualBasic15_5, - LanguageVersion.VisualBasic16 + LanguageVersion.VisualBasic16, + LanguageVersion.VisualBasic16_9 Return True End Select @@ -67,6 +69,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Return "15.5" Case LanguageVersion.VisualBasic16 Return "16" + Case LanguageVersion.VisualBasic16_9 + Return "16.9" Case Else Throw ExceptionUtilities.UnexpectedValue(value) End Select @@ -82,8 +86,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Public Function MapSpecifiedToEffectiveVersion(version As LanguageVersion) As LanguageVersion Select Case version - Case LanguageVersion.Latest, - LanguageVersion.Default + Case LanguageVersion.Latest + Return LanguageVersion.VisualBasic16_9 + Case LanguageVersion.Default Return LanguageVersion.VisualBasic16 Case Else Return version @@ -92,7 +97,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Friend ReadOnly Property CurrentVersion As LanguageVersion Get - Return LanguageVersion.VisualBasic16 + Return LanguageVersion.VisualBasic16_9 End Get End Property @@ -121,6 +126,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Return "15.5" Case LanguageVersion.VisualBasic16 Return "16" + Case LanguageVersion.VisualBasic16_9 + Return "16.9" Case LanguageVersion.Default Return "default" Case LanguageVersion.Latest @@ -158,6 +165,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic result = LanguageVersion.VisualBasic15_5 Case "16", "16.0" result = LanguageVersion.VisualBasic16 + Case "16.9" + result = LanguageVersion.VisualBasic16_9 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 3a4444c4f3f92..db503ccb6d48d 100644 --- a/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb +++ b/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb @@ -40,6 +40,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax PrivateProtected UnconstrainedTypeParameterInConditional CommentsAfterLineContinuation + InitOnlySettersUsage End Enum Friend Module FeatureExtensions @@ -102,6 +103,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Feature.CommentsAfterLineContinuation Return LanguageVersion.VisualBasic16 + Case Feature.InitOnlySettersUsage + Return LanguageVersion.VisualBasic16_9 + Case Else Throw ExceptionUtilities.UnexpectedValue(feature) End Select @@ -173,6 +177,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return ERRID.FEATURE_UnconstrainedTypeParameterInConditional Case Feature.CommentsAfterLineContinuation Return ERRID.FEATURE_CommentsAfterLineContinuation + Case Feature.InitOnlySettersUsage + Return ERRID.FEATURE_InitOnlySettersUsage 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 2afc778f2f9de..730ef4ff5435d 100644 --- a/src/Compilers/VisualBasic/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/VisualBasic/Portable/PublicAPI.Unshipped.txt @@ -1,2 +1,3 @@ +Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.VisualBasic16_9 = 1609 -> Microsoft.CodeAnalysis.VisualBasic.LanguageVersion Microsoft.CodeAnalysis.VisualBasic.VisualBasicGeneratorDriver 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/Symbols/ErrorMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/ErrorMethodSymbol.vb index 70a543270d6b2..eb1c938ca0e71 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/ErrorMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/ErrorMethodSymbol.vb @@ -117,6 +117,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Friend Overrides ReadOnly Property IsMethodKindBasedOnSyntax As Boolean Get Return False diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb index 544a55d04953d..876356c96964c 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb @@ -49,7 +49,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Private Structure PackedFlags ' Flags are packed into a 32-bit int with the following layout: - ' | h|g|f|e|d|c|b|aaaaa| + ' | |j|i|h|g|f|e|d|c|b|aaaaa| ' ' a = method kind. 5 bits ' b = method kind populated. 1 bit @@ -59,6 +59,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE ' f = custom attributes populated. 1 bit ' g = use site diagnostic populated. 1 bit ' h = conditional attributes populated. 1 bit + ' i = is init-only. 1 bit. + ' j = is init-only populated. 1 bit. Private _bits As Integer @@ -71,6 +73,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Private Const s_isCustomAttributesPopulatedBit As Integer = 1 << 9 Private Const s_isUseSiteDiagnosticPopulatedBit As Integer = 1 << 10 Private Const s_isConditionalAttributePopulatedBit As Integer = 1 << 11 + Private Const s_isInitOnlyBit = 1 << 12 + Private Const s_isInitOnlyPopulatedBit = 1 << 13 Public Property MethodKind As MethodKind Get @@ -124,6 +128,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End Get End Property + Public ReadOnly Property IsInitOnly As Boolean + Get + Return (_bits And s_isInitOnlyBit) <> 0 + End Get + End Property + + Public ReadOnly Property IsInitOnlyPopulated As Boolean + Get + Return (_bits And s_isInitOnlyPopulatedBit) <> 0 + End Get + End Property + Private Shared Function BitsAreUnsetOrSame(bits As Integer, mask As Integer) As Boolean Return (bits And mask) = 0 OrElse (bits And mask) = mask End Function @@ -156,6 +172,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Public Sub SetIsConditionalAttributePopulated() ThreadSafeFlagOperations.Set(_bits, s_isConditionalAttributePopulatedBit) End Sub + + Public Sub InitializeIsInitOnly(isInitOnly As Boolean) + Dim bitsToSet = If(isInitOnly, s_isInitOnlyBit, 0) Or s_isInitOnlyPopulatedBit + Debug.Assert(BitsAreUnsetOrSame(_bits, bitsToSet)) + ThreadSafeFlagOperations.Set(_bits, bitsToSet) + End Sub End Structure ''' @@ -831,6 +853,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + If Not _packedFlags.IsInitOnlyPopulated Then + + Dim result As Boolean = Not Me.IsShared AndAlso + Me.MethodKind = MethodKind.PropertySet AndAlso + CustomModifierUtils.HasIsExternalInitModifier(ReturnTypeCustomModifiers) + + _packedFlags.InitializeIsInitOnly(result) + End If + + Return _packedFlags.IsInitOnly + End Get + End Property + Public Overrides ReadOnly Property Locations As ImmutableArray(Of Location) Get Return StaticCast(Of Location).From(_containingType.ContainingPEModule.MetadataLocation) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/MethodSignatureComparer.vb b/src/Compilers/VisualBasic/Portable/Symbols/MethodSignatureComparer.vb index b96b1663e2835..449d48c014410 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/MethodSignatureComparer.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/MethodSignatureComparer.vb @@ -36,13 +36,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ParameterByrefMismatch = 1 << 11 ParamArrayMismatch = 1 << 12 PropertyAccessorMismatch = 1 << 13 - VarargMismatch = 1 << 14 + ''' + ''' Taken into consideration only if is set. + ''' + PropertyInitOnlyMismatch = 1 << 14 + VarargMismatch = 1 << 15 ''' ''' Mismatch in total number of parameters, both required and optional ''' ''' - TotalParameterCountMismatch = 1 << 15 - TupleNamesMismatch = 1 << 16 + TotalParameterCountMismatch = 1 << 16 + TupleNamesMismatch = 1 << 17 + + AllMismatches = (1 << 18) - 1 AllParameterMismatches = OptionalParameterMismatch Or @@ -56,8 +62,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols OptionalParameterValueMismatch Or TupleNamesMismatch - AllMismatches = (1 << 17) - 1 - ' The set of mismatches for DetailedCompare that are ignored ' when testing for conflicting method in a class, or first ' pass of finding an overridden method. See 4.1.1 of language spec. diff --git a/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb index 609630484b009..ee375e3cf897d 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb @@ -111,10 +111,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property - ' https://github.com/dotnet/roslyn/issues/44870 VB will be able to consume 'init' set accessors Private ReadOnly Property IMethodSymbol_IsInitOnly As Boolean Implements IMethodSymbol.IsInitOnly Get - Return False + Return IsInitOnly End Get End Property @@ -135,6 +134,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' Public MustOverride ReadOnly Property IsIterator As Boolean + ''' + ''' Indicates whether the accessor is marked with the 'init' modifier. + ''' + Public MustOverride ReadOnly Property IsInitOnly As Boolean + ''' ''' Source: Returns False; methods from source cannot return by reference. ''' Metadata: Returns whether or not this method returns by reference. @@ -642,7 +646,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return refModifiersErrorInfo End If - Dim typeModifiersErrorInfo = DeriveUseSiteErrorInfoFromCustomModifiers(Me.ReturnTypeCustomModifiers) + Dim typeModifiersErrorInfo = DeriveUseSiteErrorInfoFromCustomModifiers(Me.ReturnTypeCustomModifiers, allowIsExternalInit:=IsInitOnly) If typeModifiersErrorInfo IsNot Nothing AndAlso typeModifiersErrorInfo.Code = ERRID.ERR_UnsupportedMethod1 Then Return typeModifiersErrorInfo diff --git a/src/Compilers/VisualBasic/Portable/Symbols/PropertySignatureComparer.vb b/src/Compilers/VisualBasic/Portable/Symbols/PropertySignatureComparer.vb index 77ea329b2cab3..04b6e89d45c46 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/PropertySignatureComparer.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/PropertySignatureComparer.vb @@ -165,6 +165,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols GoTo Done End If End If + + If (comparisons And SymbolComparisonResults.PropertyInitOnlyMismatch) <> 0 AndAlso + prop1.SetMethod?.IsInitOnly <> prop2.SetMethod?.IsInitOnly Then + + results = results Or SymbolComparisonResults.PropertyInitOnlyMismatch + If (stopIfAny And SymbolComparisonResults.PropertyInitOnlyMismatch) <> 0 Then + GoTo Done + End If + End If End If If (comparisons And (SymbolComparisonResults.ReturnTypeMismatch Or SymbolComparisonResults.CustomModifierMismatch Or SymbolComparisonResults.TupleNamesMismatch)) <> 0 Then diff --git a/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb index 0ebfd765c3e90..419267b20b74a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb @@ -144,13 +144,59 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' ''' Indicates if the property can be written into, which means this ''' property has a setter or it is a getter only autoproperty accessed - ''' in a corresponding constructor or initializer + ''' in a corresponding constructor or initializer. + ''' If the setter is init-only, we also check that it is accessed in a constructor + ''' on Me/MyBase/MyClass or is a target of a member initializer in an object member + ''' initializer. ''' - Friend Function IsWritable(receiverOpt As BoundExpression, containingBinder As Binder) As Boolean + Friend Function IsWritable(receiverOpt As BoundExpression, containingBinder As Binder, isKnownTargetOfObjectMemberInintializer As Boolean) As Boolean Debug.Assert(containingBinder IsNot Nothing) - If Me.HasSet Then - Return True + Dim mostDerivedSet As MethodSymbol = Me.GetMostDerivedSetMethod() + + If mostDerivedSet IsNot Nothing Then + If Not mostDerivedSet.IsInitOnly Then + Return True + End If + + If receiverOpt Is Nothing Then + Return False + End If + + ' ok: New C() With { .InitOnlyProperty = ... } + If isKnownTargetOfObjectMemberInintializer Then + Debug.Assert(receiverOpt.Kind = BoundKind.WithLValueExpressionPlaceholder) + Return True + End If + + ' ok: setting on `Me`/`MyBase`/`MyClass` from an instance constructor + Dim containingMember As Symbol = containingBinder.ContainingMember + If If(TryCast(containingMember, MethodSymbol)?.MethodKind <> MethodKind.Constructor, True) Then + Return False + End If + + Select Case receiverOpt.Kind + Case BoundKind.WithLValueExpressionPlaceholder + ' This can be a `Me` reference used as a target for a `With` statement + Dim currentBinder As Binder = containingBinder + + While currentBinder IsNot Nothing AndAlso currentBinder.ContainingMember Is containingMember + Dim withBlockBinder = TryCast(currentBinder, WithBlockBinder) + If withBlockBinder IsNot Nothing Then + Return withBlockBinder.Info?.ExpressionPlaceholder Is receiverOpt AndAlso + withBlockBinder.Info.OriginalExpression.Kind = BoundKind.MeReference + End If + + currentBinder = currentBinder.ContainingBinder + End While + + Return False + + Case BoundKind.MeReference, BoundKind.MyBaseReference, BoundKind.MyClassReference + Return True + Case Else + Return False + End Select End If Dim sourceProperty As SourcePropertySymbol = TryCast(Me, SourcePropertySymbol) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb index 1a8a3a498ced4..af3b8017003f6 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/ReducedExtensionMethodSymbol.vb @@ -476,6 +476,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return _curriedFromMethod.IsInitOnly + End Get + End Property + Public Overrides ReadOnly Property IsVararg As Boolean Get Return _curriedFromMethod.IsVararg diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingMethodSymbol.vb index 9af72ac286242..a865972b212bd 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Retargeting/RetargetingMethodSymbol.vb @@ -146,6 +146,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Retargeting End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return _underlyingMethod.IsInitOnly + End Get + End Property + Public Overrides ReadOnly Property ReturnsByRef As Boolean Get Return _underlyingMethod.ReturnsByRef diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyMethodSymbol.vb index 0169de25b58ad..e94bf3daeb880 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SignatureOnlyMethodSymbol.vb @@ -157,6 +157,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Friend Overrides ReadOnly Property ObsoleteAttributeData As ObsoleteAttributeData Get Return Nothing diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/CustomModifierUtils.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/CustomModifierUtils.vb index 73eca406d3207..1ab122322b3b9 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/CustomModifierUtils.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/CustomModifierUtils.vb @@ -125,6 +125,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return False End Function + + Friend Shared Function HasIsExternalInitModifier(modifiers As ImmutableArray(Of CustomModifier)) As Boolean + Return modifiers.Any(Function(modifier) Not modifier.IsOptional AndAlso + DirectCast(modifier, VisualBasicCustomModifier).ModifierSymbol.IsWellKnownTypeIsExternalInit()) + End Function End Class End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplementsHelper.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplementsHelper.vb index f0c7cb25cb9f6..f18e893a3759e 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplementsHelper.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplementsHelper.vb @@ -502,6 +502,12 @@ DoneWithErrorReporting: DirectCast(implementedMemberSyntax.SyntaxTree, VisualBasicSyntaxTree).Options.LanguageVersion, InternalSyntax.Feature.ImplementingReadonlyOrWriteonlyPropertyWithReadwrite) End If + + If implementedPropertySetMethod?.IsInitOnly <> implementingProperty.SetMethod?.IsInitOnly Then + Binder.ReportDiagnostic(diagBag, implementedMemberSyntax, ERRID.ERR_PropertyDoesntImplementInitOnly, + implementedProperty) + errorReported = True + End If End If If implementedSym IsNot Nothing AndAlso implementingSym.ContainsTupleNames() AndAlso diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaSymbol.vb index 39855f0b3fdc5..6527fe5cdbc06 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/LambdaSymbol.vb @@ -245,6 +245,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public NotOverridable Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Public Overrides ReadOnly Property Locations As ImmutableArray(Of Location) Get Return ImmutableArray.Create(_syntaxNode.GetLocation()) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb index a5008df86c99f..e7880ce053c40 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb @@ -895,6 +895,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ReportBadOverriding(ERRID.ERR_InvalidOverrideDueToReturn2, member, overriddenMember, diagnostics) ElseIf (comparisonResults And SymbolComparisonResults.PropertyAccessorMismatch) <> 0 Then ReportBadOverriding(ERRID.ERR_OverridingPropertyKind2, member, overriddenMember, diagnostics) + ElseIf (comparisonResults And SymbolComparisonResults.PropertyInitOnlyMismatch) <> 0 Then + ReportBadOverriding(ERRID.ERR_OverridingInitOnlyProperty, member, overriddenMember, diagnostics) ElseIf (comparisonResults And SymbolComparisonResults.ParamArrayMismatch) <> 0 Then ReportBadOverriding(ERRID.ERR_OverrideWithArrayVsParamArray2, member, overriddenMember, diagnostics) ElseIf (comparisonResults And SymbolComparisonResults.OptionalParameterTypeMismatch) <> 0 Then diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb index 980e25a12b195..ee7085f257ab9 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb @@ -3559,6 +3559,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols nextMember, SymbolComparisonResults.AllMismatches And Not (SymbolComparisonResults.CallingConventionMismatch Or SymbolComparisonResults.ConstraintMismatch)) + Debug.Assert((comparisonResults And SymbolComparisonResults.PropertyInitOnlyMismatch) = 0) + ' only report diagnostics if the signature is considered equal following VB rules. If (comparisonResults And Not SymbolComparisonResults.MismatchesForConflictingMethods) = 0 Then ReportOverloadsErrors(comparisonResults, member, nextMember, member.Locations(0), diagnostics) @@ -3738,6 +3740,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols SymbolComparisonResults.CustomModifierMismatch Or SymbolComparisonResults.NameMismatch)) + Debug.Assert((comparisonResults And SymbolComparisonResults.PropertyInitOnlyMismatch) = 0) + ' only report diagnostics if the signature is considered equal following VB rules. If (comparisonResults And significantDiff) = 0 Then ReportOverloadsErrors(comparisonResults, method, nextMethod, method.Locations(0), diagnostics) @@ -3820,6 +3824,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Sub Private Sub ReportOverloadsErrors(comparisonResults As SymbolComparisonResults, firstMember As Symbol, secondMember As Symbol, location As Location, diagnostics As DiagnosticBag) + Debug.Assert((comparisonResults And SymbolComparisonResults.PropertyInitOnlyMismatch) = 0) + If (Me.Locations.Length > 1 AndAlso Not Me.IsPartial) Then ' if there was an error with the enclosing class, suppress these diagnostics ElseIf comparisonResults = 0 Then diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb index d8d928756aa88..88eaad6971850 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb @@ -1293,6 +1293,12 @@ lReportErrorOnTwoTokens: End Get End Property + Public NotOverridable Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Friend NotOverridable Overrides Function TryGetMeParameter( ByRef meParameter As ParameterSymbol) As Boolean If IsShared Then meParameter = Nothing diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb index 58d403a213c1d..8b7590d653622 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb @@ -1195,6 +1195,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public NotOverridable Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Public Overrides ReadOnly Property IsVararg As Boolean Get Return ClonedFrom.IsVararg diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedMethodSymbol.vb index 2f121d0141169..f45db5b29db40 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SubstitutedMethodSymbol.vb @@ -255,6 +255,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public NotOverridable Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return OriginalDefinition.IsInitOnly + End Get + End Property + Public Overrides ReadOnly Property IsVararg As Boolean Get Return OriginalDefinition.IsVararg diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb index b648c2604dd9b..5933fbe0fa755 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb @@ -992,7 +992,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Function Friend Function DeriveUseSiteErrorInfoFromCustomModifiers( - customModifiers As ImmutableArray(Of CustomModifier) + customModifiers As ImmutableArray(Of CustomModifier), + Optional allowIsExternalInit As Boolean = False ) As DiagnosticInfo Dim modifiersErrorInfo As DiagnosticInfo = Nothing Dim highestPriorityUseSiteError As Integer = Me.HighestPriorityUseSiteError @@ -1001,12 +1002,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim errorInfo As DiagnosticInfo - If modifier.IsOptional Then - errorInfo = DeriveUseSiteErrorInfoFromType(DirectCast(modifier.Modifier, TypeSymbol)) - Else + If Not modifier.IsOptional AndAlso + (Not allowIsExternalInit OrElse Not DirectCast(modifier, VisualBasicCustomModifier).ModifierSymbol.IsWellKnownTypeIsExternalInit()) Then + errorInfo = If(GetSymbolSpecificUnsupportedMetadataUseSiteErrorInfo(), ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedType1, String.Empty)) + + If errorInfo.Code = highestPriorityUseSiteError Then + Return errorInfo + End If + + If modifiersErrorInfo Is Nothing Then + modifiersErrorInfo = errorInfo + End If End If + errorInfo = DeriveUseSiteErrorInfoFromType(DirectCast(modifier, VisualBasicCustomModifier).ModifierSymbol) + If errorInfo IsNot Nothing Then If errorInfo.Code = highestPriorityUseSiteError Then Return errorInfo diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedDelegateMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedDelegateMethodSymbol.vb index a13c77327a049..3d337f2c80c06 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedDelegateMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedDelegateMethodSymbol.vb @@ -265,6 +265,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + ''' ''' Gets a value indicating whether this instance is vararg. ''' diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedGlobalMethodBase.vb b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedGlobalMethodBase.vb index 7079c0c6d5ea5..89e684c9ecc38 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedGlobalMethodBase.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedGlobalMethodBase.vb @@ -337,6 +337,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public NotOverridable Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Friend Overrides ReadOnly Property GenerateDebugInfoImpl As Boolean Get Return False diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedMethodBase.vb b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedMethodBase.vb index 9db5551de579f..c5d3992d949cb 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedMethodBase.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedMethodBase.vb @@ -204,6 +204,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public NotOverridable Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Friend NotOverridable Overrides ReadOnly Property IsMethodKindBasedOnSyntax As Boolean Get Return False diff --git a/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbolExtensions.vb b/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbolExtensions.vb index 40ceec396fa7f..f3e1c56f94422 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbolExtensions.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbolExtensions.vb @@ -1321,6 +1321,46 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return New Cci.TypeReferenceWithAttributes(typeRef) End Function + + + Friend Function IsWellKnownTypeIsExternalInit(typeSymbol As TypeSymbol) As Boolean + Return typeSymbol.IsWellKnownCompilerServicesTopLevelType("IsExternalInit") + End Function + + + Private Function IsWellKnownCompilerServicesTopLevelType(typeSymbol As TypeSymbol, name As String) As Boolean + If Not String.Equals(typeSymbol.Name, name) Then + Return False + End If + + Return IsCompilerServicesTopLevelType(typeSymbol) + End Function + + + Friend Function IsCompilerServicesTopLevelType(typeSymbol As TypeSymbol) As Boolean + Return typeSymbol.ContainingType Is Nothing AndAlso IsContainedInNamespace(typeSymbol, "System", "Runtime", "CompilerServices") + End Function + + + Private Function IsContainedInNamespace(typeSymbol As TypeSymbol, outerNS As String, midNS As String, innerNS As String) As Boolean + Dim innerNamespace = typeSymbol.ContainingNamespace + If Not String.Equals(innerNamespace?.Name, innerNS) Then + Return False + End If + + Dim midNamespace = innerNamespace.ContainingNamespace + If Not String.Equals(midNamespace?.Name, midNS) Then + Return False + End If + + Dim outerNamespace = midNamespace.ContainingNamespace + If Not String.Equals(outerNamespace?.Name, outerNS) Then + Return False + End If + + Dim globalNamespace = outerNamespace.ContainingNamespace + Return globalNamespace IsNot Nothing AndAlso globalNamespace.IsGlobalNamespace + End Function End Module End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedMethodSymbol.vb index 81baefc47c20a..c463f0abff4b0 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Wrapped/WrappedMethodSymbol.vb @@ -219,6 +219,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return Me.UnderlyingMethod.IsInitOnly + End Get + End Property + Friend Overrides ReadOnly Property Syntax As SyntaxNode Get Return Me.UnderlyingMethod.Syntax diff --git a/src/Compilers/VisualBasic/Portable/VBResources.resx b/src/Compilers/VisualBasic/Portable/VBResources.resx index 6fbca2938acb9..4cf524abc5c11 100644 --- a/src/Compilers/VisualBasic/Portable/VBResources.resx +++ b/src/Compilers/VisualBasic/Portable/VBResources.resx @@ -5611,4 +5611,16 @@ The loaded assembly references .NET Framework, which is not supported. + + assigning to or passing 'ByRef' properties with init-only setters + + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + + '{0}' cannot override init-only '{1}'. + + + Init-only '{0}' cannot be implemented. + diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf index 0c2f9b9a5efa0..f91370ca27982 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Chyba syntaxe příkazového řádku: {0} není platná hodnota možnosti {1}. Hodnota musí mít tvar {2}. @@ -22,6 +27,16 @@ Ve stejném adresáři nemůže být více konfiguračních souborů analyzátoru ({0}). + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. Typ {0} nemůže být vložený, protože má reabstrakci člena ze základního rozhraní. Zvažte nastavení vlastnosti Vložit typy spolupráce na hodnotu false. @@ -42,6 +57,11 @@ komentáře po pokračování řádku + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions parametry neomezeného typu v binárních podmíněných výrazech diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf index 24d84acaabc0a..14a84ab8f8ada 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Fehler in der Befehlszeilensyntax: "{0}" ist kein gültiger Wert für die Option "{1}". Der Wert muss im Format "{2}" vorliegen. @@ -22,6 +27,16 @@ Dasselbe Verzeichnis ({0}) darf nicht mehrere Konfigurationsdateien des Analysetools enthalten. + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. Der Typ "{0}" kann nicht eingebettet werden, weil er eine Neuabstraktion eines Members aus der Basisschnittstelle aufweist. Legen Sie die Eigenschaft "Interoptypen einbetten" ggf. auf FALSE fest. @@ -42,6 +57,11 @@ Kommentare nach Zeilenfortsetzung + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions Nicht eingeschränkte Typparameter in binären bedingten Ausdrücken diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf index 65cccf48c5e75..eb07c728c37fd 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Error de sintaxis de la línea de comandos: "{0}" no es un valor válido para la opción "{1}". El valor debe tener el formato "{2}". @@ -22,6 +27,16 @@ No es posible que un mismo directorio ("{0}") contenga varios archivos de configuración del analizador. + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. El tipo "{0}" no se puede insertar porque tiene una reabstracción de un miembro de la interfaz base. Puede establecer la propiedad "Incrustar tipos de interoperabilidad" en false. @@ -42,6 +57,11 @@ comentarios después de la continuación de línea + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions parámetros de tipo sin restricciones en expresiones condicionales binarias diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf index 537566ac37b2e..0449d45e57243 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Erreur de syntaxe de ligne de commande : '{0}' est une valeur non valide pour l'option '{1}'. La valeur doit se présenter sous la forme '{2}'. @@ -22,6 +27,16 @@ Plusieurs fichiers config d'analyseur ne peuvent pas figurer dans le même répertoire ('{0}'). + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. Impossible d'incorporer le type '{0}', car il a une nouvelle abstraction d'un membre de l'interface de base. Affectez la valeur false à la propriété 'Incorporer les types interop'. @@ -42,6 +57,11 @@ commentaires après la continuation de la ligne + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions paramètres de type sans contrainte dans les expressions conditionnelles binaires diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf index bb17a775b497c..4a16923f0eb75 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Errore di sintassi della riga di comando: '{0}' non è un valore valido per l'opzione '{1}'. Il valore deve essere espresso nel formato '{2}'. @@ -22,6 +27,16 @@ La stessa directory ('{0}') non può contenere più file di configurazione dell'analizzatore. + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. Non è possibile incorporare il tipo '{0}' perché contiene una nuova astrazione di un membro dell'interfaccia di base. Provare a impostare la proprietà 'Incorpora tipi di interoperabilità' su false. @@ -42,6 +57,11 @@ commenti dopo la continuazione di riga + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions parametri di tipo non senza vincoli in espressioni condizionali binarie diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf index 05c4385a09fe0..8ae5837b99957 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. コマンドライン構文エラー: '{0}' は、'{1}' オプションの有効な値ではありません。値は '{2}' の形式にする必要があります。 @@ -22,6 +27,16 @@ 複数のアナライザー構成ファイルを同じディレクトリに入れることはできません ('{0}')。 + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. 型 '{0}' には基底インターフェイスからのメンバーの再抽象化があるため、この型を埋め込むことはできません。'相互運用型の埋め込み' プロパティを false に設定することをご検討ください。 @@ -42,6 +57,11 @@ 行連結後のコメント + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions バイナリ条件式での非制約型パラメーター diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf index cef47d7a1328c..9809ee4c791e8 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. 명령줄 구문 오류: '{0}'은(는) '{1}' 옵션에 유효한 값이 아닙니다. 값은 '{2}' 형식이어야 합니다. @@ -22,6 +27,16 @@ 분석기 구성 파일 여러 개가 동일한 디렉터리('{0}')에 있을 수 없습니다. + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. '{0}' 형식에는 기본 인터페이스 멤버의 재추상화가 있으므로 해당 형식을 포함할 수 없습니다. 'Interop 형식 포함' 속성을 false로 설정해 보세요. @@ -42,6 +57,11 @@ 줄 연속 뒤 주석 + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions 이진 조건식의 비제한 형식 매개 변수 diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf index 097427e155e25..613cdcae4cefa 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Błąd składni wiersza polecenia: „{0}” nie jest prawidłową wartością dla opcji „{1}”. Wartość musi mieć postać „{2}”. @@ -22,6 +27,16 @@ Wiele plików konfiguracji analizatora nie może znajdować się w tym samym katalogu („{0}”). + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. Nie można osadzić typu „{0}”, ponieważ zawiera ponowną abstrakcję składowej z interfejsu podstawowego. Rozważ ustawienie właściwości „Osadź typy międzyoperacyjne” na wartość false. @@ -42,6 +57,11 @@ komentarze po kontynuacji wiersza + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions parametry typu bez ograniczeń w binarnych wyrażeniach warunkowych diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf index ef4b3ce5f8cd0..734f8170a7faa 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Erro de sintaxe de linha de comando: '{0}' não é um valor válido para a opção '{1}'. O valor precisa estar no formato '{2}'. @@ -22,6 +27,16 @@ Não é possível que haja vários arquivos de configuração do analisador no mesmo diretório ('{0}'). + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. O tipo '{0}' não pode ser inserido porque tem uma nova abstração de um membro da interface base. Considere a configuração da propriedade 'Embed Interop Types' como false. @@ -42,6 +57,11 @@ comentários após a continuação da linha + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions parâmetros de tipo irrestritos em expressões condicionais binárias diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf index d8868f290a36e..526076c63bd7b 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Ошибка в синтаксисе командной строки: "{0}" не является допустимым значением для параметра "{1}". Значение должно иметь форму "{2}". @@ -22,6 +27,16 @@ В одном каталоге ("{0}") не может находиться несколько файлов конфигурации анализатора. + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. Невозможно внедрить тип "{0}", так как он переопределяет абстракцию элемента базового интерфейса. Попробуйте задать для свойства "Внедрить типы взаимодействия" значение false (ложь). @@ -42,6 +57,11 @@ комментарии после продолжения строки + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions параметры неограниченного типа в двоичных условных выражениях diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf index 6e338188158df..be296cc376348 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. Komut satırı söz dizimi hatası: '{0}', '{1}' seçeneği için geçerli bir değer değil. Değer '{2}' biçiminde olmalıdır. @@ -22,6 +27,16 @@ Birden çok çözümleyici yapılandırma dosyası aynı dizinde ('{0}') olamaz. + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. '{0}' türünün temel arabirimden yeniden soyutlanmış bir üyesi olduğundan bu tür eklenemiyor. 'Embed Interop Types' özelliğini false olarak ayarlamayı deneyin. @@ -42,6 +57,11 @@ satır devamı sonrası açıklamalar + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions ikili koşullu ifadelerde kısıtlanmamış tür parametreleri diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf index a2d19a6339d01..142d41c73afcb 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. 命令行语法错误:“{0}”不是“{1}”选项的有效值。值的格式必须为 "{2}"。 @@ -22,6 +27,16 @@ 多个分析器配置文件不能位于同一目录({0})中。 + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. 无法嵌入类型“{0}”,因为它有基本接口成员的重新抽象。请考虑将“嵌入互操作类型”属性设置为 false。 @@ -42,6 +57,11 @@ 行继续符之后的注释 + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions 二进制条件表达式中的无约束类型参数 diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf index be4692c2afe57..c1275646da571 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf @@ -2,6 +2,11 @@ + + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Init-only property '{0}' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + + Command-line syntax error: '{0}' is not a valid value for the '{1}' option. The value must be of the form '{2}'. 命令列語法錯誤: '{0}' 對 '{1}' 選項而言不是有效的值。此值的格式必須是 '{2}'。 @@ -22,6 +27,16 @@ 多個分析器組態檔無法處於相同目錄 ('{0}') 中。 + + '{0}' cannot override init-only '{1}'. + '{0}' cannot override init-only '{1}'. + + + + Init-only '{0}' cannot be implemented. + Init-only '{0}' cannot be implemented. + + Type '{0}' cannot be embedded because it has a re-abstraction of a member from base interface. Consider setting the 'Embed Interop Types' property to false. 因為類型 '{0}' 有重新抽象成員 (來自基底介面),所以無法內嵌。請考慮將 [內嵌 Interop 類型] 屬性設為 false。 @@ -42,6 +57,11 @@ 行接續符號後註解 + + assigning to or passing 'ByRef' properties with init-only setters + assigning to or passing 'ByRef' properties with init-only setters + + unconstrained type parameters in binary conditional expressions 二進位條件運算式中的非限制式型別參數 diff --git a/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb b/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb index 852acbf5383be..469214224b209 100644 --- a/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb +++ b/src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb @@ -1500,6 +1500,10 @@ End Module").Path parsedArgs.Errors.Verify() Assert.Equal(LanguageVersion.VisualBasic16, parsedArgs.ParseOptions.LanguageVersion) + parsedArgs = DefaultParse({"/langVERSION:16.9", "a.vb"}, _baseDirectory) + parsedArgs.Errors.Verify() + Assert.Equal(LanguageVersion.VisualBasic16_9, parsedArgs.ParseOptions.LanguageVersion) + ' The canary check is a reminder that this test needs to be updated when a language version is added LanguageVersionAdded_Canary() @@ -2027,7 +2031,7 @@ End Module").Path ' - update project-system to recognize the new value and pass it through ' - 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", "latest"}, + AssertEx.SetEqual({"default", "9", "10", "11", "12", "14", "15", "15.3", "15.5", "16", "16.9", "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 @@ -2048,7 +2052,8 @@ End Module").Path "15.0", "15.3", "15.5", - "16" + "16", + "16.9" } AssertEx.SetEqual(versions, errorCodes) @@ -2068,8 +2073,9 @@ End Module").Path Assert.Equal(LanguageVersion.VisualBasic15_3, LanguageVersion.VisualBasic15_3.MapSpecifiedToEffectiveVersion()) 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, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()) + Assert.Equal(LanguageVersion.VisualBasic16_9, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()) ' The canary check is a reminder that this test needs to be updated when a language version is added LanguageVersionAdded_Canary() @@ -2092,6 +2098,7 @@ End Module").Path InlineData("15.5", True, LanguageVersion.VisualBasic15_5), InlineData("16", True, LanguageVersion.VisualBasic16), InlineData("16.0", True, LanguageVersion.VisualBasic16), + InlineData("16.9", True, LanguageVersion.VisualBasic16_9), InlineData("DEFAULT", True, LanguageVersion.Default), InlineData("default", True, LanguageVersion.Default), InlineData("LATEST", True, LanguageVersion.Latest), diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb new file mode 100644 index 0000000000000..f2dffe425bdba --- /dev/null +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb @@ -0,0 +1,4144 @@ +' 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.Test.Utilities +Imports Microsoft.CodeAnalysis.VisualBasic.Symbols +Imports Microsoft.CodeAnalysis.VisualBasic.Syntax +Imports Roslyn.Test.Utilities + +Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics + + Public Class InitOnlyMemberTests + Inherits BasicTestBase + + Protected Const IsExternalInitTypeDefinition As String = " +namespace System.Runtime.CompilerServices +{ + public static class IsExternalInit + { + } +} +" + + + Public Sub EvaluationInitOnlySetter_01() + + Dim csSource = +" +public class C : System.Attribute +{ + public int Property0 { init { System.Console.Write(value + "" 0 ""); } } + public int Property1 { init { System.Console.Write(value + "" 1 ""); } } + public int Property2 { init { System.Console.Write(value + "" 2 ""); } } + public int Property3 { init { System.Console.Write(value + "" 3 ""); } } + public int Property4 { init { System.Console.Write(value + "" 4 ""); } } + public int Property5 { init { System.Console.Write(value + "" 5 ""); } } + public int Property6 { init { System.Console.Write(value + "" 6 ""); } } + public int Property7 { init { System.Console.Write(value + "" 7 ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + +Class B + Inherits C + + Public Sub New() + Property0 = 41 + Me.Property3 = 44 + MyBase.Property4 = 45 + MyClass.Property5 = 46 + + With Me + .Property6 = 47 + End With + + Me.GetType().GetCustomAttributes(False) + End Sub +End Class +]]> + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="41 0 44 3 45 4 46 5 47 6 48 7 42 1 43 2 ").VerifyDiagnostics() + + Assert.True(DirectCast(comp1.GetMember(Of PropertySymbol)("C.Property0").SetMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( + + ~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Property0 = 41 + ~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Me.Property3 = 44 + ~~~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + MyBase.Property4 = 45 + ~~~~~~~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + MyClass.Property5 = 46 + ~~~~~~~~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + .Property6 = 47 + ~~~~~~~~~~~~~~~ +]]>) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Property1' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property1 = 42 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property2' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property2 = 43 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property3 = 44 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property4 = 45 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property6' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property6 = 47 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property0' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property0 = 41 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Property5 = 46 + ~~~~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + + Dim source5 = + + + + + Dim comp5 = CreateCompilation(source5, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected5 = + +BC37311: Init-only property 'Property0' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Property0 = 41 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me.Property3 = 44 + ~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyBase.Property4 = 45 + ~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyClass.Property5 = 46 + ~~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property6' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property6 = 47 + ~~~~~~~~~~~~~~~ + + comp5.AssertTheseDiagnostics(expected5) + + Dim comp6 = CreateCompilation(source5, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp6.AssertTheseDiagnostics(expected5) + End Sub + + + Public Sub EvaluationInitOnlySetter_02() + + Dim csSource = +" +public class C : System.Attribute +{ + public int Property0 { init; get; } + public int Property1 { init; get; } + public int Property2 { init; get; } + public int Property3 { init; get; } + public int Property4 { init; get; } + public int Property5 { init; get; } + public int Property6 { init; get; } + public int Property7 { init; get; } + public int Property8 { init; get; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + +Class B + Inherits C + + Public Sub New() + Property0 = 41 + Me.Property3 = 44 + MyBase.Property4 = 45 + MyClass.Property5 = 46 + + With Me + .Property6 = 47 + End With + + Init(Property2, 43) + Init((Property2), 430) + + With Me + Init(.Property8, 49) + Init((.Property8), 494) + End With + + Dim b = Me + Init(b.Property8, 490) + Init((b.Property8), 491) + + With b + Init(.Property8, 499) + Init((.Property8), 450) + End With + + Test() + + Dim d = Sub() + Init(Property8, 600) + Init((Property8), 601) + End Sub + + d() + End Sub + + Public Sub Test() + With Me + Init(.Property8, 495) + Init((.Property8), 496) + End With + + Init(Property8, 497) + Init((Property8), 498) + + Dim b = Me + + With b + Init(.Property8, 451) + Init((.Property8), 452) + End With + End Sub + + Public Shared Sub Init(ByRef p as Integer, val As Integer) + p = val + End Sub +End Class +]]> + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16_9, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="41 42 43 44 45 46 47 48 49").VerifyDiagnostics() + + Assert.True(DirectCast(comp1.GetMember(Of PropertySymbol)("C.Property0").SetMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( + + ~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Property0 = 41 + ~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Me.Property3 = 44 + ~~~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + MyBase.Property4 = 45 + ~~~~~~~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + MyClass.Property5 = 46 + ~~~~~~~~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + .Property6 = 47 + ~~~~~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(Property2, 43) + ~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(.Property8, 49) + ~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(b.Property8, 490) + ~~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(.Property8, 499) + ~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(Property8, 600) + ~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(.Property8, 495) + ~~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(Property8, 497) + ~~~~~~~~~ +BC36716: Visual Basic 16 does not support assigning to or passing 'ByRef' properties with init-only setters. + Init(.Property8, 451) + ~~~~~~~~~~ +]]>) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Property1' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property1 = 42 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property2' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property2 = 43 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property3 = 44 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property4 = 45 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property6' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property6 = 47 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property0' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property0 = 41 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Property5 = 46 + ~~~~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + + Dim source5 = + + + + + Dim comp5 = CreateCompilation(source5, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected5 = + +BC37311: Init-only property 'Property0' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Property0 = 41 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me.Property3 = 44 + ~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyBase.Property4 = 45 + ~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyClass.Property5 = 46 + ~~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property6' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property6 = 47 + ~~~~~~~~~~~~~~~ + + comp5.AssertTheseDiagnostics(expected5) + + Dim comp6 = CreateCompilation(source5, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp6.AssertTheseDiagnostics(expected5) + End Sub + + + Public Sub EvaluationInitOnlySetter_03() + + Dim csSource = +" +public class C +{ + public int this[int x] { init { System.Console.Write(value + "" ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="40 41 42 43 44 45 ").VerifyDiagnostics() + + Assert.True(DirectCast(comp1.GetMember(Of PropertySymbol)("C.Item").SetMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( +) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x(0) = 40 + ~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Item(0) = 41 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) = 42 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) = 43 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) = 44 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) = 45 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x(0) = 46 + ~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Item(0) = 47 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Item(0) = 48 + ~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me(0) = 49 + ~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + + Dim source5 = + + + + + Dim comp5 = CreateCompilation(source5, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected5 = + +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Item(0) = 40 + ~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me(0) = 41 + ~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me.Item(0) = 42 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyBase.Item(0) = 43 + ~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyClass.Item(0) = 44 + ~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) = 45 + ~~~~~~~~~~~~~ + + comp5.AssertTheseDiagnostics(expected5) + + Dim comp6 = CreateCompilation(source5, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp6.AssertTheseDiagnostics(expected5) + End Sub + + + Public Sub EvaluationInitOnlySetter_04() + + Dim csSource = +" +public class C : System.Attribute +{ + private int[] _item = new int[36]; + public int this[int x] { init => _item[x] = value; get => _item[x]; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16_9, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="40 41 42 43 44 45 46 47 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0").VerifyDiagnostics() + + Assert.True(DirectCast(comp1.GetMember(Of PropertySymbol)("C.Item").SetMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( +) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x(0) = 40 + ~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Item(1) = 41 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(2) = 42 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(3) = 43 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(4) = 44 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(5) = 45 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x(6) = 46 + ~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Item(7) = 47 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Item(8) = 48 + ~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me(9) = 49 + ~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + + Dim source5 = + + + + + Dim comp5 = CreateCompilation(source5, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected5 = + +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Item(0) = 40 + ~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me(1) = 41 + ~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me.Item(2) = 42 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyBase.Item(3) = 43 + ~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyClass.Item(4) = 44 + ~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(5) = 45 + ~~~~~~~~~~~~~ + + comp5.AssertTheseDiagnostics(expected5) + + Dim comp6 = CreateCompilation(source5, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp6.AssertTheseDiagnostics(expected5) + End Sub + + + Public Sub EvaluationInitOnlySetter_05() + + Dim csSource = +" +public class C +{ + public int Property0 { get => 0; init { System.Console.Write(value + "" 0 ""); } } + public int Property1 { get => 0; init { System.Console.Write(value + "" 1 ""); } } + public int Property2 { get => 0; init { System.Console.Write(value + "" 2 ""); } } + public int Property3 { get => 0; init { System.Console.Write(value + "" 3 ""); } } + public int Property4 { get => 0; init { System.Console.Write(value + "" 4 ""); } } + public int Property5 { get => 0; init { System.Console.Write(value + "" 5 ""); } } + public int Property6 { get => 0; init { System.Console.Write(value + "" 6 ""); } } + public int Property7 { get => 0; init { System.Console.Write(value + "" 7 ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="41 0 44 3 45 4 46 5 47 6 ").VerifyDiagnostics() + + Assert.True(DirectCast(comp1.GetMember(Of PropertySymbol)("C.Property0").SetMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( +) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Property1' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property1 += 42 + ~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property2' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property2 += 43 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property3 += 44 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property4 += 45 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property6' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property6 += 47 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property0' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property0 += 41 + ~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Property5 += 46 + ~~~~~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + + Dim source5 = + + + + + Dim comp5 = CreateCompilation(source5, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected5 = + +BC37311: Init-only property 'Property0' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Property0 += 41 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me.Property3 += 44 + ~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyBase.Property4 += 45 + ~~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyClass.Property5 += 46 + ~~~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property6' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property6 += 47 + ~~~~~~~~~~~~~~~~ + + comp5.AssertTheseDiagnostics(expected5) + + Dim comp6 = CreateCompilation(source5, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp6.AssertTheseDiagnostics(expected5) + End Sub + + + Public Sub EvaluationInitOnlySetter_06() + + Dim csSource = +" +public class C +{ + public int this[int x] { get => 0; init { System.Console.Write(value + "" ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="40 41 42 43 44 45 ").VerifyDiagnostics() + + Assert.True(DirectCast(comp1.GetMember(Of PropertySymbol)("C.Item").SetMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( +) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x(0) += 40 + ~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Item(0) += 41 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) += 42 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) += 43 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) += 44 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) += 45 + ~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x(0) += 46 + ~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Item(0) += 47 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Item(0) += 48 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me(0) += 49 + ~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + + Dim source5 = + + + + + Dim comp5 = CreateCompilation(source5, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected5 = + +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Item(0) += 40 + ~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me(0) += 41 + ~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + Me.Item(0) += 42 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyBase.Item(0) += 43 + ~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + MyClass.Item(0) += 44 + ~~~~~~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Item' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Item(0) += 45 + ~~~~~~~~~~~~~~ + + comp5.AssertTheseDiagnostics(expected5) + + Dim comp6 = CreateCompilation(source5, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp6.AssertTheseDiagnostics(expected5) + End Sub + + + Public Sub EvaluationInitOnlySetter_07() + + Dim csSource = +" +public interface I +{ + public int Property1 { init; } + public int Property2 { init; } + public int Property3 { init; } + public int Property4 { init; } + public int Property5 { init; } +} + +public class C : I +{ + public int Property1 { init { System.Console.Write(value + "" 1 ""); } } + public int Property2 { init { System.Console.Write(value + "" 2 ""); } } + public int Property3 { init { System.Console.Write(value + "" 3 ""); } } + public int Property4 { init { System.Console.Write(value + "" 4 ""); } } + public int Property5 { init { System.Console.Write(value + "" 5 ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="42 1 43 2 ").VerifyDiagnostics() + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( +) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Property1' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property1 = 42 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property2' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property2 = 43 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property3' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property3 = 44 + ~~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property4' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property4 = 45 + ~~~~~~~~~~~~~~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + x.Property5 = 46 + ~~~~~~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + End Sub + + + Public Sub EvaluationInitOnlySetter_08() + + Dim csSource = +" +using System; +using System.Runtime.InteropServices; + +[assembly: ImportedFromTypeLib(""GeneralPIA.dll"")] +[assembly: Guid(""f9c2d51d-4f44-45f0-9eda-c9d599b58257"")] + +[ComImport()] +[Guid(""f9c2d51d-4f44-45f0-9eda-c9d599b58277"")] +[CoClass(typeof(C))] +public interface I +{ + public int Property1 { init; } + public int Property2 { init; } +} + +[Guid(""f9c2d51d-4f44-45f0-9eda-c9d599b58278"")] +public class C : I +{ + int I.Property1 { init { System.Console.Write(value + "" 1 ""); } } + int I.Property2 { init { System.Console.Write(value + "" 2 ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:="42 1 ").VerifyDiagnostics() + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics( +) + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC37311: Init-only property 'Property2' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property2 = 43 + ~~~~~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + End Sub + + + Public Sub EvaluationInitOnlySetter_09() + + Dim csSource = +" +public class C +{ + public int Property1 { init { System.Console.Write(value + "" 1 ""); } } + public int Property2 { init { System.Console.Write(value + "" 2 ""); } } + public int Property3 { init { System.Console.Write(value + "" 3 ""); } } + public int Property4 { init { System.Console.Write(value + "" 4 ""); } } + public int Property5 { init { System.Console.Write(value + "" 5 ""); } } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source3 = + + + + + Dim comp3 = CreateCompilation(source3, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected3 = + +BC30369: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. + Property1 = 41 + ~~~~~~~~~ +BC30043: 'Me' is valid only within an instance method. + Me.Property2 = 42 + ~~ +BC30043: 'MyBase' is valid only within an instance method. + MyBase.Property3 = 43 + ~~~~~~ +BC30043: 'MyClass' is valid only within an instance method. + MyClass.Property4 = 44 + ~~~~~~~ +BC30043: 'Me' is valid only within an instance method. + With Me + ~~ +BC37311: Init-only property 'Property5' can only be assigned by an object member initializer, or on 'Me', 'MyClass` or 'MyBase' in an instance constructor. + .Property5 = 45 + ~~~~~~~~~~~~~~~ + + comp3.AssertTheseDiagnostics(expected3) + + Dim comp4 = CreateCompilation(source3, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp4.AssertTheseDiagnostics(expected3) + End Sub + + + Public Sub Overriding_01() + + Dim csSource = +" +public class C +{ + public virtual int P0 { init { } } + public virtual int P1 { init; get; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected1 = + +BC37312: 'Public Overrides WriteOnly Property P0 As Integer' cannot override init-only 'Public Overridable Overloads WriteOnly Property P0 As Integer'. + Public Overrides WriteOnly Property P0 As Integer + ~~ +BC37312: 'Public Overrides Property P1 As Integer' cannot override init-only 'Public Overridable Overloads Property P1 As Integer'. + Public Overrides Property P1 As Integer + ~~ +BC30362: 'Public Overrides Property P0 As Integer' cannot override 'Public Overridable Overloads WriteOnly Property P0 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides Property P0 As Integer + ~~ +BC30362: 'Public Overrides ReadOnly Property P1 As Integer' cannot override 'Public Overridable Overloads Property P1 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides ReadOnly Property P1 As Integer + ~~ +BC30362: 'Public Overrides ReadOnly Property P0 As Integer' cannot override 'Public Overridable Overloads WriteOnly Property P0 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides ReadOnly Property P0 As Integer + ~~ +BC30362: 'Public Overrides WriteOnly Property P1 As Integer' cannot override 'Public Overridable Overloads Property P1 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides WriteOnly Property P1 As Integer + ~~ + + comp1.AssertTheseDiagnostics(expected1) + + Dim p0Set = comp1.GetMember(Of PropertySymbol)("B1.P0").SetMethod + Assert.False(p0Set.IsInitOnly) + Assert.True(p0Set.OverriddenMethod.IsInitOnly) + Dim p1Set = comp1.GetMember(Of PropertySymbol)("B1.P1").SetMethod + Assert.False(p1Set.IsInitOnly) + Assert.True(p1Set.OverriddenMethod.IsInitOnly) + Assert.False(comp1.GetMember(Of PropertySymbol)("B2.P0").SetMethod.IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics(expected1) + End Sub + + + Public Sub Overriding_02() + + Dim csSource = +" +public class C +{ + public virtual T this[int x] { init { } } + public virtual T this[short x] { init {} get => throw null; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected1 = + +BC37312: 'Public Overrides WriteOnly Property Item(x As Integer) As Integer' cannot override init-only 'Public Overridable Overloads WriteOnly Default Property Item(x As Integer) As Integer'. + Public Overrides WriteOnly Property Item(x as Integer) As Integer + ~~~~ +BC37312: 'Public Overrides Property Item(x As Short) As Integer' cannot override init-only 'Public Overridable Overloads Default Property Item(x As Short) As Integer'. + Public Overrides Property Item(x as Short) As Integer + ~~~~ +BC30362: 'Public Overrides Property Item(x As Integer) As Integer' cannot override 'Public Overridable Overloads WriteOnly Default Property Item(x As Integer) As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides Property Item(x as Integer) As Integer + ~~~~ +BC30362: 'Public Overrides ReadOnly Property Item(x As Short) As Integer' cannot override 'Public Overridable Overloads Default Property Item(x As Short) As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides ReadOnly Property Item(x as Short) As Integer + ~~~~ +BC30362: 'Public Overrides ReadOnly Property Item(x As Integer) As Integer' cannot override 'Public Overridable Overloads WriteOnly Default Property Item(x As Integer) As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides ReadOnly Property Item(x as Integer) As Integer + ~~~~ +BC30362: 'Public Overrides WriteOnly Property Item(x As Short) As Integer' cannot override 'Public Overridable Overloads Default Property Item(x As Short) As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides WriteOnly Property Item(x as Short) As Integer + ~~~~ + + comp1.AssertTheseDiagnostics(expected1) + + Dim p0Set = comp1.GetTypeByMetadataName("B1").GetMembers("Item").OfType(Of PropertySymbol).First().SetMethod + Assert.False(p0Set.IsInitOnly) + Assert.True(p0Set.OverriddenMethod.IsInitOnly) + Assert.True(DirectCast(p0Set.OverriddenMethod, IMethodSymbol).IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics(expected1) + End Sub + + + Public Sub Overriding_03() + + Dim csSource = +" +public class A +{ + public virtual int P1 { init; get; } + public virtual int P2 { init; get; } +} + +public class B : A +{ + public override int P1 { get => throw null; } + public override int P2 { init {} } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected1 = + +BC30362: 'Public Overrides WriteOnly Property P1 As Integer' cannot override 'Public Overrides ReadOnly Property P1 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides WriteOnly Property P1 As Integer + ~~ +BC37312: 'Public Overrides WriteOnly Property P2 As Integer' cannot override init-only 'Public Overrides WriteOnly Property P2 As Integer'. + Public Overrides WriteOnly Property P2 As Integer + ~~ +BC30362: 'Public Overrides Property P1 As Integer' cannot override 'Public Overrides ReadOnly Property P1 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides Property P1 As Integer + ~~ +BC30362: 'Public Overrides Property P2 As Integer' cannot override 'Public Overrides WriteOnly Property P2 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides Property P2 As Integer + ~~ +BC30362: 'Public Overrides ReadOnly Property P2 As Integer' cannot override 'Public Overrides WriteOnly Property P2 As Integer' because they differ by 'ReadOnly' or 'WriteOnly'. + Public Overrides ReadOnly Property P2 As Integer + ~~ + + comp1.AssertTheseDiagnostics(expected1) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics(expected1) + End Sub + + + Public Sub Overriding_04() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + CompileAndVerify(compilation).VerifyDiagnostics() + + Dim p = compilation.GetMember(Of PropertySymbol)("Test.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.False(pSet.OverriddenMethod.IsInitOnly) + Assert.Empty(pSet.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(p.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(p.OverriddenProperty.TypeCustomModifiers) + End Sub + + + Public Sub Overriding_05() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + CompileAndVerify(compilation).VerifyDiagnostics() + + Dim p = compilation.GetMember(Of PropertySymbol)("Test.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.False(pSet.OverriddenMethod.IsInitOnly) + Assert.Empty(pSet.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(p.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(p.OverriddenProperty.TypeCustomModifiers) + End Sub + + + Public Sub Overriding_06() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30935: Member 'Public Overridable Overloads Property P As Integer' that matches this signature cannot be overridden because the class 'CL1' contains multiple members with this same name and signature: + 'Public Overridable Overloads Property P As Integer' + 'Public Overridable Overloads Property P As Integer' + Overrides Property P As Integer + ~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("Test.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.False(pSet.OverriddenMethod.IsInitOnly) + Assert.Empty(pSet.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(p.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + End Sub + + + Public Sub Overriding_07() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30935: Member 'Public Overridable Overloads Property P As Integer' that matches this signature cannot be overridden because the class 'CL1' contains multiple members with this same name and signature: + 'Public Overridable Overloads Property P As Integer' + 'Public Overridable Overloads Property P As Integer' + Overrides Property P As Integer + ~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("Test.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.True(pSet.OverriddenMethod.IsInitOnly) + Assert.NotEmpty(pSet.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.NotEmpty(p.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + End Sub + + + Public Sub Overriding_08() + Dim ilSource = .Value + + Dim vbSource = + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + Dim cl2p1 = compilation.GetMember(Of PropertySymbol)("CL2.P1") + Assert.NotEmpty(cl2p1.SetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.NotEmpty(cl2p1.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.NotEmpty(cl2p1.OverriddenProperty.TypeCustomModifiers) + + Dim cl2p2 = compilation.GetMember(Of PropertySymbol)("CL2.P2") + Assert.NotEmpty(cl2p2.SetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.NotEmpty(cl2p2.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.NotEmpty(cl2p2.OverriddenProperty.TypeCustomModifiers) + + Dim cl3p1 = compilation.GetMember(Of PropertySymbol)("CL3.P1") + Assert.Empty(cl3p1.SetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(cl3p1.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(cl3p1.OverriddenProperty.TypeCustomModifiers) + + Dim cl3p2 = compilation.GetMember(Of PropertySymbol)("CL3.P2") + Assert.Empty(cl3p2.SetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(cl3p2.GetMethod.OverriddenMethod.ReturnTypeCustomModifiers) + Assert.Empty(cl3p2.OverriddenProperty.TypeCustomModifiers) + End Sub + + + Public Sub Implementing_01() + + Dim csSource = +" +public interface I +{ + int P0 { init; } + int P1 { init; get; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected1 = + +BC37313: Init-only 'WriteOnly Property P0 As Integer' cannot be implemented. + Public WriteOnly Property P0 As Integer Implements I.P0 + ~~~~ +BC37313: Init-only 'Property P1 As Integer' cannot be implemented. + Public Property P1 As Integer Implements I.P1 + ~~~~ +BC37313: Init-only 'WriteOnly Property P0 As Integer' cannot be implemented. + Public Property P0 As Integer Implements I.P0 + ~~~~ +BC31444: 'Property P1 As Integer' cannot be implemented by a ReadOnly property. + Public ReadOnly Property P1 As Integer Implements I.P1 + ~~~~ +BC31444: 'WriteOnly Property P0 As Integer' cannot be implemented by a ReadOnly property. + Public ReadOnly Property P0 As Integer Implements I.P0 + ~~~~ +BC31444: 'Property P1 As Integer' cannot be implemented by a WriteOnly property. + Public WriteOnly Property P1 As Integer Implements I.P1 + ~~~~ +BC37313: Init-only 'Property P1 As Integer' cannot be implemented. + Public WriteOnly Property P1 As Integer Implements I.P1 + ~~~~ + + comp1.AssertTheseDiagnostics(expected1) + + Dim p0Set = comp1.GetMember(Of PropertySymbol)("B1.P0").SetMethod + Assert.False(p0Set.IsInitOnly) + Dim p1Set = comp1.GetMember(Of PropertySymbol)("B1.P1").SetMethod + Assert.False(p1Set.IsInitOnly) + Assert.False(comp1.GetMember(Of PropertySymbol)("B2.P0").SetMethod.IsInitOnly) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics(expected1) + End Sub + + + Public Sub Implementing_02() + + Dim csSource = +" +public interface I +{ + int this[int x] { init; } + int this[short x] { init; get; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected1 = + +BC37313: Init-only 'WriteOnly Default Property Item(x As Integer) As Integer' cannot be implemented. + Public WriteOnly Property Item(x As Integer) As Integer Implements I.Item + ~~~~~~ +BC37313: Init-only 'Default Property Item(x As Short) As Integer' cannot be implemented. + Public Property Item(x As Short) As Integer Implements I.Item + ~~~~~~ +BC37313: Init-only 'WriteOnly Default Property Item(x As Integer) As Integer' cannot be implemented. + Public Property Item(x As Integer) As Integer Implements I.Item + ~~~~~~ +BC31444: 'Default Property Item(x As Short) As Integer' cannot be implemented by a ReadOnly property. + Public ReadOnly Property Item(x As Short) As Integer Implements I.Item + ~~~~~~ +BC31444: 'WriteOnly Default Property Item(x As Integer) As Integer' cannot be implemented by a ReadOnly property. + Public ReadOnly Property Item(x As Integer) As Integer Implements I.Item + ~~~~~~ +BC31444: 'Default Property Item(x As Short) As Integer' cannot be implemented by a WriteOnly property. + Public WriteOnly Property Item(x As Short) As Integer Implements I.Item + ~~~~~~ +BC37313: Init-only 'Default Property Item(x As Short) As Integer' cannot be implemented. + Public WriteOnly Property Item(x As Short) As Integer Implements I.Item + ~~~~~~ + + comp1.AssertTheseDiagnostics(expected1) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics(expected1) + End Sub + + + Public Sub Implementing_03() + + Dim csSource = +" +public interface I +{ + int P0 { set; get; } + int P1 { init; get; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, references:={csCompilation}) + Dim expected1 = + +BC37313: Init-only 'Property P1 As Integer' cannot be implemented. + Public Property P0 As Integer Implements I.P0, I.P1 + ~~~~ +BC37313: Init-only 'Property P1 As Integer' cannot be implemented. + Public Property P0 As Integer Implements I.P1, I.P0 + ~~~~ + + comp1.AssertTheseDiagnostics(expected1) + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, references:={csCompilation}) + comp2.AssertTheseDiagnostics(expected1) + End Sub + + + Public Sub Implementing_04() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30149: Class 'Test' must implement 'Property P As Integer' for interface 'CL1'. + Implements CL1 + ~~~ +BC30937: Member 'CL1.P' that matches this signature cannot be implemented because the interface 'CL1' contains multiple members with this same name and signature: + 'Property P As Integer' + 'Property P As Integer' + Property P As Integer Implements CL1.P + ~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("Test.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.False(pSet.ExplicitInterfaceImplementations.Single().IsInitOnly) + Assert.Empty(pSet.ExplicitInterfaceImplementations.Single().ReturnTypeCustomModifiers) + Assert.Empty(p.GetMethod.ExplicitInterfaceImplementations.Single().ReturnTypeCustomModifiers) + Assert.Empty(p.ExplicitInterfaceImplementations.Single().TypeCustomModifiers) + End Sub + + + Public Sub Implementing_05() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30149: Class 'Test' must implement 'Property P As Integer' for interface 'CL1'. + Implements CL1 + ~~~ +BC30937: Member 'CL1.P' that matches this signature cannot be implemented because the interface 'CL1' contains multiple members with this same name and signature: + 'Property P As Integer' + 'Property P As Integer' + Property P As Integer Implements CL1.P + ~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("Test.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.True(pSet.ExplicitInterfaceImplementations.Single().IsInitOnly) + Assert.NotEmpty(pSet.ExplicitInterfaceImplementations.Single().ReturnTypeCustomModifiers) + Assert.NotEmpty(p.GetMethod.ExplicitInterfaceImplementations.Single().ReturnTypeCustomModifiers) + Assert.NotEmpty(p.ExplicitInterfaceImplementations.Single().TypeCustomModifiers) + End Sub + + + Public Sub LateBound_01() + + Dim csSource = +" +public class C +{ + public int P0 { init; get; } + public int P1 { init; get; } + public int P2 { init; get; } + public int P3 { init; get; } + private int[] _item = new int[10]; + public int this[int x] { init => _item[x] = value; get => _item[x]; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim expectedOutput As String = "-40 -41 0 -43 40 41 42 0 44 0 46 47" + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:=expectedOutput).VerifyDiagnostics() + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp2, expectedOutput:=expectedOutput).VerifyDiagnostics() + End Sub + + + Public Sub LateBound_02() + + Dim csSource = +" +public class C +{ + private int[] _item = new int[12]; + public int this[int x] { init => _item[x] = value; get => _item[x]; } + public int this[short x] { init => throw null; get => throw null; } +} +" + Dim csCompilation = CreateCSharpCompilation(csSource + IsExternalInitTypeDefinition).EmitToImageReference() + + Dim source1 = + + + + + Dim expectedOutput As String = "40 41 42 43 44 45 46 47 48 49 50 51" + Dim comp1 = CreateCompilation(source1, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp1, expectedOutput:=expectedOutput).VerifyDiagnostics() + + Dim comp2 = CreateCompilation(source1, parseOptions:=TestOptions.Regular16, options:=TestOptions.DebugExe, references:={csCompilation}) + CompileAndVerify(comp2, expectedOutput:=expectedOutput).VerifyDiagnostics() + End Sub + + + + Public Sub ModReqOnSetAccessorParameter() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + ' An expected error on the override is missing due to https://github.com/dotnet/roslyn/issues/50327 + compilation.AssertTheseDiagnostics( + +BC30657: 'Property1' has a return type that is not supported or parameter types that are not supported. + c.Property1 = 42 + ~~~~~~~~~~~ +BC30456: 'set_Property1' is not a member of 'C'. + c.set_Property1(43) + ~~~~~~~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Assert.Null(p.GetUseSiteErrorInfo()) + Assert.False(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnSetAccessorParameter_AndProperty() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30643: Property 'C.Property1' is of an unsupported type. + Public Overrides WriteOnly Property Property1 As Integer + ~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + c.Property1 = 42 + ~~~~~~~~~ +BC30456: 'set_Property1' is not a member of 'C'. + c.set_Property1(43) + ~~~~~~~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Assert.NotNull(p.GetUseSiteErrorInfo()) + Assert.True(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnStaticMethod() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30657: 'M' has a return type that is not supported or parameter types that are not supported. + C.M() + ~ +) + + Dim m = compilation.GetMember(Of MethodSymbol)("C.M") + Assert.False(m.IsInitOnly) + Assert.NotNull(m.GetUseSiteErrorInfo()) + Assert.True(m.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnInstanceMethod() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30657: 'M' has a return type that is not supported or parameter types that are not supported. + c.M() + ~ +) + + Dim m = compilation.GetMember(Of MethodSymbol)("C.M") + Assert.False(m.IsInitOnly) + Assert.NotNull(m.GetUseSiteErrorInfo()) + Assert.True(m.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnStaticSet() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30657: 'P' has a return type that is not supported or parameter types that are not supported. + C.P = 2 + ~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Assert.Null(p.GetUseSiteErrorInfo()) + Assert.False(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnSetterOfRefProperty() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30456: 'get_Property1' is not a member of 'C'. + Dim x1 = c.get_Property1() + ~~~~~~~~~~~~~~~ +BC30456: 'set_Property' is not a member of 'C'. + c.set_Property(i) + ~~~~~~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Assert.Null(p.GetUseSiteErrorInfo()) + Assert.False(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnRefProperty_OnRefReturn() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30456: 'get_Property1' is not a member of 'C'. + Dim x1 = c.get_Property1() + ~~~~~~~~~~~~~~~ +BC30456: 'set_Property' is not a member of 'C'. + c.set_Property(i) + ~~~~~~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + Dim x2 = c.Property1 + ~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + c.Property1 = i + ~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Dim pGet = p.GetMethod + Assert.False(pGet.IsInitOnly) + Assert.NotNull(pGet.GetUseSiteErrorInfo()) + Assert.True(pGet.HasUnsupportedMetadata) + + Assert.NotNull(p.GetUseSiteErrorInfo()) + Assert.True(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnRefProperty_OnReturn() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30456: 'get_Property1' is not a member of 'C'. + Dim x1 = c.get_Property1() + ~~~~~~~~~~~~~~~ +BC30456: 'set_Property' is not a member of 'C'. + c.set_Property(i) + ~~~~~~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + Dim x2 = c.Property1 + ~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + c.Property1 = i + ~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Dim pGet = p.GetMethod + Assert.False(pGet.IsInitOnly) + Assert.NotNull(pGet.GetUseSiteErrorInfo()) + Assert.True(pGet.HasUnsupportedMetadata) + + Assert.NotNull(p.GetUseSiteErrorInfo()) + Assert.True(p.HasUnsupportedMetadata) + End Sub + + + + Public Sub ModReqOnGetAccessorReturnValue() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + ' An error on override is not reported due to https://github.com/dotnet/roslyn/issues/50327 + compilation.AssertTheseDiagnostics( + +BC30456: 'get_Property1' is not a member of 'C'. + Dim x1 = c.get_Property1() + ~~~~~~~~~~~~~~~ +BC30456: 'set_Property' is not a member of 'C'. + c.set_Property(1) + ~~~~~~~~~~~~~~ +BC30657: 'Property1' has a return type that is not supported or parameter types that are not supported. + Dim x2 = c.Property1 + ~~~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.Null(pSet.GetUseSiteErrorInfo()) + Assert.False(pSet.HasUnsupportedMetadata) + Dim pGet = p.GetMethod + Assert.False(pGet.IsInitOnly) + Assert.NotNull(pGet.GetUseSiteErrorInfo()) + Assert.True(pGet.HasUnsupportedMetadata) + + Assert.Null(p.GetUseSiteErrorInfo()) + Assert.False(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModReqOnPropertyAndGetAccessorReturnValue() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30643: Property 'C.Property1' is of an unsupported type. + Overrides Property Property1 As Integer + ~~~~~~~~~ +BC30456: 'get_Property1' is not a member of 'C'. + Dim x1 = c.get_Property1() + ~~~~~~~~~~~~~~~ +BC30456: 'set_Property' is not a member of 'C'. + c.set_Property(1) + ~~~~~~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + Dim x2 = c.Property1 + ~~~~~~~~~ +BC30643: Property 'C.Property1' is of an unsupported type. + c.Property1 = 2 + ~~~~~~~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.Property1") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.Null(pSet.GetUseSiteErrorInfo()) + Assert.False(pSet.HasUnsupportedMetadata) + Dim pGet = p.GetMethod + Assert.False(pGet.IsInitOnly) + Assert.NotNull(pGet.GetUseSiteErrorInfo()) + Assert.True(pGet.HasUnsupportedMetadata) + + Assert.NotNull(p.GetUseSiteErrorInfo()) + Assert.True(p.HasUnsupportedMetadata) + End Sub + + + Public Sub ModOptOnSet() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + CompileAndVerify(compilation).VerifyDiagnostics() + + Dim p = compilation.GetMember(Of PropertySymbol)("C.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.Null(pSet.GetUseSiteErrorInfo()) + Assert.False(pSet.HasUnsupportedMetadata) + Assert.Null(p.GetUseSiteErrorInfo()) + Assert.False(p.HasUnsupportedMetadata) + End Sub + + + Public Sub IsExternalInitCheck(modifierName As String) + Dim ilSource = " +.class public auto ansi beforefieldinit C extends System.Object +{ + .method public hidebysig newslot specialname + instance void modreq(" + modifierName + ") set_P(int32 x) cil managed + { + IL_0000: ldnull + IL_0001: throw + } + + .property instance int32 P() + { + .set instance void modreq(" + modifierName + ") C::set_P(int32) + } + + .method public hidebysig specialname rtspecialname instance void .ctor () cil managed + { + IL_0000: ldnull + IL_0001: throw + } +} + +.class public auto ansi sealed beforefieldinit " + modifierName + " extends System.Object +{ + .method public hidebysig specialname rtspecialname instance void .ctor () cil managed + { + IL_0000: ldnull + IL_0001: throw + } +} +" + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, parseOptions:=TestOptions.RegularLatest, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30657: 'P' has a return type that is not supported or parameter types that are not supported. + c.P = 2 + ~~~ +) + + Dim p = compilation.GetMember(Of PropertySymbol)("C.P") + Dim pSet = p.SetMethod + Assert.False(pSet.IsInitOnly) + Assert.NotNull(pSet.GetUseSiteErrorInfo()) + Assert.True(pSet.HasUnsupportedMetadata) + Assert.Null(p.GetUseSiteErrorInfo()) + Assert.False(p.HasUnsupportedMetadata) + End Sub + + + Public Sub IsInitOnlyValue() + Dim vbSource1 = + + + + + + Dim compilation1 = CreateCompilation(vbSource1, options:=TestOptions.ReleaseDll) + + Dim vbSource2 = + + + Sub DoSomething(x As Integer) + End Sub +End Module +]]> + + + + Dim compilation2 = CreateCompilation(vbSource2, references:={compilation1.ToMetadataReference()}, options:=TestOptions.ReleaseDll) + + Dim tree = compilation2.SyntaxTrees.Single() + Dim model = compilation2.GetSemanticModel(tree) + Dim lambda = tree.GetRoot.DescendantNodes().OfType(Of LambdaExpressionSyntax)().Single() + + Assert.False(DirectCast(model.GetSymbolInfo(lambda).Symbol, MethodSymbol).IsInitOnly) + + Dim invocation = tree.GetRoot.DescendantNodes().OfType(Of InvocationExpressionSyntax)().Single() + Assert.False(DirectCast(model.GetSymbolInfo(invocation).Symbol, MethodSymbol).IsInitOnly) + + Dim verify = Sub(compilation As VisualBasicCompilation) + Dim test1 = compilation.GetTypeByMetadataName("Test1`1") + Dim p = test1.GetMember(Of PropertySymbol)("P") + Assert.False(p.SetMethod.IsInitOnly) + Assert.False(p.GetMethod.IsInitOnly) + + Assert.False(test1.GetMember(Of MethodSymbol)("M1").IsInitOnly) + Assert.False(test1.GetMember(Of MethodSymbol)("M2").IsInitOnly) + + Dim test1Constructed = compilation.GetTypeByMetadataName("Test2").BaseTypeNoUseSiteDiagnostics + p = test1Constructed.GetMember(Of PropertySymbol)("P") + Assert.False(p.SetMethod.IsInitOnly) + Assert.False(p.GetMethod.IsInitOnly) + + Assert.False(test1Constructed.GetMember(Of MethodSymbol)("M1").IsInitOnly) + Assert.False(test1Constructed.GetMember(Of MethodSymbol)("M2").IsInitOnly) + + Dim d = compilation.GetTypeByMetadataName("D") + For Each m As MethodSymbol In d.GetMembers() + Assert.False(m.IsInitOnly) + Next + End Sub + + verify(compilation2) + + Dim compilation3 = CreateCompilation(vbSource1, references:={compilation2.ToMetadataReference()}, options:=TestOptions.ReleaseDll) + verify(compilation3) + End Sub + + End Class +End Namespace diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/CustomModifiersTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/CustomModifiersTests.vb index 70023459bc004..c28e068e536ea 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/CustomModifiersTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/CustomModifiersTests.vb @@ -2631,5 +2631,695 @@ BC40001: 'Public Overrides Function M(x As (Object, Object)) As (a As Object, b End Sub + + + Public Sub OverrideWithModreq_01() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30657: 'get_P' has a return type that is not supported or parameter types that are not supported. + Overrides Function get_P() As Integer + ~~~~~ +) + End Sub + + + + Public Sub OverrideWithModreq_02() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30643: Property 'CL1.P' is of an unsupported type. + Overrides Readonly Property P As Integer + ~ +) + End Sub + + + + Public Sub OverrideWithModreq_03() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + + + + Public Sub OverrideWithModreq_04() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + + + + Public Sub OverrideWithModreq_05() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + + + + Public Sub OverrideWithModreq_06() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + + + + Public Sub OverrideWithModreq_07() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + + + + Public Sub ImplementWithModreq_01() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30657: 'get_P' has a return type that is not supported or parameter types that are not supported. + Function get_P() As Integer Implements CL1.get_P + ~~~~~ +) + End Sub + + + + Public Sub ImplementWithModreq_02() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseDiagnostics( + +BC30643: Property 'CL1.P' is of an unsupported type. + ReadOnly Property P As Integer Implements CL1.P + ~ +) + End Sub + + + + Public Sub ImplementWithModreq_03() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + + + + Public Sub ImplementWithModreq_04() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + 'CompileAndVerify(compilation) + End Sub + + + + Public Sub ImplementWithModreq_05() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + 'CompileAndVerify(compilation) + End Sub + + + + Public Sub ImplementWithModreq_06() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + 'CompileAndVerify(compilation) + End Sub + + + + Public Sub ImplementWithModreq_07() + Dim ilSource = .Value + + Dim vbSource = + + + + + + Dim compilation = CreateCompilationWithCustomILSource(vbSource, ilSource, options:=TestOptions.ReleaseDll) + + compilation.AssertTheseEmitDiagnostics( + +) + CompileAndVerify(compilation) + End Sub + End Class End Namespace diff --git a/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/EEMethodSymbol.vb b/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/EEMethodSymbol.vb index 7c8d7b05f45eb..a120bcf3c7f31 100644 --- a/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/EEMethodSymbol.vb +++ b/src/ExpressionEvaluator/VisualBasic/Source/ExpressionCompiler/Symbols/EEMethodSymbol.vb @@ -411,6 +411,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator End Get End Property + Public Overrides ReadOnly Property IsInitOnly As Boolean + Get + Return False + End Get + End Property + Public Overrides ReadOnly Property IsOverloads As Boolean Get Return False