Skip to content

The DeclarationModifiers class does not properly handle readonly keyword for struct \s #11850

@andriipatsula

Description

@andriipatsula

The initialization of isReadOnly in DeclarationModifiers.From must be extended in case ~ when ISymbol is type declaration.

DeclarationModifiers.cs#L80

public static DeclarationModifiers From(ISymbol symbol)
{
/// ...
    isReadOnly: field?.IsReadOnly == true || property?.IsReadOnly == true,
/// ...

DeclarationModifiers.From(...) is used not just for fields and properties and for SymbolKind.NamedType: with TypeKind.Class and TypeKind.Struct: SyntaxGenerator.cs#L612

namespace Foo
{
public readonly struct PublicReadonlyStruct { }
}

After roundtrip: source -> ISymbol-> SyntaxGenerator -> source:

namespace Foo
{
public struct PublicReadonlyStruct { }
}

Metadata

Metadata

Assignees

Labels

area-product-constructionIssues owned by the Product Construction team. Used to label epics and untriaged, loose issues.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions