Skip to content

Commit

Permalink
Some comments as follow up for #7966
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaanm committed May 9, 2019
1 parent d73f85d commit 6fcc7eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
classTParams = tparams
val parents = new ListBuffer[Type]()
while (index < end) {
val parent = sig2type(tparams, skiptvs = false)
parents += (if (parent == ObjectTpeJava) ObjectTpe else parent) // here the variance doesn't matter
val parent = sig2type(tparams, skiptvs = false) // here the variance doesn't matter
parents += (if (parent == ObjectTpeJava) ObjectTpe else parent)
}
ClassInfoType(parents.toList, instanceScope, sym)
}
Expand Down
11 changes: 11 additions & 0 deletions src/reflect/scala/reflect/internal/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,19 @@ trait Definitions extends api.StandardDefinitions {
lazy val BoxedUnitTpe = BoxedUnitClass.tpe
lazy val NothingTpe = NothingClass.tpe
lazy val NullTpe = NullClass.tpe

/** Represents `java.lang.Object` as referenced from Scala code. */
lazy val ObjectTpe = ObjectClass.tpe

/** ObjectTpeJava is a TypeRef that's structurally equal to ObjectTpe, but with its own object identity.
*
* When referenced from Java (source or bytecode), `Object` should be considered equal to Scala's `Any`,
* as these types are both conceptually the top of the subtyping lattice of the respective languages.
*
* We use `ObjectTpeJava`'s identity to equate it, but not `ObjectTpe`, to `AnyTpe` in subtyping and type equality.
*/
lazy val ObjectTpeJava = mkObjectTpeJava

lazy val SerializableTpe = SerializableClass.tpe
lazy val StringTpe = StringClass.tpe
lazy val ThrowableTpe = ThrowableClass.tpe
Expand Down
8 changes: 8 additions & 0 deletions src/reflect/scala/reflect/internal/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2709,6 +2709,14 @@ trait Types
private final class ClassNoArgsTypeRef(pre: Type, sym: Symbol) extends NoArgsTypeRef(pre, sym){
override def contains(sym0: Symbol): Boolean = (sym eq sym0) || pre.contains(sym0)
}

/** Expose ClassNoArgsTypeRef so we can create a non-uniqued ObjectTpeJava here and in reflect
*
* NOTE:
* - definitions.ObjectTpe is forced first, so that it ends up in the unique cache.
* - the created TypeRef is structurally equal to ObjectTpe, but with its own identity
* - we don't want the TypeRef we create here to be unique'd
*/
private[scala] def mkObjectTpeJava: Type = new ClassNoArgsTypeRef(definitions.ObjectTpe.prefix, definitions.ObjectClass)

object TypeRef extends TypeRefExtractor {
Expand Down

0 comments on commit 6fcc7eb

Please sign in to comment.