scala / bug

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

Type check in macros should not yield an unchecked warning when the corresponding AbsTypeTag is in scope #6531

Open scabug opened 12 years ago

scabug commented 12 years ago

Type check in macros should not yield an unchecked warning (caused by erasure) when the corresponding AbsTypeTag is in scope:

def test[A, B](a: A, b: B): A = macro test_impl[A,B]

def test_impl[A: c.AbsTypeTag, B](c: Context)(a: c.Expr[A], b: c.Expr[B]): c.Expr[A] = {
    import c.universe._
    reify {
      b.splice match {
        case bb: A => bb 
        case _ => a.splice
      }
    }
  }

Leads to the following compiler warning:

[warn] /home/dk/macropolis/src/main/scala/macropolis/Equalizer.scala:16: abstract type A in type pattern A is unchecked since it is eliminated by erasure
[warn]         case bb:A => bb
[warn]      

Comment by Eugene [1]:

That's a limitation of the typecheck, and I invite you to submit a bug about it. The thing is that the reifee (the body of the reify call) is: 1) typechecked and, 2) only then reified. The typechecker from the step 1 doesn't know anything about reification and, in particular, doesn't know that T isn't just an abstract type, but is going to be spliced later.

[1] https://groups.google.com/d/msg/scala-user/alYUId3YmuY/rr9WSuAGjwQJ

scabug commented 12 years ago

Imported From: https://issues.scala-lang.org/browse/SI-6531?orig=1 Reporter: daniel kroeni (dk) Affected Versions: 2.10.0-M7