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

Add regression test for #19087 #19726

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading