Skip to content

Fix parsing errors on anonymous types in variant tags and generic arguments - #474

Open
davidheff wants to merge 1 commit into
integrated-application-development:masterfrom
davidheff:fix-anonymous-type-parsing
Open

davidheff wants to merge 1 commit into
integrated-application-development:masterfrom
davidheff:fix-anonymous-type-parsing

Conversation

@davidheff

Copy link
Copy Markdown

SonarDelphi fails to parse two constructs that the Delphi compiler accepts:

type
  TRec = record
  case Kind: (rkInt, rkDbl) of                // anonymous enum (or subrange) as a variant tag type
    rkInt: (I: Integer);
    rkDbl: (D: Double);
  end;

  TFoo = class
    Values: TArray<array[Boolean] of Double>; // anonymous array type as a generic argument
  end;

Each fails with "no viable alternative", and the whole file drops out of analysis.

Changes:

  • recordVariantTag accepts an anonymous enum or subrange type as well as a type reference.
    SymbolTableVisitor already handles anonymous enums in variant tags through
    handleVarDeclaration, so the enum elements are declared and resolve.
  • genericArguments accepts anonymous array, set and procedural types, all of which
    NameResolutionHelper.resolve(TypeNode) already handles.

Scope, checked against Delphi 11: the compiler also accepts anonymous pointer (TArray<^Integer>)
and enum (TArray<(a, b)>) generic arguments. I've left those out because a leading ^ overlaps
with caret-escaped character literals (#111), <( is ambiguous with a comparison in expressions,
and an anonymous enum there would need its elements declared from inside a generic argument list.
I'm happy to follow up if you'd like them covered.

Tests: grammar tests for both constructs, plus symbol table tests showing that anonymous tag enum
elements resolve and that type references inside an anonymous array generic argument resolve. The
full delphi-frontend and delphi-checks suites pass.

🤖 Generated with Claude Code

@davidheff
davidheff force-pushed the fix-anonymous-type-parsing branch from 97d3b15 to 6b29b5c Compare October 9, 2026 01:52
@cirras
cirras self-requested a review October 9, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant