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

dealias is not working for Predef.String #9323

Open
scabug opened this issue May 22, 2015 · 9 comments
Open

dealias is not working for Predef.String #9323

scabug opened this issue May 22, 2015 · 9 comments
Labels
dealias compiler isn't dealiasing when it should, or vice versa reflection
Milestone

Comments

@scabug
Copy link

scabug commented May 22, 2015

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
Copy link
Author

scabug commented May 22, 2015

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

@scabug
Copy link
Author

scabug commented May 22, 2015

@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
Copy link
Author

scabug commented May 22, 2015

@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
Copy link
Author

scabug commented May 25, 2015

@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
Copy link
Author

scabug commented Jun 1, 2015

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
Copy link
Author

scabug commented Jun 1, 2015

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
Copy link
Author

scabug commented Jun 1, 2015

@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
Copy link
Author

scabug commented Jun 2, 2015

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
Copy link
Author

scabug commented Jun 2, 2015

@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

@SethTisue SethTisue added the dealias compiler isn't dealiasing when it should, or vice versa label Nov 11, 2020
@SethTisue SethTisue added this to the Backlog milestone Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dealias compiler isn't dealiasing when it should, or vice versa reflection
Projects
None yet
Development

No branches or pull requests

3 participants