Skip to content

syntax: Disallow using @goto to skip finally blocks#60979

Merged
IanButterworth merged 5 commits intoJuliaLang:masterfrom
IanButterworth:ib/goto_fixes
Apr 2, 2026
Merged

syntax: Disallow using @goto to skip finally blocks#60979
IanButterworth merged 5 commits intoJuliaLang:masterfrom
IanButterworth:ib/goto_fixes

Conversation

@IanButterworth
Copy link
Copy Markdown
Member

Add syntax errors when @goto is used to jump out of try, catch, or else blocks when a finally block is present.

Fixes #60972

@IanButterworth IanButterworth added the needs pkgeval Tests for all registered packages should be run with this change label Feb 10, 2026
@Keno
Copy link
Copy Markdown
Member

Keno commented Feb 10, 2026

In the unlikely event that pkgeval comes back negative, I will note that it is possible to use syntax evolution to detect the syntax version of the calling module.

@oscardssmith oscardssmith added the triage This should be discussed on a triage call label Feb 10, 2026
@IanButterworth IanButterworth force-pushed the ib/goto_fixes branch 2 times, most recently from 876401f to 993b392 Compare February 10, 2026 18:35
@oscardssmith
Copy link
Copy Markdown
Member

oscardssmith commented Feb 12, 2026

Triage likes this (especially that it parallels goto within try with finally)

julia> function f()
           try
               @goto hi
           catch
               return 1
           finally
              return 3
           end
           @label hi
           return 2
       end
ERROR: syntax: goto from a try/finally block is not permitted around REPL[6]:2
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

Triage also thinks that this should probably done via syntax evolution (potentially with a deprecation warning). We built ourselves a mechanism for evolving the language syntax so we should be using it.

@oscardssmith oscardssmith removed the triage This should be discussed on a triage call label Feb 12, 2026
@oscardssmith
Copy link
Copy Markdown
Member

@nanosoldier runtests()

@nanosoldier
Copy link
Copy Markdown
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Report summary

❗ Packages that crashed

281 packages crashed on the previous version too.

✖ Packages that failed

18 packages failed only on the current version.

  • Package has test failures: 4 packages
  • Tests became inactive: 1 packages
  • Test duration exceeded the time limit: 13 packages

1229 packages failed on the previous version too.

✔ Packages that passed tests

8 packages passed tests only on the current version.

  • Other: 8 packages

5573 packages passed tests on the previous version too.

~ Packages that at least loaded

3413 packages successfully loaded on the previous version too.

➖ Packages that were skipped altogether

3 packages were skipped only on the current version.

  • Package could not be installed: 3 packages

906 packages were skipped on the previous version too.

@PallHaraldsson
Copy link
Copy Markdown
Contributor

I looked at all of (these) failures (probably all false alarms);

EliminateGraphs | v0.2.1 | fail | test | ▇▇▇▇▇▇▇▇▇▇▇
PushVectors | v0.2.1 | fail | test | ▇▇▇▅▇▇▇▅▅▇▇
MetropolisAlgorithm | v0.0.1 | fail | test | ▇▇▇▇▇▇▇▇▇▇▅
MCMCTempering | v0.3.2 | fail | test | ▅▅▇▅▅▅▅▇▇▅▇

EliminateGraphs generates a different random graphs, no longer the same (based of rand, likely unchanged, but I'm guessing some numerical inaccuracy follows).

MetropolisAlgorithm is about numerical accuracy (slightly changed, likely testing with too strict tolerance)

PushVectors is a failed speed test (no longer improving, not a concern)

@IanButterworth
Copy link
Copy Markdown
Member Author

Great.

Regarding the syntax evolution suggestion from triage, I don't know how to do that. Does someone want to take over here?

@Keno
Copy link
Copy Markdown
Member

Keno commented Feb 19, 2026

goto needs to become a special macro name like VERSION and then use the same mechanism. Claude will be able to do it with that sentence, but if you need me to do it, I can.

@IanButterworth
Copy link
Copy Markdown
Member Author

Sorry I tried and neither I nor Claude could figure it out. Are there docs?

@Keno
Copy link
Copy Markdown
Member

Keno commented Feb 21, 2026

I'm trying the following prompt:

make `goto` a  conditional keyword like VERSION, then fix the PR by adding a new oldsymbolicgoto HEAD IR form that doesn't have the error check, and using the same mechanism as the `@VERSION` macro to conditionally emit the error-ful version only for new syntax versions.  

I'd put money on that working, but I'll need to check back in the morning.

@Keno
Copy link
Copy Markdown
Member

Keno commented Feb 21, 2026

I pushed Claude's work to https://github.com/JuliaLang/julia/compare/kf/ib/goto_fixes?expand=1. I didn't review it in detail, but looks about right.

IanButterworth and others added 2 commits March 19, 2026 21:29
Add syntax errors when `@goto` is used to jump out of try, catch, or else blocks when a finally block is present.

Fixes JuliaLang#60972

Co-Authored-By: Claude <noreply@anthropic.com>
Written by Claude

(cherry picked from commit 97371de)
Co-Authored-By: Claude <claude@users.noreply.github.com>
@IanButterworth IanButterworth requested a review from Keno March 20, 2026 13:37
@IanButterworth IanButterworth removed the needs pkgeval Tests for all registered packages should be run with this change label Apr 1, 2026
@IanButterworth IanButterworth added merge me PR is reviewed. Merge when all tests are passing and removed merge me PR is reviewed. Merge when all tests are passing labels Apr 1, 2026
@IanButterworth IanButterworth merged commit 6a750cd into JuliaLang:master Apr 2, 2026
8 checks passed
@IanButterworth IanButterworth deleted the ib/goto_fixes branch April 2, 2026 23:23
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.

@goto in a catch skips finally

5 participants