Skip to content

Commit c266bee

Browse files
mbovelWojciechMazur
authored andcommitted
Add regression test for #19087 (#19726)
Fixes #19087 [Cherry-picked 69170d3]
1 parent 0c3717f commit c266bee

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/neg/19087.check

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- [E103] Syntax Error: tests/neg/19087.scala:4:2 ----------------------------------------------------------------------
2+
4 | Option.when(state.x == 0) body // error: Illegal start of toplevel definition
3+
| ^^^^^^
4+
| Illegal start of toplevel definition
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E040] Syntax Error: tests/neg/19087.scala:15:6 ---------------------------------------------------------------------
8+
15 | bar = 2 // error: ',' or ')' expected
9+
| ^^^
10+
| ',' or ')' expected, but identifier found
11+
-- [E067] Syntax Error: tests/neg/19087.scala:3:4 ----------------------------------------------------------------------
12+
3 |def foo[T](state: State)(body: => T): Option[T] // error: only classes can have declared but undefined members
13+
| ^
14+
| Declaration of method foo not allowed here: only classes can have declared but undefined members
15+
-- [E050] Type Error: tests/neg/19087.scala:13:22 ----------------------------------------------------------------------
16+
13 | foo(state.copy(x = 5): // Missing ")" // error: method copy in class State does not take more parameters
17+
| ^^^^^^^^^^^^^^^^^
18+
| method copy in class State does not take more parameters
19+
|
20+
| longer explanation available when compiling with `-explain`

tests/neg/19087.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
case class State(x: Int)
2+
3+
def foo[T](state: State)(body: => T): Option[T] // error: only classes can have declared but undefined members
4+
Option.when(state.x == 0) body // error: Illegal start of toplevel definition
5+
6+
var bar = 0
7+
val state = State(0)
8+
9+
def app: Function1[Int, Unit] =
10+
new Function1[Int, Unit]:
11+
def apply(x: Int): Unit =
12+
foo(state):
13+
foo(state.copy(x = 5): // Missing ")" // error: method copy in class State does not take more parameters
14+
println("a")
15+
bar = 2 // error: ',' or ')' expected

0 commit comments

Comments
 (0)