diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 8471b06b7e97..5750dbed2924 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -775,17 +775,7 @@ object desugar { case PatDef(_, ids: List[Ident] @ unchecked, _, _) => ids } - val stats0 = impl.body.map(expandConstructor) - val stats = - if (ctx.owner eq defn.ScalaPackageClass) && defn.hasProblematicGetClass(className) then - stats0.filterConserve { - case ddef: DefDef => - ddef.name ne nme.getClass_ - case _ => - true - } - else - stats0 + val stats = impl.body.map(expandConstructor) if (isEnum) { val (enumCases, enumStats) = stats.partition(DesugarEnums.isEnumCase) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 8d305eef16e1..9d7ca9466e75 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1940,27 +1940,6 @@ class Definitions { if (isBoxedUnitClass(cls)) parents.filter(_.typeSymbol != JavaSerializableClass) else parents - private val HasProblematicGetClass: Set[Name] = Set( - tpnme.AnyVal, tpnme.Byte, tpnme.Short, tpnme.Char, tpnme.Int, tpnme.Long, tpnme.Float, tpnme.Double, - tpnme.Unit, tpnme.Boolean) - - /** When typing a primitive value class or AnyVal, we ignore the `getClass` - * member: it's supposed to be an override of the `getClass` defined on `Any`, - * but in dotty `Any#getClass` is polymorphic so it ends up being an overload. - * This is especially problematic because it means that when writing: - * - * 1.asInstanceOf[Int & AnyRef].getClass - * - * the `getClass` that returns `Class[Int]` defined in Int can be selected, - * but this call is specified to return `classOf[Integer]`, see - * tests/run/t5568.scala. - * - * FIXME: remove all the `getClass` methods defined in the standard library - * so we don't have to hot-patch it like this. - */ - def hasProblematicGetClass(className: Name): Boolean = - HasProblematicGetClass.contains(className) - @tu lazy val assumedTransparentNames: Map[Name, Set[Symbol]] = // we should do a more through sweep through it then. val strs = Map( diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 630e618fa09d..66780d18af69 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -444,11 +444,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas var flags = unpickleScalaFlags(readLongNat(), name.isTypeName) - if (name eq nme.getClass_) && defn.hasProblematicGetClass(owner.name) - // Scala 2 sometimes pickle the same type parameter symbol multiple times - // (see i11173 for an example), but we should only unpickle it once. - || tag == TYPEsym && flags.is(TypeParam) && symScope(owner).lookup(name.asTypeName).exists - then + // Scala 2 sometimes pickle the same type parameter symbol multiple times + // (see i11173 for an example), but we should only unpickle it once. + if tag == TYPEsym && flags.is(TypeParam) && symScope(owner).lookup(name.asTypeName).exists then // skip this member return NoSymbol diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 7037a9a986aa..b513c8b8221a 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1035,14 +1035,7 @@ object RefChecks { case Nil => report.error(OverridesNothing(member), member.srcPos) case ms => - // getClass in primitive value classes is defined in the standard library as: - // override def getClass(): Class[Int] = ??? - // However, it's not actually an override in Dotty because our Any#getClass - // is polymorphic (see `Definitions#Any_getClass`), so since we can't change - // the standard library, we need to drop the override flag without reporting - // an error. - if (!(member.name == nme.getClass_ && clazz.isPrimitiveValueClass)) - report.error(OverridesNothingButNameExists(member, ms), member.srcPos) + report.error(OverridesNothingButNameExists(member, ms), member.srcPos) } member.resetFlag(Override) member.resetFlag(AbsOverride) diff --git a/library/src/scala/AnyVal.scala b/library/src/scala/AnyVal.scala index 03eccd7d501c..6fe2ea64a0cb 100644 --- a/library/src/scala/AnyVal.scala +++ b/library/src/scala/AnyVal.scala @@ -55,6 +55,4 @@ import scala.language.`2.13` * still must allocate a value class instance at runtime. These limitations and circumstances are * explained in greater detail in the [[https://docs.scala-lang.org/overviews/core/value-classes.html Value Classes and Universal Traits]]. */ -transparent abstract class AnyVal extends Any, Matchable { - def getClass(): Class[? <: AnyVal] = null.asInstanceOf[Class[? <: AnyVal]] -} +transparent abstract class AnyVal extends Any, Matchable diff --git a/library/src/scala/Boolean.scala b/library/src/scala/Boolean.scala index fcffb481b294..457e38cbbc65 100644 --- a/library/src/scala/Boolean.scala +++ b/library/src/scala/Boolean.scala @@ -108,8 +108,6 @@ final abstract class Boolean private extends AnyVal { */ def ^(x: Boolean): Boolean - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Boolean] = ??? } object Boolean extends AnyValCompanion { diff --git a/library/src/scala/Byte.scala b/library/src/scala/Byte.scala index 4411af029fc2..5b048efec3f8 100644 --- a/library/src/scala/Byte.scala +++ b/library/src/scala/Byte.scala @@ -444,8 +444,6 @@ final abstract class Byte private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Byte] = ??? } object Byte extends AnyValCompanion { diff --git a/library/src/scala/Char.scala b/library/src/scala/Char.scala index 2676676acf27..2f98c23f2e6c 100644 --- a/library/src/scala/Char.scala +++ b/library/src/scala/Char.scala @@ -444,8 +444,6 @@ final abstract class Char private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Char] = ??? } object Char extends AnyValCompanion { diff --git a/library/src/scala/Double.scala b/library/src/scala/Double.scala index ee814f97be16..3e5933d5ed72 100644 --- a/library/src/scala/Double.scala +++ b/library/src/scala/Double.scala @@ -207,8 +207,6 @@ final abstract class Double private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Double] = ??? } object Double extends AnyValCompanion { diff --git a/library/src/scala/Float.scala b/library/src/scala/Float.scala index fc6cced40b5d..d1a861965176 100644 --- a/library/src/scala/Float.scala +++ b/library/src/scala/Float.scala @@ -207,8 +207,6 @@ final abstract class Float private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Float] = ??? } object Float extends AnyValCompanion { diff --git a/library/src/scala/Int.scala b/library/src/scala/Int.scala index dcaa1d2ff828..9dd372ad3182 100644 --- a/library/src/scala/Int.scala +++ b/library/src/scala/Int.scala @@ -444,8 +444,6 @@ final abstract class Int private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Int] = ??? } object Int extends AnyValCompanion { diff --git a/library/src/scala/Long.scala b/library/src/scala/Long.scala index 7c0643b0b2f4..657ee4cf6ec5 100644 --- a/library/src/scala/Long.scala +++ b/library/src/scala/Long.scala @@ -441,8 +441,6 @@ final abstract class Long private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Long] = ??? } object Long extends AnyValCompanion { diff --git a/library/src/scala/Short.scala b/library/src/scala/Short.scala index ed94d655d656..34d2c10304d1 100644 --- a/library/src/scala/Short.scala +++ b/library/src/scala/Short.scala @@ -444,8 +444,6 @@ final abstract class Short private extends AnyVal { /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Short] = ??? } object Short extends AnyValCompanion { diff --git a/library/src/scala/Unit.scala b/library/src/scala/Unit.scala index ab5f1a9b4a3d..90e608d91b37 100644 --- a/library/src/scala/Unit.scala +++ b/library/src/scala/Unit.scala @@ -23,10 +23,7 @@ import scala.language.`2.13` * runtime system. A method with return type `Unit` is analogous to a Java * method which is declared `void`. */ -final abstract class Unit private extends AnyVal { - // Provide a more specific return type for Scaladoc - override def getClass(): Class[Unit] = ??? -} +final abstract class Unit private extends AnyVal @scala.annotation.compileTimeOnly("`Unit` companion object is not allowed in source; instead, use `()` for the unit value") object Unit extends AnyValCompanion {