Commit df5f612
authored
Allow global language imports in REPL and snippet compiler (scala#25458)
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
## 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.1 parent e5a1ae2 commit df5f612
File tree
16 files changed
+304
-70
lines changed- compiler/src/dotty/tools/dotc
- config
- parsing
- printing
- docs/_docs/reference/experimental/capture-checking
- project
- repl
- src/dotty/tools/repl
- test/dotty/tools/repl
- scaladoc
- src/dotty/tools/scaladoc/snippets
- test/dotty/tools/scaladoc/snippets
- tests/neg-custom-args/captures
16 files changed
+304
-70
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
255 | 262 | | |
256 | 263 | | |
257 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3937 | 3937 | | |
3938 | 3938 | | |
3939 | 3939 | | |
3940 | | - | |
3941 | | - | |
3942 | | - | |
3943 | | - | |
3944 | | - | |
3945 | | - | |
3946 | | - | |
3947 | | - | |
3948 | | - | |
| 3940 | + | |
3949 | 3941 | | |
3950 | 3942 | | |
3951 | 3943 | | |
| |||
5023 | 5015 | | |
5024 | 5016 | | |
5025 | 5017 | | |
5026 | | - | |
| 5018 | + | |
5027 | 5019 | | |
5028 | 5020 | | |
5029 | 5021 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
| 332 | + | |
| 333 | + | |
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
| |||
567 | 568 | | |
568 | 569 | | |
569 | 570 | | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
570 | 590 | | |
571 | 591 | | |
572 | 592 | | |
| |||
575 | 595 | | |
576 | 596 | | |
577 | 597 | | |
| 598 | + | |
| 599 | + | |
578 | 600 | | |
579 | 601 | | |
580 | 602 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1176 | 1176 | | |
1177 | 1177 | | |
1178 | 1178 | | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
1179 | 1183 | | |
1180 | 1184 | | |
1181 | 1185 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
16 | | - | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
| |||
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
49 | | - | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2003 | 2003 | | |
2004 | 2004 | | |
2005 | 2005 | | |
2006 | | - | |
2007 | | - | |
2008 | | - | |
2009 | | - | |
| 2006 | + | |
2010 | 2007 | | |
2011 | 2008 | | |
2012 | 2009 | | |
| |||
2965 | 2962 | | |
2966 | 2963 | | |
2967 | 2964 | | |
2968 | | - | |
2969 | | - | |
2970 | | - | |
2971 | | - | |
| 2965 | + | |
2972 | 2966 | | |
2973 | 2967 | | |
2974 | 2968 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
307 | 326 | | |
308 | 327 | | |
309 | 328 | | |
| |||
340 | 359 | | |
341 | 360 | | |
342 | 361 | | |
| 362 | + | |
343 | 363 | | |
344 | 364 | | |
345 | 365 | | |
| |||
422 | 442 | | |
423 | 443 | | |
424 | 444 | | |
425 | | - | |
| 445 | + | |
426 | 446 | | |
427 | 447 | | |
428 | 448 | | |
| |||
433 | 453 | | |
434 | 454 | | |
435 | 455 | | |
436 | | - | |
| 456 | + | |
437 | 457 | | |
438 | 458 | | |
439 | 459 | | |
| |||
484 | 504 | | |
485 | 505 | | |
486 | 506 | | |
487 | | - | |
| 507 | + | |
488 | 508 | | |
489 | 509 | | |
490 | 510 | | |
491 | 511 | | |
492 | 512 | | |
493 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
494 | 518 | | |
495 | 519 | | |
496 | 520 | | |
| |||
0 commit comments