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

Nested anonymous functions fail to compile on 2.11 #22

Open
non opened this issue Jul 18, 2019 · 0 comments
Open

Nested anonymous functions fail to compile on 2.11 #22

non opened this issue Jul 18, 2019 · 0 comments

Comments

@non
Copy link
Contributor

non commented Jul 18, 2019

I noticed that certain kinds of expressions seem to cause problems under 2.11:

val xs = List(1,2,3,4)
val prop0 = Claim(xs.flatMap(x => List(x).filter(_ => false)) == Nil)

If you compile under 2.12 or 2.13, things are fine. But if you compile for 2.11, the macro does run and produces a tree, but the compiler crashes in a later phase:

[error] scala.reflect.internal.Types$TypeError: value <none> is not a member of scala.runtime.AbstractFunction0[org.sca
lacheck.Prop] with Serializable
[error]         at scala.tools.nsc.typechecker.Contexts$ThrowingReporter.handleError(Contexts.scala:1402)
[error]         at scala.tools.nsc.typechecker.Contexts$ContextReporter.issue(Contexts.scala:1254)
[error]         at scala.tools.nsc.typechecker.Contexts$Context.issue(Contexts.scala:573)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.reportError$2(Typers.scala:4512)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.onError$3(Typers.scala:4556)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4581)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4608)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5370)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5387)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5423)
[error]         at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typ
ers.scala:5450)

< stack trace continues for many lines >

However, these two very similar expressions both works fine under 2.11:

val xs = List(1,2,3,4)

val p = (x: Int) => false
val prop1 = Claim(xs.flatMap(x => List(x).filter(p)) == Nil)

val f = (x: Int) => List(x).filter(_ => false)
val prop2 = Claim(xs.flatMap(f))

I spent some time trying to track this down. As far as I can tell it's a bug with quasiquoting, which we're using heavily to take trees apart and put them back together. The problem occurs when constructing the label, which can be as simple as q"($tree).toString" while still having problems.

It's possible we will be able to change the code so this works in 2.11, but I've exhausted my budget for looking into this. The current work-arounds are either to refactor your code as above, or just build a Prop directly without a label:

val prop3 = Prop(xs.flatMap(x => List(x).filter(_ => false)) == Nil)

I'm planning to add a test to track this, to make it easy for me (or others) to pick this up later.

non pushed a commit that referenced this issue Jul 18, 2019
non added a commit that referenced this issue Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant