Skip to content

C#12: Class primary constructor with base invocation fails to parse #403

@boukeversteegh

Description

@boukeversteegh

Problem

C# 12 allows primary constructors on classes with base class invocation, but this syntax produces an ERROR node.

Reproduction

public class MyException(int id, string message) : Exception($"Error {id}: {message}");

Expected

Should parse similarly to how records with primary constructors are handled (using primary_constructor_base_type).

Actual

Produces an ERROR node wrapping the entire class declaration.

Working cases

Syntax Result
public record Foo(int x) : Base(x); ✅ Parses correctly
public class Foo(int x) { } ✅ Parses correctly
public class Foo(int x) : Base(x); ❌ ERROR node

Analysis

Looking at the grammar, primary_constructor_base_type appears to only be included in record_declaration, not in class_declaration. The C# 12 spec allows this syntax on all class types.

Reference

Environment

  • tree-sitter-c-sharp version: 0.23.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions