scala / bug

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

dealias is not working for Predef.String #9323

Open scabug opened 9 years ago

scabug commented 9 years ago

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

=============================================

scala> import scala.reflect.runtime.{universe => ru}
import scala.reflect.runtime.{universe=>ru}

scala> ru.typeOf[Map[String, Int]].dealias   // this works
res0: reflect.runtime.universe.Type = scala.collection.immutable.Map[String,Int]

scala> ru.typeOf[String].dealias   // expecting java.lang.String after dealiased
res1: reflect.runtime.universe.Type = String
scabug commented 9 years ago

Imported From: https://issues.scala-lang.org/browse/SI-9323?orig=1 Reporter: Zhu, Chenye (maxcellent) Affected Versions: 2.11.5

scabug commented 9 years ago

@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
scabug commented 9 years ago

@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).

scabug commented 9 years ago

@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.

scabug commented 9 years ago

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

scabug commented 9 years ago

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.

scabug commented 9 years ago

@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.

scabug commented 9 years ago

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
scabug commented 9 years ago

@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