Skip to content

Commit

Permalink
Add regression test for #19087 (#19726)
Browse files Browse the repository at this point in the history
Fixes #19087
  • Loading branch information
mbovel authored Feb 19, 2024
1 parent c3a1959 commit 69170d3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/neg/19087.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- [E103] Syntax Error: tests/neg/19087.scala:4:2 ----------------------------------------------------------------------
4 | Option.when(state.x == 0) body // error: Illegal start of toplevel definition
| ^^^^^^
| Illegal start of toplevel definition
|
| longer explanation available when compiling with `-explain`
-- [E040] Syntax Error: tests/neg/19087.scala:15:6 ---------------------------------------------------------------------
15 | bar = 2 // error: ',' or ')' expected
| ^^^
| ',' or ')' expected, but identifier found
-- [E067] Syntax Error: tests/neg/19087.scala:3:4 ----------------------------------------------------------------------
3 |def foo[T](state: State)(body: => T): Option[T] // error: only classes can have declared but undefined members
| ^
| Declaration of method foo not allowed here: only classes can have declared but undefined members
-- [E050] Type Error: tests/neg/19087.scala:13:22 ----------------------------------------------------------------------
13 | foo(state.copy(x = 5): // Missing ")" // error: method copy in class State does not take more parameters
| ^^^^^^^^^^^^^^^^^
| method copy in class State does not take more parameters
|
| longer explanation available when compiling with `-explain`
15 changes: 15 additions & 0 deletions tests/neg/19087.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
case class State(x: Int)

def foo[T](state: State)(body: => T): Option[T] // error: only classes can have declared but undefined members
Option.when(state.x == 0) body // error: Illegal start of toplevel definition

var bar = 0
val state = State(0)

def app: Function1[Int, Unit] =
new Function1[Int, Unit]:
def apply(x: Int): Unit =
foo(state):
foo(state.copy(x = 5): // Missing ")" // error: method copy in class State does not take more parameters
println("a")
bar = 2 // error: ',' or ')' expected

0 comments on commit 69170d3

Please sign in to comment.