Skip to content

Fix compiler state corruption after an exception in the OnUses handler#300

Open
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:fix/onuses-exception-state
Open

Fix compiler state corruption after an exception in the OnUses handler#300
TetzkatLipHoka wants to merge 1 commit into
remobjects:masterfrom
TetzkatLipHoka:fix/onuses-exception-state

Conversation

@TetzkatLipHoka

Copy link
Copy Markdown

With PS_USESSUPPORT, ProcessUses sets fModule to the name of the unit
being imported before invoking the OnUses callback. The regular failure
path (OnUses returning False) restores fModule and FParser afterwards,
but the exception handler did not. The stale fModule survives Cleanup:
Compile saves it as OldFileName on entry and restores it after the
System import, so every following Compile on the same instance treats
the main module as the previously failed unit and rejects any
'uses ;' with a bogus cross-reference error.

Reproduction (one compiler instance):

  1. Compile a script whose OnUses handler raises (e.g. a failing
    AddTypeS registration) -> correct error is reported.
  2. Compile any script with 'uses ;' again
    -> before: 'Cross-Reference error of '
    -> after: compiles normally (or reports the real error again).

The exception handler now restores FParser and fModule exactly like the
regular failure path. MakeError stays first so the error keeps being
attributed to the failed unit.

🤖 Generated with Claude Code

With PS_USESSUPPORT, ProcessUses sets fModule to the name of the unit
being imported before invoking the OnUses callback. The regular failure
path (OnUses returning False) restores fModule and FParser afterwards,
but the exception handler did not. The stale fModule survives Cleanup:
Compile saves it as OldFileName on entry and restores it after the
System import, so every following Compile on the same instance treats
the main module as the previously failed unit and rejects any
'uses <that unit>;' with a bogus cross-reference error.

Reproduction (one compiler instance):
  1. Compile a script whose OnUses handler raises (e.g. a failing
     AddTypeS registration) -> correct error is reported.
  2. Compile any script with 'uses <SameUnit>;' again
     -> before: 'Cross-Reference error of <unit>'
     -> after:  compiles normally (or reports the real error again).

The exception handler now restores FParser and fModule exactly like the
regular failure path. MakeError stays first so the error keeps being
attributed to the failed unit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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