Skip to content

Merge 2.10.x to master (plus a test) #92

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

Merged
merged 3 commits into from
Oct 2, 2014

Conversation

retronym
Copy link
Member

@retronym retronym commented Oct 1, 2014

Review by @phaller

`TreeGen#mkZero` returns `q"null"` for derived value classes.

```
scala> class V(val a: String) extends AnyVal
defined class V

scala> showRaw(gen.mkZero(typeOf[V]))
res0: String = Literal(Constant(null))
```

We use this API in async to generate the initial value for
ANF-lifted temporary variables.

However, this leads to NPEs, as after posterasure, we call the
unbox method on a null reference:

```
% cat sandbox/Macro.scala; scalac-hash v2.10.4 sandbox/Macro.scala; scala-hash v2.10.4 -e 'val x = Macros.myMacro'
import scala.reflect.macros.Context
import scala.language.experimental.macros

object Macros {
  def macroImpl(c: Context): c.Expr[C] = {
    import c.universe._
    val e1 = c.Expr[C](Literal(Constant(null)).setType(typeOf[C]))
    reify(e1.splice.asInstanceOf[C @annotation.unchecked.uncheckedVariance])
  }

  def myMacro: C = macro macroImpl
}

class C(val a: String) extends AnyVal
java.lang.NullPointerException
	at Main$$anon$1.<init>(scalacmd4059893593754060829.scala:1)
	at Main$.main(scalacmd4059893593754060829.scala:1)
	at Main.main(scalacmd4059893593754060829.scala)
```

This commit installs a custom version of `mkZero` that instead
returns `q"new C[$..targs](${mkZero(wrappedType)})`.

Thanks to @ewiner for pinpointing the problem.
Conflicts:
	src/main/scala/scala/async/internal/AnfTransform.scala
	src/main/scala/scala/async/internal/AsyncTransform.scala
	src/test/scala/scala/async/run/toughtype/ToughType.scala
@retronym
Copy link
Member Author

retronym commented Oct 2, 2014

I'm going to merge this one now as I'm ready to cut the next release. Post hoc review still welcome.

retronym added a commit that referenced this pull request Oct 2, 2014
@retronym retronym merged commit 38416ae into scala:master Oct 2, 2014
@phaller
Copy link
Contributor

phaller commented Oct 3, 2014

LGTM

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

Successfully merging this pull request may close these issues.

2 participants