From 6d53a72250dbb3d9387cba34a9c1737f62e4ac34 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 29 Dec 2021 11:34:10 +0200 Subject: [PATCH] Adjust logic --- .../CSharp/Portable/Compiler/MethodBodySynthesizer.cs | 7 +++++++ .../Symbols/Source/SourcePropertyAccessorSymbol.cs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs b/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs index cdd918a3aeb46..e29050f835d45 100644 --- a/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs +++ b/src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs @@ -184,6 +184,13 @@ internal static BoundBlock ConstructAutoPropertyAccessorBody(SourceMemberMethodS } var field = property.BackingField; + if (field is null) + { + // This happens for public int { set; } where we produce ERR_AutoPropertyMustHaveGetAccessor + Debug.Assert(!property.HasGetAccessor); + return null; + } + Debug.Assert(!field.IsCreatedForFieldKeyword); var fieldAccess = new BoundFieldAccess(syntax, thisReference, field, ConstantValue.NotAvailable) { WasCompilerGenerated = true }; BoundStatement statement; diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs index a26d94ca41076..bb6a0e4d5a13e 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs @@ -209,7 +209,7 @@ protected SourcePropertyAccessorSymbol( isIterator) { _property = property; - _accessorBodyShouldBeSynthesized = (property.IsAutoProperty && property.HasGetAccessor && syntax is AccessorDeclarationSyntax { SemicolonToken.RawKind: (int)SyntaxKind.SemicolonToken, ExpressionBody: null, Body: null }) || + _accessorBodyShouldBeSynthesized = (property.IsAutoProperty && syntax is AccessorDeclarationSyntax { SemicolonToken.RawKind: (int)SyntaxKind.SemicolonToken, ExpressionBody: null, Body: null }) || property is SynthesizedRecordPropertySymbol; _containsFieldKeyword = property.IsIndexer ? false : NodeContainsFieldKeyword(getAccessorSyntax(syntax)); Debug.Assert(!_property.IsExpressionBodied, "Cannot have accessors in expression bodied lightweight properties");