Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fewerBraces allows empty indentation region #13097

Closed
som-snytt opened this issue Jul 18, 2021 · 4 comments
Closed

fewerBraces allows empty indentation region #13097

som-snytt opened this issue Jul 18, 2021 · 4 comments

Comments

@som-snytt
Copy link
Contributor

As originally noted by Scala book author @cayhorstmann on gitter, the fewer braces variant is circulating in the population.

Compiler version

3.0.3-RC1

Minimized code

~/projects/dotty/bin/scala -language:experimental.fewerBraces
scala> List(42).foreach:
val res0: (Int => Any) => Unit = Lambda$1372/0x00000008010e8000@17ec5e2a

scala> import util.control.Breaks.*

scala> breakable:
val res1: (=> Unit) => Unit = Lambda$1413/0x00000008010fd208@5a4b8e25

scala> class C:
     | end C
// defined class C

Output

It's not so much the output as the input. I hope REPL would wait for more.

The compiler allows empty indentation:

def f = List(42).foreach:
end f

// package may not be empty, class template may be empty
package p:
  class C:
  end C
end p

Expectation

The def f with empty indentation requires either end f or eof. Expect it to require a block expr and not happily eta-expand.

In REPL, it should work like class C:.

Spec requires a touch-up for the ArgExpr, but feature is still behind a flag.

@dos65
Copy link
Collaborator

dos65 commented Oct 5, 2021

The reason why it's parsed correctly is that COLONEOL is silently consumed by argumentStart() at this line: https://github.com/lampepfl/dotty/blob/eb8773ecbedd32b7f7f6822696f3c3df3cde6930/compiler/src/dotty/tools/dotc/parsing/Parsers.scala#L2298-L2300 and other branches won't match because the next token is EOF.

It seems that it having COLONEOL and EOF in simpleExprRest should lead to parsing error.
Raising it using syntaxErrorOrIncomplete will also fix the issue with REPL.

So expectation is:

val x = List(42).foreach: // error 

@SethTisue
Copy link
Member

SethTisue commented Dec 7, 2021

to add a REPL test that uses a custom compiler flag, it seems we could either:

  • add the test to ReplCompilerTests.scala (the ReplTest class allows passing compiler flags)
    • Tom noticed that we can use ParseResult.isIncomplete to check detection of incomplete input
  • build on top of Implement :settings in the REPL #13982 and use the new :settings command to set -language:experimental.fewerBraces in a transcript in the compiler/test-resources/repl directory (run with scala3-compiler/testOnly *ScriptedTests)

whatevs, either way

UPDATE: oh, but I tried the latter path and it didn't work ("Illegal start of statement"); apparently ReplTest#testScript doesn't support colon-commands. (Which is a yak somebody might want to shave at some point, maybe not us right now...)

@SethTisue
Copy link
Member

SethTisue commented Dec 7, 2021

We looked at this in the spree today. (We = me, @griggt, @gagandeepkalra, @jirid) but only got partway into it. @gagandeepkalra has a wip branch with some tests and a stab at a patch, but it's still very wippy — we don't think we have the right fix yet.

@som-snytt
Copy link
Contributor Author

apparently fixed by #16466
or duplicates #15718 or #16452

Technically, this issue was lodged first, of course, so the others are dupes. Where is my dotty t-shirt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants