Skip to content

Optional braces not allowed for pattern match guard #11444

Closed
@tgodzik

Description

@tgodzik

Compiler version

3.0.0-RC1

Minimized code

  1 match {
     case a if 
         val b = 11
         a < b =>
       a
  } 

Output

[info] compiling 1 Scala source to /home/tgodzik/Documents/workspaces/dotty-vinz/target/scala-3.0.0-M4/classes ...
[error] -- [E018] Syntax Error: /home/tgodzik/Documents/workspaces/dotty-vinz/src/main/scala/Main.scala:18:14 
[error] 18 |     case a if 
[error]    |              ^
[error]    |              expression expected but val found
[error] -- [E007] Type Mismatch Error: /home/tgodzik/Documents/workspaces/dotty-vinz/src/main/scala/Main.scala:18:11 
[error] 18 |     case a if 
[error]    |           ^
[error]    |           Found:    Null
[error]    |           Required: Boolean
[error] two errors found
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Feb 17, 2021 5:29:10 PM

Expectation

Compiles succesfully.

It seems this works in both normal ifs and if in for comprehensions, so this seems a bit of an inconsistency.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions