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

Reflection: isVariable returns wrong result on a var field #5889

Closed
scabug opened this issue Jun 6, 2012 · 4 comments
Closed

Reflection: isVariable returns wrong result on a var field #5889

scabug opened this issue Jun 6, 2012 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jun 6, 2012

Consider the following example:

import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
	
class A {
  var x: Int = 42
}

val a = new A

val im: InstanceMirror = cm.reflect(a)
val cs = im.reflectClass.symbol
val f = cs.typeSignature.declaration(newTermName("x")).asTermSymbol
val fm: FieldMirror = im.reflectField(f) 
fm.field.isVariable

The last expression returns false:

scala> fm.field.isVariable
res0: Boolean = false

I expected that it returns true, according to the documentation:

/** Does this symbol represent a mutable value?
  * If yes, `isTerm` and `isValue` are also guaranteed to be true.
  */
def isVariable: Boolean

The MUTABLE-Flag is also not set (which is consistent with the above result)

scala> fm.field.flags.containsAll(Flag.MUTABLE)
res174: Boolean = false
@scabug
Copy link
Author

scabug commented Jun 6, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5889?orig=1
Reporter: @dgruntz
Affected Versions: 2.10.0

@scabug
Copy link
Author

scabug commented Jun 6, 2012

@xeno-by said:
scala> fm.field.isMethod
res1 @ 3796a671: Boolean = true

I think, this is the problem.

@scabug
Copy link
Author

scabug commented Jun 7, 2012

@xeno-by said:
Changing newTermName("x") to newTermName("x ") solves the problem (yes, "x " as in "x with a whitespace").

@scabug
Copy link
Author

scabug commented Jun 7, 2012

@xeno-by said:
Superceded by #5895.

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