Skip to content
This repository was archived by the owner on Apr 19, 2020. It is now read-only.

Commit c7a8172

Browse files
committed
SI-6937 core type tags are no longer referentially unique
Type tag factory used to evaluate the provided type creator in the context of the initial mirror in order to maintain referential equality of instances of standard tags. Unfortunately this evaluation might fail if the mirror provided doesn't contain the classes being referred to. Therefore I think we should avoid evaluating type creators there. Note that failure of evaluation doesn't mean that there's something bad going on. When one creates a type tag, the correct mirror / classloader to interpret that tag in might be unknown (like it happens here). This is okay, and this is exactly what the 2.10.0-M4 refactoring has addressed. Something like `res2.typeTag[A].in(currentMirror)` should be okay.
1 parent 2894db7 commit c7a8172

8 files changed

+63
-59
lines changed

src/reflect/scala/reflect/api/TypeTags.scala

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,7 @@ trait TypeTags { self: Universe =>
221221

222222

223223
def apply[T](mirror1: scala.reflect.api.Mirror[self.type], tpec1: TypeCreator): WeakTypeTag[T] =
224-
tpec1(mirror1) match {
225-
case ByteTpe => WeakTypeTag.Byte.asInstanceOf[WeakTypeTag[T]]
226-
case ShortTpe => WeakTypeTag.Short.asInstanceOf[WeakTypeTag[T]]
227-
case CharTpe => WeakTypeTag.Char.asInstanceOf[WeakTypeTag[T]]
228-
case IntTpe => WeakTypeTag.Int.asInstanceOf[WeakTypeTag[T]]
229-
case LongTpe => WeakTypeTag.Long.asInstanceOf[WeakTypeTag[T]]
230-
case FloatTpe => WeakTypeTag.Float.asInstanceOf[WeakTypeTag[T]]
231-
case DoubleTpe => WeakTypeTag.Double.asInstanceOf[WeakTypeTag[T]]
232-
case BooleanTpe => WeakTypeTag.Boolean.asInstanceOf[WeakTypeTag[T]]
233-
case UnitTpe => WeakTypeTag.Unit.asInstanceOf[WeakTypeTag[T]]
234-
case AnyTpe => WeakTypeTag.Any.asInstanceOf[WeakTypeTag[T]]
235-
case AnyValTpe => WeakTypeTag.AnyVal.asInstanceOf[WeakTypeTag[T]]
236-
case AnyRefTpe => WeakTypeTag.AnyRef.asInstanceOf[WeakTypeTag[T]]
237-
case ObjectTpe => WeakTypeTag.Object.asInstanceOf[WeakTypeTag[T]]
238-
case NothingTpe => WeakTypeTag.Nothing.asInstanceOf[WeakTypeTag[T]]
239-
case NullTpe => WeakTypeTag.Null.asInstanceOf[WeakTypeTag[T]]
240-
case _ => new WeakTypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1)
241-
}
224+
new WeakTypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1)
242225

243226
def unapply[T](ttag: WeakTypeTag[T]): Option[Type] = Some(ttag.tpe)
244227
}
@@ -299,24 +282,7 @@ trait TypeTags { self: Universe =>
299282
val Null: TypeTag[scala.Null] = new PredefTypeTag[scala.Null] (NullTpe, _.TypeTag.Null)
300283

301284
def apply[T](mirror1: scala.reflect.api.Mirror[self.type], tpec1: TypeCreator): TypeTag[T] =
302-
tpec1(mirror1) match {
303-
case ByteTpe => TypeTag.Byte.asInstanceOf[TypeTag[T]]
304-
case ShortTpe => TypeTag.Short.asInstanceOf[TypeTag[T]]
305-
case CharTpe => TypeTag.Char.asInstanceOf[TypeTag[T]]
306-
case IntTpe => TypeTag.Int.asInstanceOf[TypeTag[T]]
307-
case LongTpe => TypeTag.Long.asInstanceOf[TypeTag[T]]
308-
case FloatTpe => TypeTag.Float.asInstanceOf[TypeTag[T]]
309-
case DoubleTpe => TypeTag.Double.asInstanceOf[TypeTag[T]]
310-
case BooleanTpe => TypeTag.Boolean.asInstanceOf[TypeTag[T]]
311-
case UnitTpe => TypeTag.Unit.asInstanceOf[TypeTag[T]]
312-
case AnyTpe => TypeTag.Any.asInstanceOf[TypeTag[T]]
313-
case AnyValTpe => TypeTag.AnyVal.asInstanceOf[TypeTag[T]]
314-
case AnyRefTpe => TypeTag.AnyRef.asInstanceOf[TypeTag[T]]
315-
case ObjectTpe => TypeTag.Object.asInstanceOf[TypeTag[T]]
316-
case NothingTpe => TypeTag.Nothing.asInstanceOf[TypeTag[T]]
317-
case NullTpe => TypeTag.Null.asInstanceOf[TypeTag[T]]
318-
case _ => new TypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1)
319-
}
285+
new TypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1)
320286

321287
def unapply[T](ttag: TypeTag[T]): Option[Type] = Some(ttag.tpe)
322288
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
TypeTag[Int]
1+
WeakTypeTag[Int]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
TypeTag[Int]
1+
WeakTypeTag[Int]
22
WeakTypeTag[String]
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
===Macros1 typed===
2-
TypeTag[Int]
3-
TypeTag[Int]
2+
WeakTypeTag[Int]
3+
WeakTypeTag[Int]
44
WeakTypeTag[String]
5-
TypeTag[Boolean]
5+
WeakTypeTag[Boolean]
66
===Macros1 untyped===
77
WeakTypeTag[U]
88
WeakTypeTag[U]
99
WeakTypeTag[U]
1010
WeakTypeTag[U]
1111
===Macros2 typed===
12-
TypeTag[Boolean] TypeTag[Int]
13-
TypeTag[Boolean] WeakTypeTag[String]
12+
WeakTypeTag[Boolean] WeakTypeTag[Int]
13+
WeakTypeTag[Boolean] WeakTypeTag[String]
1414
===Macros2 untyped===
15-
TypeTag[Boolean] WeakTypeTag[U]
16-
TypeTag[Boolean] WeakTypeTag[U]
15+
WeakTypeTag[Boolean] WeakTypeTag[U]
16+
WeakTypeTag[Boolean] WeakTypeTag[U]
1717
===Macros3 typed===
18-
TypeTag[Int]
18+
WeakTypeTag[Int]
1919
WeakTypeTag[String]
20-
TypeTag[Boolean]
20+
WeakTypeTag[Boolean]
2121
===Macros3 untyped===
22-
TypeTag[Int]
22+
WeakTypeTag[Int]
2323
WeakTypeTag[String]
24-
TypeTag[Boolean]
24+
WeakTypeTag[Boolean]
2525
===Macros4 typed===
26-
TypeTag[Int]
26+
WeakTypeTag[Int]
2727
WeakTypeTag[String]
28-
TypeTag[Boolean]
28+
WeakTypeTag[Boolean]
2929
===Macros4 untyped===
30-
TypeTag[Int]
30+
WeakTypeTag[Int]
3131
WeakTypeTag[String]
32-
TypeTag[Boolean]
32+
WeakTypeTag[Boolean]
3333
===Macros5 typed and untyped===
3434
WeakTypeTag[T]
3535
WeakTypeTag[U]
36-
TypeTag[Boolean]
36+
WeakTypeTag[Boolean]
3737
WeakTypeTag[T]
3838
WeakTypeTag[U]
39-
TypeTag[Boolean]
39+
WeakTypeTag[Boolean]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
A = TypeTag[Int]
2-
B = TypeTag[Nothing]
1+
A = WeakTypeTag[Int]
2+
B = WeakTypeTag[Nothing]
33
List(1)
4-
A = TypeTag[Any]
4+
A = WeakTypeTag[Any]
55
List(abc, 1)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
TypeTag[Int]
1+
WeakTypeTag[Int]
22
WeakTypeTag[String]

test/files/run/t6937.check

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Type in expressions to have them evaluated.
2+
Type :help for more information.
3+
4+
scala>
5+
6+
scala> import scala.reflect.runtime.{universe => ru}
7+
import scala.reflect.runtime.{universe=>ru}
8+
9+
scala> import scala.reflect.runtime.{currentMirror => cm}
10+
import scala.reflect.runtime.{currentMirror=>cm}
11+
12+
scala> import scala.reflect.api.{Universe => ApiUniverse}
13+
import scala.reflect.api.{Universe=>ApiUniverse}
14+
15+
scala> class A
16+
defined class A
17+
18+
scala> lazy val apiru = ru: ApiUniverse
19+
apiru: scala.reflect.api.Universe = <lazy>
20+
21+
scala> apiru.typeTag[A].in(cm)
22+
res0: reflect.runtime.universe.TypeTag[A] = TypeTag[A]
23+
24+
scala>
25+
26+
scala>

test/files/run/t6937.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.tools.partest.ReplTest
2+
3+
object Test extends ReplTest {
4+
def code = """
5+
import scala.reflect.runtime.{universe => ru}
6+
import scala.reflect.runtime.{currentMirror => cm}
7+
import scala.reflect.api.{Universe => ApiUniverse}
8+
class A
9+
lazy val apiru = ru: ApiUniverse
10+
apiru.typeTag[A].in(cm)
11+
"""
12+
}

0 commit comments

Comments
 (0)