Strange behaviour in repl when using fewerBraces, first it does not work then it does
See original GitHub issueCompiler version
Scala 3.1.3-RC1-bin-SNAPSHOT-nonbootstrapped-git-ccd39b7
using repl
in sbt
from current dotty repo.
Minimized code and output
Welcome to Scala 3.1.3-RC1-bin-SNAPSHOT-nonbootstrapped-git-ccd39b7 (11.0.13, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> import language.experimental.fewerBraces
scala> Seq(1,2,3).apply: // press Alt+Enter to get new line
| 1
-- Error: ----------- // this should work and not give this error
1 |Seq(1,2,3).apply:
|^^^^^^^^^^^^^^^^
|missing arguments for method apply in trait SeqOps
1 error found
scala> Seq(1,2,3).apply: // don't press Alt+Enter
val res0: Int => Int = Lambda$14686/0x000000080384a040@44471878
scala> Seq(1,2,3).apply: // press Alt+Enter to get new line
| 1
|
val res1: Int = 2 // now it suddenly works as should
scala>
Expectation
The first try above should work. Now it first does not work as expected; then it starts working after creating the first lambda by providing an empty arg.
Maybe it is cased by some kind of jline parsing issue?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
fewerBraces allows empty indentation region #13097 - GitHub
Expect it to require a block expr and not happily eta-expand. ... Strange behaviour in repl when using fewerBraces, first it does not...
Read more >This is definitely a strange p... - Replit
Hrmm...that sounds like a distinct possibility. I had that problem with Sublime and found that Repl.it handled the same code that erred out...
Read more >On braces and indentation-based syntax - Scala Contributors
My vote and prayer to the coding God is that indenting lords over noisy braces. Fix it and make it consistent everywhere, no...
Read more >Scala 3: Even Fewer Braces - Medium
This makes it easier to compare the differences. First, here is an examplemethod that takes a function argument, which takes no arguments: def ......
Read more >Optional Braces - Scala 3 - EPFL
First, some badly indented programs are flagged with warnings. ... Generally, the rule is that adding a pair of optional braces will not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, the issue has to do with how import statements from previous REPL lines are brought into the compiler context.
This happens here:
https://github.com/lampepfl/dotty/blob/1476a30b7949d2078aa6ff6660b54774cdeb2f00/compiler/src/dotty/tools/repl/ReplCompiler.scala#L41-L66
where the user defined imports from previous lines are folded into the rootContext for the new compiler run.
However, the REPL is special in that the Parser is run standalone rather than as part of the frontend phases of the compiler, which in turn means that the REPL parser is not seeing an up-to-date context since the next run of the compiler has not yet started.
The issue does not manifest in the example above because the import is brought into context during compilation of the line containing “hello”. Indeed the issue is only present when the code on the REPL line immediately following the fewerBraces import requires fewerBraces to be enabled.
The issue does not manifest if fewer braces support is enabled by starting the REPL with the
-language:experimental.fewerBraces
command line option rather than using the import during the REPL session. Which leads me to suspect that the compiler context is not being (fully) updated upon first seeing the import statement.