scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

polymorphic macros declared in structural types don't pass correct type tags to their impls #7736

Open scabug opened 11 years ago

scabug commented 11 years ago
scala> def impl[A: c.WeakTypeTag, B: c.WeakTypeTag](c: Context) = { println(c.weakTypeTag[A]); println(c.weakTypeTag[B]); c.literalUnit }
impl: [A, B](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[A], implicit evidence$2: c.WeakTypeTag[B])c.Expr[Unit]

scala> def foo[A] = new { def bar[B] = macro impl[A, B] }
foo: [A]=> AnyRef{def bar[B]: Unit}

scala> foo[Int].bar[Double]
WeakTypeTag[A]
WeakTypeTag[B] 
scabug commented 11 years ago

Imported From: https://issues.scala-lang.org/browse/SI-7736?orig=1 Reporter: @xeno-by Affected Versions: 2.10.2, 2.11.0-M4

scabug commented 11 years ago

@xeno-by said: Btw as a workaround one can always inspect c.macroApplication and extract the type args manually.

scabug commented 11 years ago

@xeno-by said:

import scala.language.experimental.macros
import scala.reflect.macros.Context

object Macros {
  def impl[A: c.WeakTypeTag, B: c.WeakTypeTag](c: Context) = {
    println(c.weakTypeTag[A])
    println(c.weakTypeTag[B])
    c.literalUnit
  }
}
import scala.language.experimental.macros
import scala.language.reflectiveCalls

object Test extends App {
  def foo[A] = new { def bar[B] = macro Macros.impl[A, B] }
  foo[Int].bar[Double]
}
21:58 ~/Projects/210x/sandbox (2.10.x)$ sst -uniqid -Yshow-symkinds
WeakTypeTag[A#7080#TPE]
WeakTypeTag[B#11936#TPE]
[[syntax trees at end of                     typer]] // Test.scala
package <empty>#4#PK {
  import scala#20#PK.language#861#MOD.experimental#6997#MOD.macros;
  import scala#20#PK.language#861#MOD.reflectiveCalls;
  object Test#6978#MOD extends AnyRef#2169#TPE with App#35#TRT {
    def <init>#7078#PCTOR(): Test#6979#MODC.type = {
      Test#6979#MODC.super.<init>#4691#PCTOR();
      ()
    };
    def foo#7079#METH[A#7080#TPE >: Nothing#3304#CLS <: Any#3303#CLS]: AnyRef#2169#TPE{def bar#16748#MAC[B#16749#TPE]: Unit#1595#CLS} = {
      final class $anon#11933#AC extends scala#20#PK.AnyRef#2169#TPE {
        def <init>#11934#PCTOR(): anonymous class $anon#11933#AC = {
          $anon#11933#AC.super.<init>#4691#PCTOR();
          ()
        };
        @scala#21#PK.reflect#1622#PK.macros#2309#PK.internal#16551#PK.macroImpl#16732#CLS(`macro`("versionFormat" = 1, "className" = "Macros", "methodName" = "impl", "signature" = List#10952#MOD(-1, 0, 1))[A#7081#TPE#SKO, B#11937#TPE#SKO]) <macro> def bar#11935#MAC[B#11936#TPE >: Nothing#3304#CLS <: Any#3303#CLS]: Unit#1595#CLS = Macros#6974#MOD.impl#16439#METH[A#7081#TPE#SKO, B#11937#TPE#SKO]
      };
      new $anon#11933#AC()
    };
    ()
  }
}