scala / bug

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

some methods of Symbol don't work correctly unless the symbol is initialized #6277

Closed scabug closed 12 years ago

scabug commented 12 years ago

It seems isSealed is not working at runtime. At least, it doesn't work for List:


Welcome to Scala version 2.11.0-20120808-025516-c0d5f0aadd (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import reflect.runtime.universe._
import reflect.runtime.universe._

scala> typeOf[List]
<console>:11: error: type List takes type parameters
              typeOf[List]
                     ^

scala> typeOf[List[_]]
res1: reflect.runtime.universe.Type = scala.List[_]

scala> res1.type
typeConstructor   typeSymbol        

scala> res1.typeSymbol
res2: reflect.runtime.universe.Symbol = class List

scala> res2.asClass
res3: reflect.runtime.universe.ClassSymbol = class List

scala> res3.isSealed
res4: Boolean = false

upd. This also plagues annotation-getting methods as described in #6428. In the interest of full disclosure, I should mention that privateWithin is also affected.

scabug commented 12 years ago

Imported From: https://issues.scala-lang.org/browse/SI-6277?orig=1 Reporter: @dcsobral Affected Versions: 2.10.0-M6, 2.10.0-M7, 2.10.0 Other Milestones: 2.10.0

scabug commented 12 years ago

@paulp said: I don't know how to deliver this bit of news, other than to say that I hope you're impressed at the few things we do manage to fix in such a hostile environment. That we are on the verge of exporting this behavior into userland is not something I can bear to consider.

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> val sym = typeOf[scala.collection.immutable.List[_]].typeSymbol.asClass
sym: reflect.runtime.universe.ClassSymbol = class List

scala> sym.isSealed
res0: Boolean = false

scala> { sym.typeSignature ; () }

scala> sym.isSealed
res2: Boolean = true
scabug commented 12 years ago

@dcsobral said: And here was I saying Symbols were immutable at runtime (despite your presentation -- Eugene was very emphatic on them being immutable at runtime, when he reviewed my blog post saying otherwise).

Other than that, I've been impressed for a long time, and I think you understate the case when you say "few".

scabug commented 12 years ago

@odersky said: I think this is important to fix before 2.10 RC1: Any flags tests need to make sure the symbol is fully loaded when called from reflection, and the flags method needs to do the same. However, in the compiler we must not change behavior. Maybe this means we need to find different names for the exposed flag testing methods.

scabug commented 12 years ago

@xeno-by said: Okay I'm on it. Sorry for neglecting this issue yesterday - I'm in the middle of an exam prep. Also Daniel I'm sorry about misinforming you.

scabug commented 12 years ago

@xeno-by said: @odersky. I suggest we mix the auto-initialization logic into runtime reflection Symbols in the same way we mix in SynchronizedSymbol. This way we'll also get rid of the ugliness of the annotation/getAnnotation dilemma.

scabug commented 12 years ago

@heathermiller said: Scala core meeting consensus: go with Eugene's suggestion

scabug commented 12 years ago

@odersky said: @xeno.by yes, I think this is the way to go. Can you do it?

scabug commented 12 years ago

@xeno-by said: Sure, I will submit a pull request within a week.

scabug commented 12 years ago

@xeno-by said: https://github.com/scala/scala/pull/1264

scabug commented 12 years ago

@jsuereth said: pull request was dropped.

scabug commented 12 years ago

@xeno-by said: https://github.com/scala/scala/pull/1380

scabug commented 12 years ago

@xeno-by said: https://github.com/scala/scala/commit/2fb507b849e2b0f86c2480bde95200f8ae30803d