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

Reify and path-dependent types #6591

Closed
scabug opened this issue Oct 30, 2012 · 8 comments
Closed

Reify and path-dependent types #6591

scabug opened this issue Oct 30, 2012 · 8 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 30, 2012

Given these data types:

trait Outer {
  trait Inner[T]
  def make[T](t: T): Inner[T] = ???
}
object Def extends Outer

the following shows that inside reify, Def.Inner is treated as Outer.this.Inner, causing a type mismatch.

Macro implementation:

import language.experimental.macros
import scala.reflect.macros._

import Def.Inner
object Test {
  def id[T](t: Inner[T]): Inner[T] = macro idImpl[T]

  def idImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[Inner[T]]): c.Expr[Inner[T]] =
    c.universe.reify {
      val v: Def.Inner[T] = t.splice
      v
    }
}

Macro usage:

object Use {
  val y = Test.id(Def.make(3))
}

The type mismatch error generated when compiling Use is below. The mismatch is from the first line of the reify block.

Use.scala:2: error: type mismatch;
 found   : Def.Inner[Int]
 required: Outer.this.Inner[Int]

        val y = Test.id(Def.make(3))
                                ^
Use.scala:2: error: type mismatch;
 found   : Outer.this.Inner[Int]
 required: Def.Inner[Int]

        val y = Test.id(Def.make(3))
                       ^
two errors found
@scabug
Copy link
Author

scabug commented Oct 30, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6591?orig=1
Reporter: @harrah
Affected Versions: 2.10.0-RC1, 2.11.0-M1

@scabug
Copy link
Author

scabug commented Oct 30, 2012

@xeno-by said:
Luckily, this isn't a fundamental problem as I feared. It's just an oversight in the reifier.

The problem is that when reifyBoundType in GenTrees.scala sees a Select(_, _), it happily assumes that it's enough to just reify the underlying symbol and wrap it in a Ident.

@scabug
Copy link
Author

scabug commented Oct 30, 2012

@jsuereth said:
Eugene - Do you think we can get a fix for this by 2.10.1?

@scabug
Copy link
Author

scabug commented Nov 7, 2012

@xeno-by said:
Sorry Josh, missed this comment. Yes we definitely can.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@xeno-by said:
This bug is being fixed

@scabug
Copy link
Author

scabug commented Feb 4, 2013

@xeno-by said:
The patch will arrive this Wednesday

@scabug
Copy link
Author

scabug commented Feb 8, 2013

@JamesIry said:
scala/scala#2072

@scabug
Copy link
Author

scabug commented Feb 8, 2013

@JamesIry said:
superseded by scala/scala#2094

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

No branches or pull requests

2 participants