You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scala code runner version 3.1.3-RC1-bin-SNAPSHOT-git-aa59abe -- Copyright 2002-2022, LAMP/EPFL
Minimized code
importscala.util.chaining.givenclassC:defop:Unit=thrownewRuntimeException("a").tap(_ => println("throw a"))
defhandler:Unit=thrownewRuntimeException("b").tap(_ => println("throw b"))
deftest:Unit=try op
catchcase_: NullPointerException=>
handler
endtestdeftest1:Unit=try op
//catch case _: NullPointerException =>catchcase_: NullPointerException=> end try
handler
endtest1@main deftest() = println {
valc=newC()
c.test
//c.test1
}
Compilation output
deftest:Unit=try op catch {
{
case _:NullPointerException=> handler
}
}
deftest1:Unit=
{
try op catch {
{
case _:NullPointerException=>
<empty>
}
}
handler
}
Expectation
In test, the call to handler is in the case, as opposed to following it as in test1.
This is probably because ExprCaseClause must consume an Expr.
The single line catch case in test1 is not allowed with an empty body before end try.
That may be a feature, but the doc for new control syntax says it must "follow on a single line"; maybe that wording just needs to be tweaked to say "start on the same line".
However, it's also very confusing to read. It doesn't conform to intuitions acquired from optional braces (which doesn't govern this syntax). Normally, the aligned token that is not case incurs the outdent. (And now I see that is not only when the case is aligned with match.)
deff(x: Int):Int=
x matchcase1=>
println("no") ; 42case _ =>27
I love single line catch case quiet syntax, but would love it more on a single line.
Sample in the wild where it's not obvious what was intended.
The text was updated successfully, but these errors were encountered:
Compiler version
Scala code runner version 3.1.3-RC1-bin-SNAPSHOT-git-aa59abe -- Copyright 2002-2022, LAMP/EPFL
Minimized code
Compilation output
Expectation
In
test
, the call tohandler
is in thecase
, as opposed to following it as intest1
.This is probably because
ExprCaseClause
must consume anExpr
.The single line
catch case
intest1
is not allowed with an empty body beforeend try
.That may be a feature, but the doc for new control syntax says it must "follow on a single line"; maybe that wording just needs to be tweaked to say "start on the same line".
However, it's also very confusing to read. It doesn't conform to intuitions acquired from optional braces (which doesn't govern this syntax). Normally, the aligned token that is not
case
incurs the outdent. (And now I see that is not only when thecase
is aligned withmatch
.)I love single line
catch case
quiet syntax, but would love it more on a single line.Sample in the wild where it's not obvious what was intended.
The text was updated successfully, but these errors were encountered: