Skip to content

Problem with conditionals in inline matches #13570

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

Closed
DavidGoodenough opened this issue Sep 21, 2021 · 0 comments · Fixed by #13601
Closed

Problem with conditionals in inline matches #13570

DavidGoodenough opened this issue Sep 21, 2021 · 0 comments · Fixed by #13601
Assignees
Milestone

Comments

@DavidGoodenough
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants