From 69170d3260a4f5989b63527192b245e4c57d8c3e Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 19 Feb 2024 14:12:12 +0100 Subject: [PATCH] Add regression test for #19087 (#19726) Fixes #19087 --- tests/neg/19087.check | 20 ++++++++++++++++++++ tests/neg/19087.scala | 15 +++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/neg/19087.check create mode 100644 tests/neg/19087.scala diff --git a/tests/neg/19087.check b/tests/neg/19087.check new file mode 100644 index 000000000000..db6da907205d --- /dev/null +++ b/tests/neg/19087.check @@ -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` diff --git a/tests/neg/19087.scala b/tests/neg/19087.scala new file mode 100644 index 000000000000..b52dddcad651 --- /dev/null +++ b/tests/neg/19087.scala @@ -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