Skip to content

Fix a compiler exception - #463

Merged
cpurdy merged 1 commit into
masterfrom
gene/compiler
May 17, 2026
Merged

cpurdy merged 1 commit into
masterfrom
gene/compiler

Conversation

@ggleyzer

Copy link
Copy Markdown
Collaborator

This issues was reported by Dima on Discord.

The gist of the problem lies in the flow of processing by the StageManager:

  1. during the "resolveName" stage, we resolve all the names with a possible exception of the annotation parameters, since they could be represented by expressions and need to be "validated"

  2. during the "validateContent" stage, we validate those "left behind" annotation parameters; if detect that some of them are on not-yet-validated, we repeat the cycle via mgr.requestRevisit() API

The problem arises when the validation requires using the TypeInfo for classes that depend on those "not-yet-validated" ones. In that case, the UnresolvedNameConstant or UnresolvedTypeConstant would throw an UnsupportedOperationException, causing the compiler termination.

The proposed fix replaces the UnsupportedOperationException with the CompilerException and handles it in the StageManager in the same way a standard "Name not resolved" error

@ggleyzer
ggleyzer requested a review from cpurdy May 17, 2026 16:29

@cpurdy cpurdy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a reasonable solution to avoid the exception. Are there still any remaining cases where we should be able to resolve something but don't?

@cpurdy
cpurdy merged commit 91f6d7d into master May 17, 2026
4 checks passed
@cpurdy
cpurdy deleted the gene/compiler branch May 17, 2026 16:59
lagergren added a commit that referenced this pull request May 23, 2026
…ls in expression position

Closes two grammar gaps that surface as parse errors against the
manualTests corpus (CI hides these on master because the validation
step is gated on path-filter `lang/**`):

* annos.x:141 — `annotation Foo(...) into Bar { ... }` inside a method
  body. Local class/interface/mixin/service declarations were already in
  the `_statement` choice; `annotation_declaration` was not. Added.

* generics.x:27 — `Base<Int>.Child2<String>` as a value-position type
  literal. `member_type` was reachable from `_non_bi_type` only, so it
  was never tried in expression position. Added to `_expression` next
  to `$.generic_type` (the symmetric case for non-virtual-child type
  literals).

  The with-type-arguments form of `member_type` is split into its own
  alternative at `prec.left(MAX_PRECEDENCE_PLUS_3)` so it outranks
  `member_expression` (MAX_PRECEDENCE_PLUS_2). Without that, the GLR
  conflict resolver preferred `member_expression(Base<Int>, Child2)`
  and choked on the trailing `<String>`. The no-arguments form keeps
  default precedence so `Base<Int>.Child` still parses as a
  `member_expression` (no AST shape change for that case).

  The previously-declared `[$.member_type, $._expression]` GLR conflict
  is now redundant (static precedence resolves the ambiguity) and was
  removed; tree-sitter flagged it as an unnecessary conflict.

Why this regressed silently
---------------------------
Neither failure is a tooling/grammar regression — both are new XTC
syntax patterns added to the manualTests corpus that the grammar
never had a test case for:

* generics.x:27 was added on 2026-05-06 by 0120712 ("Fix
  NameExpression code production for parameterized virtual child
  classes") — a compiler bugfix that needed a test exercising
  `Base<Int>.Child2<String>`.
* annos.x:141 was added on 2026-05-17 by 91f6d7d ("Fix a compiler
  exception (#463)") — a compiler bugfix that needed a test exercising
  a local `annotation … into …` declaration.

Both PRs only touched `manualTests/src/main/x/` and `javatools/`,
never `lang/`. The `dorny/paths-filter` gate in
`.github/workflows/commit.yml` skips the tree-sitter validation step
whenever no `lang/**` paths change, so the master CI run was green
even though both new test files would have failed grammar validation.
This PR (which touches `lang/vscode-extension/**`) is the first since
May 6 to trip the gate and run the validation, which is why both
failures surfaced together here.

The skip lists (parked.txt, intentional.txt) and the grammar template
itself were unchanged between PR #452 (May 1, last grammar work) and
the May 6 / May 17 corpus additions — git log confirms generics.x was
never in any skip list, so the parked.txt header comment "generics.x
parses cleanly now -- removed from this list" is incidentally
misleading; it refers to a draft state that never made it into git.

Verified: `:lang:tree-sitter:testTreeSitterParse` 881/881 (was 879/881),
`:lang:lsp-server:test -Plsp.adapter=treesitter` green,
`validateTreeSitterGrammar` no warnings.
@lagergren lagergren mentioned this pull request May 23, 2026
lagergren added a commit that referenced this pull request May 23, 2026
…ls in expression position

Closes two grammar gaps that surface as parse errors against the
manualTests corpus (CI hides these on master because the validation
step is gated on path-filter `lang/**`):

* annos.x:141 — `annotation Foo(...) into Bar { ... }` inside a method
  body. Local class/interface/mixin/service declarations were already in
  the `_statement` choice; `annotation_declaration` was not. Added.

* generics.x:27 — `Base<Int>.Child2<String>` as a value-position type
  literal. `member_type` was reachable from `_non_bi_type` only, so it
  was never tried in expression position. Added to `_expression` next
  to `$.generic_type` (the symmetric case for non-virtual-child type
  literals).

  The with-type-arguments form of `member_type` is split into its own
  alternative at `prec.left(MAX_PRECEDENCE_PLUS_3)` so it outranks
  `member_expression` (MAX_PRECEDENCE_PLUS_2). Without that, the GLR
  conflict resolver preferred `member_expression(Base<Int>, Child2)`
  and choked on the trailing `<String>`. The no-arguments form keeps
  default precedence so `Base<Int>.Child` still parses as a
  `member_expression` (no AST shape change for that case).

  The previously-declared `[$.member_type, $._expression]` GLR conflict
  is now redundant (static precedence resolves the ambiguity) and was
  removed; tree-sitter flagged it as an unnecessary conflict.

Why this regressed silently
---------------------------
Neither failure is a tooling/grammar regression — both are new XTC
syntax patterns added to the manualTests corpus that the grammar
never had a test case for:

* generics.x:27 was added on 2026-05-06 by 0120712 ("Fix
  NameExpression code production for parameterized virtual child
  classes") — a compiler bugfix that needed a test exercising
  `Base<Int>.Child2<String>`.
* annos.x:141 was added on 2026-05-17 by 91f6d7d ("Fix a compiler
  exception (#463)") — a compiler bugfix that needed a test exercising
  a local `annotation … into …` declaration.

Both PRs only touched `manualTests/src/main/x/` and `javatools/`,
never `lang/`. The `dorny/paths-filter` gate in
`.github/workflows/commit.yml` skips the tree-sitter validation step
whenever no `lang/**` paths change, so the master CI run was green
even though both new test files would have failed grammar validation.
This PR (which touches `lang/vscode-extension/**`) is the first since
May 6 to trip the gate and run the validation, which is why both
failures surfaced together here.

The skip lists (parked.txt, intentional.txt) and the grammar template
itself were unchanged between PR #452 (May 1, last grammar work) and
the May 6 / May 17 corpus additions — git log confirms generics.x was
never in any skip list, so the parked.txt header comment "generics.x
parses cleanly now -- removed from this list" is incidentally
misleading; it refers to a draft state that never made it into git.

Verified: `:lang:tree-sitter:testTreeSitterParse` 881/881 (was 879/881),
`:lang:lsp-server:test -Plsp.adapter=treesitter` green,
`validateTreeSitterGrammar` no warnings.
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.

2 participants