From 5dc127e69cae1d88aa6910ea6378ad5dc1aaeaab Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 23 Jun 2011 10:26:42 +0000 Subject: getting the revamped getClass to work on Java 5 hunch by adriaan (needed to change Object to Any in strategic location), location + fix determined by paul, menial work (reverts of obsolete spears and introduction of fix) by adriaan review by extempore Revert "A line missed from spear thrust, no review. Revert " "Thrusting spear into darkened alcove attempting to slay java5 " Revert "New theory: fails running on java 1.5. Put in hack to " discover Revert "Everything builds for me, but apparently not for " jenkins. First " --- src/compiler/scala/reflect/internal/Definitions.scala | 14 ++++---------- src/compiler/scala/tools/nsc/Properties.scala | 3 --- .../scala/tools/nsc/settings/StandardScalaSettings.scala | 5 +---- .../scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 2 +- src/compiler/scala/tools/nsc/transform/Erasure.scala | 6 ++---- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 5 ++--- 6 files changed, 10 insertions(+), 25 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 62ed26329e..ce869cfd3d 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -10,7 +10,6 @@ import scala.collection.{ mutable, immutable } import scala.collection.mutable.{ HashMap } import Flags._ import PartialFunction._ -import scala.tools.nsc.Properties trait Definitions /*extends reflect.generic.StandardDefinitions*/ { self: SymbolTable => @@ -833,15 +832,10 @@ trait Definitions /*extends reflect.generic.StandardDefinitions*/ { // Since getClass is not actually a polymorphic method, this requires compiler // participation. At the "Any" level, the return type is Class[_] as it is in // java.lang.Object. Java also special cases the return type. - if (!Properties.isJava5) { - Any_getClass = { - val eparams = typeParamsToExistentials(ClassClass, ClassClass.typeParams) - eparams.head setInfo TypeBounds.empty - val tpe = existentialAbstraction(eparams, appliedType(ClassClass.tpe, List(eparams.head.tpe))) - - newMethod(AnyClass, nme.getClass_, Nil, tpe) setFlag DEFERRED - } - } + Any_getClass = ( + newMethod(AnyClass, nme.getClass_, Nil, getMember(ObjectClass, nme.getClass_).tpe.resultType) + setFlag DEFERRED + ) Any_isInstanceOf = newPolyMethod( AnyClass, nme.isInstanceOf_, tparam => NullaryMethodType(booltype)) setFlag FINAL Any_asInstanceOf = newPolyMethod( diff --git a/src/compiler/scala/tools/nsc/Properties.scala b/src/compiler/scala/tools/nsc/Properties.scala index 5c47c3b887..f88b7e82fc 100644 --- a/src/compiler/scala/tools/nsc/Properties.scala +++ b/src/compiler/scala/tools/nsc/Properties.scala @@ -11,9 +11,6 @@ object Properties extends scala.util.PropertiesTrait { protected def propCategory = "compiler" protected def pickJarBasedOn = classOf[Global] - def isJava5 = javaVersion startsWith "1.5" - def isJava6 = javaVersion startsWith "1.6" - // settings based on jar properties def fileEndingString = scalaPropOrElse("file.ending", ".scala|.java") def residentPromptString = scalaPropOrElse("resident.prompt", "\nnsc> ") diff --git a/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala index 4bc9586ae5..c5b477c7bd 100644 --- a/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala @@ -39,10 +39,7 @@ trait StandardScalaSettings { val nowarn = BooleanSetting ("-nowarn", "Generate no warnings.") val optimise: BooleanSetting // depends on post hook which mutates other settings val print = BooleanSetting ("-print", "Print program with Scala-specific features removed.") - val target = ChoiceSetting ( - "-target", "target", "Target platform for object files.", - List("jvm-1.5", "jvm-1.6", "msil"), "jvm-1.5" - ) + val target = ChoiceSetting ("-target", "target", "Target platform for object files.", List("jvm-1.5", "msil"), "jvm-1.5") val unchecked = BooleanSetting ("-unchecked", "Enable detailed unchecked (erasure) warnings.") val uniqid = BooleanSetting ("-uniqid", "Uniquely tag all identifiers in debugging output.") val usejavacp = BooleanSetting ("-usejavacp", "Utilize the java.class.path in classpath resolution.") diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 92d86c85f3..84054680c4 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -741,7 +741,7 @@ abstract class ClassfileParser { case variance @ ('+' | '-' | '*') => index += 1 val bounds = variance match { - case '+' => TypeBounds.upper(sig2type(tparams, skiptvs)) + case '+' => TypeBounds.upper(objToAny(sig2type(tparams, skiptvs))) case '-' => TypeBounds.lower(sig2type(tparams, skiptvs)) case '*' => TypeBounds.empty } diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 5f1d5808b4..a06812084e 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -535,11 +535,9 @@ abstract class Erasure extends AddInterfaces } // Methods on Any/Object which we rewrite here while we still know what // is a primitive and what arrived boxed. - private lazy val interceptedMethods: Set[Symbol] = ( - Set[Symbol](Any_##, Object_##) - ++ Option(Any_getClass) + private lazy val interceptedMethods = Set[Symbol](Any_##, Object_##, Any_getClass) ++ ( // Each value class has its own getClass for ultra-precise class object typing. - ++ ScalaValueClasses.map(_.tpe member nme.getClass_) + ScalaValueClasses map (_.tpe member nme.getClass_) ) // -------- erasure on trees ------------------------------------------ diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 8ee04bf67d..dd92418af7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3635,8 +3635,7 @@ trait Typers extends Modes { // getClass, we have to catch it immediately so expressions // like x.getClass().newInstance() are typed with the type of x. val isRefinableGetClass = ( - !Properties.isJava5 // seems to be failing weirdly on java5 - && selection.symbol.name == nme.getClass_ + selection.symbol.name == nme.getClass_ && selection.tpe.params.isEmpty // TODO: If the type of the qualifier is inaccessible, we can cause private types // to escape scope here, e.g. pos/t1107. I'm not sure how to properly handle this @@ -3644,7 +3643,7 @@ trait Typers extends Modes { && qual.tpe.typeSymbol.isPublic ) if (isRefinableGetClass) - selection setType MethodType(Nil, erasure.getClassReturnType(qual.tpe)) + selection setType MethodType(Nil, erasure.getClassReturnType(qual.tpe)) else selection } -- cgit v1.2.3