Skip to content

Problem with conditionals in inline matches  #13570

Closed
@DavidGoodenough

Description

@DavidGoodenough

Compiler version

3.02 and 3.1.0-RC1

Minimized code

object Fred {
  inline def jim(seq:Seq[Int]) = {
    inline seq match { // If this is not inline, this code works as expected, with the inline it fails as below
      case s:Seq[Int] if s.isEmpty => println("seq is empty")
      case s:Seq[Int] => println("seq is not empty")
      case _ => println("somthing hinky happened")
      }
    }
  def main(args:Array[String]):Unit = {
    Fred.jim(Seq())
    Fred.jim(Seq(1,2))
    }
  }

Output

seq is not empty
seq is not empty

Expectation

seq is empty
seq is not empty

Discussion

I am unsure whether the compiler is supposed to be able to evaluate this kind of match at compile time (which is after all when an inline match in an inline def is evaluated), so either the compiler should reject this as something that can only be be done in a runtime (i.e. non-inline) match, or it should produce the expected result.

If the inline on the match is removed, this code works as expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions