Open scabug opened 9 years ago
Imported From: https://issues.scala-lang.org/browse/SI-9323?orig=1 Reporter: Zhu, Chenye (maxcellent) Affected Versions: 2.11.5
@som-snytt said: Out of curiosity:
scala> import reflect.runtime._,universe._
import reflect.runtime._
import universe._
scala> typeOf[String] == typeOf[java.lang.String]
res0: Boolean = false
scala> typeOf[String].dealias == typeOf[java.lang.String]
res1: Boolean = true
@adriaanm said: +1, dealias is not broken, type.toString is. In any case, I do not recommend using == for type comparison. It's faster for a reason (not accurate).
@retronym said: The root difficulty is the way that runtime reflection can have more than one package symbol for a given package (one for each distinct classloader).
https://gist.github.com/retronym/0440cd94f6b531d0e5a0
If you need performance, you can use ==
as a first attempt, but you'll need to fall back to =:=
to be sure.
Zhu, Chenye (maxcellent) said: @A. P. Marki which Scala version are you using? I can not reproduce in my REPL.
scala> import scala.reflect.runtime.{universe => ru} import scala.reflect.runtime.{universe=>ru}
scala> ru.typeOf[String].dealias == ru.typeOf[java.lang.String] res1: Boolean = false
Zhu, Chenye (maxcellent) said: I cannot reproduce what @A.P. Marki said, under Scala 2.11.5.
Would you please indicated the fixed version? If this is already fixed.
@som-snytt said: Odd-numbered point releases have weird bugs requiring manual confirmation:
$ scala
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.reflect.runtime.{ universe => ru }
import scala.reflect.runtime.{universe=>ru}
scala> ru.typeOf[String].dealias == ru.typeOf[java.lang.String]
res0: Boolean = true
scala> :quit
$ ./scala-2.11.5/bin/scala
Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.reflect.runtime.{ universe => ru }
import scala.reflect.runtime.{universe=>ru}
scala> ru.typeOf[String].dealias == ru.typeOf[java.lang.String]
res0: Boolean = true
Maybe verify your platform and classpath etc.
Zhu, Chenye (maxcellent) said: FYI this is what I have tried so far. No luck
Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.reflect.runtime.{universe => ru}
import scala.reflect.runtime.{universe=>ru}
scala> ru.typeOf[String].dealias == ru.typeOf[java.lang.String]
res0: Boolean = false
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.reflect.runtime.{universe => ru}
import scala.reflect.runtime.{universe=>ru}
scala> ru.typeOf[String].dealias == ru.typeOf[java.lang.String]
res0: Boolean = false
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_40).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.reflect.runtime.{universe => ru}
import scala.reflect.runtime.{universe=>ru}
scala> ru.typeOf[String].dealias == ru.typeOf[java.lang.String]
res0: Boolean = false
@mpociecha said (edited on Jun 2, 2015 9:39:10 AM UTC): FYI
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\michal>scala
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51). // also tested with 1.8.0_45
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
import reflect.runtime._,universe._
import reflect.runtime._
import universe._
// Exiting paste mode, now interpreting.
import reflect.runtime._
import universe._
import reflect.runtime._
import universe._
scala> typeOf[String] == typeOf[java.lang.String]
res2: Boolean = false
scala> typeOf[String].dealias == typeOf[java.lang.String]
res3: Boolean = false
I am not sure if this is only Predef.String. There may be other classes having the same issue.
This bug means we have to always use =:=, instead of == on dealiased type directly, which is really slow
=============================================