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

Typechecking a generic method leads to inconsistent parameter symbols #9972

Closed
scabug opened this issue Oct 19, 2016 · 4 comments
Closed

Typechecking a generic method leads to inconsistent parameter symbols #9972

scabug opened this issue Oct 19, 2016 · 4 comments

Comments

@scabug
Copy link

scabug commented Oct 19, 2016

Minimal example to reproduce:

import scala.reflect.runtime.universe._
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox

object Test {

  def main(args: Array[String]) {
    val tb = currentMirror.mkToolBox()
    
    val id1 = tb.typecheck(q"def id(x: Int) = x").asInstanceOf[DefDef]
    val x1 = id1.symbol.asMethod.paramLists.head.head
    val x2 = id1.vparamss.head.head.symbol
    println(x1 == x2) // true
    
    val id2 = tb.typecheck(q"def id[A](x: A) = x").asInstanceOf[DefDef]
    val x3 = id2.symbol.asMethod.paramLists.head.head
    val x4 = id2.vparamss.head.head.symbol
    println(x3 == x4) // false
    val A1 = id2.symbol.asMethod.typeParams.head
    val A2 = id2.tparams.head.symbol
    println(A1 == A2) // false
  }
}

The same behavior can be observed when typechecking in macro context.

@scabug
Copy link
Author

scabug commented Oct 19, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9972?orig=1
Reporter: Georgi Krastev (gkrastev)
Affected Versions: 2.11.8, 2.12.0-RC2

@scabug
Copy link
Author

scabug commented Oct 19, 2016

@adriaanm said:
This is surprising, but not a bug as far as I can see.
You can't compare different MethodTypes like that. The symbols used for the parameters are only in scope inside the same method type. For a generic method, the convenience methods to get parameter symbols must first go under the polytype's binder,
which means creating a new method type.

@scabug
Copy link
Author

scabug commented Oct 19, 2016

Georgi Krastev (gkrastev) said:
Is there a workaround, having the MethodSymbol to arrive at the parameter symbols used in the definition?

@scabug
Copy link
Author

scabug commented Oct 19, 2016

@adriaanm said:
I'm afraid I'm not aware of one. Can you get a hold of the DefDef? It has the trees that represent the arguments and their symbols. Since this is not a bug, I'm going to close this ticket. Feel free to ask follow-up questions at https://gitter.im/scala/scala

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