@@ -1914,33 +1914,47 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
19141914
19151915 Debug.Assert(propertyAccess.AccessKind <> PropertyAccessKind.Get)
19161916
1917+ Dim setMethod = propertySymbol.GetMostDerivedSetMethod()
1918+
19171919 If Not propertyAccess.IsWriteable Then
1918- ReportDiagnostic(diagnostics, node, ERRID.ERR_NoSetProperty1, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol))
1920+ If setMethod Is Nothing Then
1921+ ReportDiagnostic(diagnostics, node, ERRID.ERR_NoSetProperty1, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol))
1922+ Else
1923+ Debug.Assert(setMethod.IsInitOnly)
1924+ ReportDiagnostic(diagnostics, node, ERRID.ERR_AssignmentInitOnly, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol))
1925+ End If
1926+
19191927 isError = True
1920- Else
1921- Dim setMethod = propertySymbol.GetMostDerivedSetMethod()
1928+ End If
19221929
1923- ' NOTE: the setMethod could not be present, while it would still be
1924- ' possible to write to the property in a case
1925- ' where the property is a getter-only autoproperty
1926- ' and the writing is happening in the corresponding constructor or initializer
1927- If setMethod IsNot Nothing Then
1928- ReportDiagnosticsIfObsoleteOrNotSupportedByRuntime(diagnostics, setMethod, node)
1930+ ' NOTE: the setMethod could not be present, while it would still be
1931+ ' possible to write to the property in a case
1932+ ' where the property is a getter-only autoproperty
1933+ ' and the writing is happening in the corresponding constructor or initializer
1934+ If setMethod IsNot Nothing Then
1935+
1936+ If propertyAccess.IsWriteable AndAlso setMethod.IsInitOnly Then
1937+ InternalSyntax.Parser.CheckFeatureAvailability(diagnostics,
1938+ node.Location,
1939+ DirectCast (node.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion,
1940+ InternalSyntax.Feature.InitOnlySettersUsage)
1941+ End If
19291942
1930- If ReportUseSiteError(diagnostics, op1.Syntax, setMethod) Then
1931- isError = True
1932- Else
1933- Dim accessThroughType = GetAccessThroughType(propertyAccess.ReceiverOpt)
1934- Dim useSiteDiagnostics As HashSet( Of DiagnosticInfo) = Nothing
1943+ ReportDiagnosticsIfObsoleteOrNotSupportedByRuntime(diagnostics, setMethod, node)
19351944
1936- If Not IsAccessible(setMethod, useSiteDiagnostics, accessThroughType) AndAlso
1937- IsAccessible(propertySymbol, useSiteDiagnostics, accessThroughType) Then
1938- ReportDiagnostic(diagnostics, node, ERRID.ERR_NoAccessibleSet, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol))
1939- isError = True
1940- End If
1945+ If ReportUseSiteError(diagnostics, op1.Syntax, setMethod) Then
1946+ isError = True
1947+ Else
1948+ Dim accessThroughType = GetAccessThroughType(propertyAccess.ReceiverOpt)
1949+ Dim useSiteDiagnostics As HashSet( Of DiagnosticInfo) = Nothing
19411950
1942- diagnostics.Add(node, useSiteDiagnostics)
1951+ If Not IsAccessible(setMethod, useSiteDiagnostics, accessThroughType) AndAlso
1952+ IsAccessible(propertySymbol, useSiteDiagnostics, accessThroughType) Then
1953+ ReportDiagnostic(diagnostics, node, ERRID.ERR_NoAccessibleSet, CustomSymbolDisplayFormatter.ShortErrorName(propertySymbol))
1954+ isError = True
19431955 End If
1956+
1957+ diagnostics.Add(node, useSiteDiagnostics)
19441958 End If
19451959 End If
19461960
0 commit comments