Allow global language imports in REPL and snippet compiler - #25458
Merged
bracevac merged 5 commits intoMar 11, 2026
Conversation
Member
Author
|
This is an alternative to #25415 |
bracevac
force-pushed
the
fix-experimental-repl-import-v2
branch
4 times, most recently
from
March 8, 2026 19:27
cad95f0 to
985919c
Compare
bracevac
commented
Mar 8, 2026
bracevac
commented
Mar 8, 2026
bishabosha
reviewed
Mar 9, 2026
Previously, `import language.experimental.captureChecking` (and related
global language imports) were rejected in the REPL and snippet compiler
because they appeared in nested scopes rather than at the toplevel.
This change takes a structural approach to fix both contexts:
- REPL: Forward `outermost` through `blockStatSeq` in Interactive mode
so the parser treats REPL-level imports as toplevel. After a successful
compile, propagate global language imports to `rootCtx` as `-language:`
settings so subsequent inputs can parse CC syntax (e.g. `^`).
- Snippet compiler: Extract global language imports from snippet body and
place them before the `object Snippet {}` wrapper, making them genuine
toplevel imports.
Fixes scala#16250
Move propagateLanguageImports before compile so that newRun derives the state context from an already-updated rootCtx, eliminating the post-compilation settings sync.
Move the set of global language features (pureFunctions, captureChecking, separationChecking, safe) into Feature.globalLanguageImports so that ReplDriver and WrappedSnippet derive from a single source of truth.
bracevac
force-pushed
the
fix-experimental-repl-import-v2
branch
from
March 11, 2026 10:43
a14790e to
b81511e
Compare
Contributor
|
Function types seem to have wrong capture sets printed: |
Member
Author
|
Yikes! I didn't realize how broken the CC pretty printing was. Edit: It was straightforward to fix. |
bracevac
force-pushed
the
fix-experimental-repl-import-v2
branch
from
March 11, 2026 14:20
db37130 to
daa49e3
Compare
The REPL rendered types at `typerPhase.next`, before capture checking
runs, so inferred capture sets were invisible. When CC is enabled, render
at `checkCapturesPhase` instead where Setup has added `CaptureAnnotations`
and the `CapturingType` extractor works.
Additionally, the local defs in renderDefinitions captured the outer
given Context instead of receiving the phase-adjusted context from
atPhase. Adding (using Context) parameters fixes the propagation.
Also route the `CaptureAnnotation` fallback in `PlainPrinter` through
`toTextCapturing` so function types render as () ->{a} Unit rather
than (() -> Unit)^{a}.
bracevac
force-pushed
the
fix-experimental-repl-import-v2
branch
from
March 11, 2026 14:54
daa49e3 to
3b55f53
Compare
natsukagami
approved these changes
Mar 11, 2026
natsukagami
left a comment
Contributor
There was a problem hiding this comment.
Nicer error messages too ð
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
import language.experimental.captureChecking(and related global language imports) were rejected in the REPL and snippet compiler because they appeared in nested scopes rather than at the toplevel.This change takes a structural approach to fix both contexts:
REPL: Forward
outermostthroughblockStatSeqin Interactive mode so the parser treats REPL-level imports as toplevel. After a successful compile, propagate global language imports torootCtxas-language:settings so subsequent inputs can parse CC syntax (e.g.^).Snippet compiler: Extract global language imports from snippet body and place them before the
object Snippet {}wrapper, making them genuine toplevel imports.Fixes #16250
How much have your relied on LLM-based tools in this contribution?
Used Claude extensively to analyze the problem and iterate on the solution.
How was the solution tested?
There are REPL and snippet compiler tests. I also verified manually
within the REPL that the top-level CC import works.
Updated some snippets in the CC language ref to verify that the snippet compilation
works as well.