From 66cf4e9a920506d5531279e2e7a6cbae28372828 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 30 Jan 2012 12:14:04 -0800 Subject: Removed obsolete checkfile. --- test/files/neg/anyval-sealed.check | 12 ------------ test/files/neg/anyval-sealed.flags | 1 - 2 files changed, 13 deletions(-) delete mode 100644 test/files/neg/anyval-sealed.check delete mode 100644 test/files/neg/anyval-sealed.flags (limited to 'test/files/neg') diff --git a/test/files/neg/anyval-sealed.check b/test/files/neg/anyval-sealed.check deleted file mode 100644 index 48a457b496..0000000000 --- a/test/files/neg/anyval-sealed.check +++ /dev/null @@ -1,12 +0,0 @@ -anyval-sealed.scala:2: error: match is not exhaustive! -missing combination Byte -missing combination Char -missing combination Double -missing combination Float -missing combination Long -missing combination Short -missing combination Unit - - def f(x: AnyVal) = x match { - ^ -one error found diff --git a/test/files/neg/anyval-sealed.flags b/test/files/neg/anyval-sealed.flags deleted file mode 100644 index 85d8eb2ba2..0000000000 --- a/test/files/neg/anyval-sealed.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings -- cgit v1.2.3 From a9eb9c5b69071a944d2a5225aa320babdf33ad42 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 30 Jan 2012 12:42:26 -0800 Subject: More work on inline classes. Fail compile if AnyVal is inherited by a trait, a non-@inline class, or a class with an AnyRef parent somewhere. Added tests. Added logging, like [log extmethods] Inline class class Bippy spawns extension method. Old: def getClass: Class[_ <: Bippy] New: final def extension$getClass($this: Bippy): Class[_ <: Bippy] Fixed what I hope was a bug in ExtensionMethods where the original method params were dropped. Since adding a NonNull parent was also inflicting an AnyRef on AnyVal subclasses, suppressed that for those. Had the bright idea that AnyVal could extend NotNull. It doesn't seem to accomplish much, but then, I don't think NotNull accomplishes much. Still, maybe it's time to restrict the ways one can use AnyVal so one can't do this: scala> var x: AnyVal = _ x: AnyVal = null --- .../scala/reflect/internal/Definitions.scala | 8 ++++++- .../scala/tools/nsc/ast/parser/Parsers.scala | 2 +- .../tools/nsc/transform/ExtensionMethods.scala | 13 ++++++++--- .../scala/tools/nsc/typechecker/Namers.scala | 6 +++-- .../scala/tools/nsc/typechecker/RefChecks.scala | 23 +++++++++++++++---- src/library/scala/AnyVal.scala | 2 +- src/library/scala/NotNull.scala | 2 -- test/files/neg/anyval-children-2.check | 4 ++++ test/files/neg/anyval-children-2.scala | 1 + test/files/neg/anyval-children.check | 26 ++++++++++++++++++++++ test/files/neg/anyval-children.scala | 14 ++++++++++++ test/files/pos/anyval-children.scala | 2 +- 12 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 test/files/neg/anyval-children-2.check create mode 100644 test/files/neg/anyval-children-2.scala create mode 100644 test/files/neg/anyval-children.check create mode 100644 test/files/neg/anyval-children.scala (limited to 'test/files/neg') diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index f8342444c8..ce0505bf44 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -910,6 +910,12 @@ trait Definitions extends reflect.api.StandardDefinitions { private lazy val scalaValueClassesSet = ScalaValueClasses.toSet private lazy val boxedValueClassesSet = boxedClass.values.toSet + BoxedUnitClass + /** Now that AnyVal is unsealing we need less ambiguous names + * for when we need to distinguish the Nine Original AnyVals + * from the heathen masses. + */ + def isPrimitiveValueClass(sym: Symbol) = scalaValueClassesSet(sym) + /** Is symbol a value class? */ def isValueClass(sym: Symbol) = scalaValueClassesSet(sym) def isNonUnitValueClass(sym: Symbol) = (sym != UnitClass) && isValueClass(sym) @@ -1029,7 +1035,7 @@ trait Definitions extends reflect.api.StandardDefinitions { /** Removing the anyref parent they acquire from having a source file. */ - setParents(AnyValClass, anyparam) + setParents(AnyValClass, List(NotNullClass.tpe, AnyClass.tpe)) ScalaValueClasses foreach { sym => setParents(sym, anyvalparam) } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index eb7c5a6699..3ee8b62bc6 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2757,7 +2757,7 @@ self => Template(List(scalaDot(tpnme.AnyVal)), self, body) } else if (parents0 exists isReferenceToAnyVal) { - // TODO - enforce @inline annotation, and no other parents + // @inline and other restrictions enforced in refchecks Template(parents0, self, body) } else if (name == tpnme.AnyVal) { diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index 5f62dfab39..c308a3633e 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -84,10 +84,11 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { def extensionMethInfo(extensionMeth: Symbol, origInfo: Type, clazz: Symbol): Type = { var newTypeParams = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth) val thisParamType = appliedType(clazz.typeConstructor, newTypeParams map (_.tpe)) - val thisParam = extensionMeth.newValueParameter(nme.SELF, extensionMeth.pos) setInfo thisParamType + val thisParam = extensionMeth.newValueParameter(nme.SELF, extensionMeth.pos) setInfo thisParamType def transform(clonedType: Type): Type = clonedType match { case MethodType(params, restpe) => - MethodType(List(thisParam), clonedType) + // I assume it was a bug that this was dropping params... + MethodType(thisParam :: params, clonedType) case NullaryMethodType(restpe) => MethodType(List(thisParam), restpe) } @@ -116,7 +117,13 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { val extensionMeth = companion.moduleClass.newMethod(extensionName, origMeth.pos, origMeth.flags & ~OVERRIDE | FINAL) .setAnnotations(origMeth.annotations) companion.info.decls.enter(extensionMeth) - extensionMeth.setInfo(extensionMethInfo(extensionMeth, origMeth.info, currentOwner)) + val newInfo = extensionMethInfo(extensionMeth, origMeth.info, currentOwner) + extensionMeth setInfo newInfo + log("Inline class %s spawns extension method.\n Old: %s\n New: %s".format( + currentOwner, + origMeth.defString, + extensionMeth.defString)) // extensionMeth.defStringSeenAs(origInfo + def thisParamRef = gen.mkAttributedIdent(extensionMeth.info.params.head setPos extensionMeth.pos) val GenPolyType(extensionTpeParams, extensionMono) = extensionMeth.info val origTpeParams = origMeth.typeParams ::: currentOwner.typeParams diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index b9f3adec75..2f31347829 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1407,7 +1407,9 @@ trait Namers extends MethodSynthesis { } if (sym.isClass && sym.hasAnnotation(ScalaInlineClass) && !phase.erasedTypes) { - ensureParent(NotNullClass) + if (!sym.isSubClass(AnyValClass)) + ensureParent(NotNullClass) + sym setFlag FINAL } @@ -1437,7 +1439,7 @@ trait Namers extends MethodSynthesis { checkNoConflict(PRIVATE, PROTECTED) // checkNoConflict(PRIVATE, OVERRIDE) // this one leads to bad error messages like #4174, so catch in refchecks // checkNoConflict(PRIVATE, FINAL) // can't do this because FINAL also means compile-time constant - checkNoConflict(ABSTRACT, FINAL) + // checkNoConflict(ABSTRACT, FINAL) // this one gives a bad error for non-@inline classes which extend AnyVal // @PP: I added this as a sanity check because these flags are supposed to be // converted to ABSOVERRIDE before arriving here. checkNoConflict(ABSTRACT, OVERRIDE) diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 4449116fd1..f7a6815905 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -683,16 +683,16 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R if (abstractErrors.nonEmpty) unit.error(clazz.pos, abstractErrorMessage) - } else if (clazz.isTrait) { - // prevent abstract methods in interfaces that override final members in Object; see #4431 - if (!(clazz isSubClass AnyValClass)) { + } + else if (clazz.isTrait && !(clazz isSubClass AnyValClass)) { + // For non-AnyVal classes, prevent abstract methods in interfaces that override + // final members in Object; see #4431 for (decl <- clazz.info.decls.iterator) { val overridden = decl.overriddenSymbol(ObjectClass) if (overridden.isFinal) unit.error(decl.pos, "trait cannot redefine final method from class AnyRef") } } - } /** Returns whether there is a symbol declared in class `inclazz` * (which must be different from `clazz`) whose name and type @@ -1527,6 +1527,19 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R ) case _ => () } + + // verify classes extending AnyVal meet the requirements + // (whatever those are to be, but at least: @inline annotation) + private def checkAnyValSubclass(clazz: Symbol) = { + if ((clazz isSubClass AnyValClass) && (clazz ne AnyValClass) && !isPrimitiveValueClass(clazz)) { + if (!clazz.hasAnnotation(ScalaInlineClass)) + unit.error(clazz.pos, "Only @inline classes are allowed to extend AnyVal") + if (clazz.isTrait) + unit.error(clazz.pos, "Only @inline classes (not traits) are allowed to extend AnyVal") + if (clazz.tpe <:< AnyRefClass.tpe) + unit.error(clazz.pos, "Classes which extend AnyVal may not have an ancestor which inherits AnyRef") + } + } override def transform(tree: Tree): Tree = { val savedLocalTyper = localTyper @@ -1562,6 +1575,8 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R checkOverloadedRestrictions(currentOwner) val bridges = addVarargBridges(currentOwner) checkAllOverrides(currentOwner) + checkAnyValSubclass(currentOwner) + if (bridges.nonEmpty) treeCopy.Template(tree, parents, self, body ::: bridges) else tree diff --git a/src/library/scala/AnyVal.scala b/src/library/scala/AnyVal.scala index fb36d61c57..ed32fb7302 100644 --- a/src/library/scala/AnyVal.scala +++ b/src/library/scala/AnyVal.scala @@ -25,7 +25,7 @@ package scala * The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]]. * The ''floating point types'' are [[scala.Float]] and [[scala.Double]]. */ -trait AnyVal { +trait AnyVal extends NotNull { // disabled for now to make the standard build go through. // Once we have a new strap we can uncomment this and delete the AnyVal_getClass entry in Definitions. // def getClass(): Class[_ <: AnyVal] = ??? diff --git a/src/library/scala/NotNull.scala b/src/library/scala/NotNull.scala index d47d47a83e..f90b95c789 100644 --- a/src/library/scala/NotNull.scala +++ b/src/library/scala/NotNull.scala @@ -6,8 +6,6 @@ ** |/ ** \* */ - - package scala /** diff --git a/test/files/neg/anyval-children-2.check b/test/files/neg/anyval-children-2.check new file mode 100644 index 0000000000..cb327faeeb --- /dev/null +++ b/test/files/neg/anyval-children-2.check @@ -0,0 +1,4 @@ +anyval-children-2.scala:1: error: Only @inline classes (not traits) are allowed to extend AnyVal +@inline trait NotOkDingus1 extends AnyVal // fail + ^ +one error found diff --git a/test/files/neg/anyval-children-2.scala b/test/files/neg/anyval-children-2.scala new file mode 100644 index 0000000000..4034eb22dd --- /dev/null +++ b/test/files/neg/anyval-children-2.scala @@ -0,0 +1 @@ +@inline trait NotOkDingus1 extends AnyVal // fail diff --git a/test/files/neg/anyval-children.check b/test/files/neg/anyval-children.check new file mode 100644 index 0000000000..cbb5a2b1d1 --- /dev/null +++ b/test/files/neg/anyval-children.check @@ -0,0 +1,26 @@ +anyval-children.scala:7: error: illegal inheritance; superclass Bippy + is not a subclass of the superclass Object + of the mixin trait ScalaObject +class NotOkBippy1 extends Bippy // fail + ^ +anyval-children.scala:9: error: illegal inheritance; superclass Bippy + is not a subclass of the superclass Object + of the mixin trait Immutable +class NotOkBippy2 extends Bippy with Immutable //fail + ^ +anyval-children.scala:9: error: illegal inheritance; superclass Bippy + is not a subclass of the superclass Object + of the mixin trait ScalaObject +class NotOkBippy2 extends Bippy with Immutable //fail + ^ +anyval-children.scala:11: error: illegal inheritance; superclass Bippy + is not a subclass of the superclass Object + of the mixin trait Immutable +@inline class NotOkBippy3 extends Bippy with Immutable //fail + ^ +anyval-children.scala:11: error: illegal inheritance; superclass Bippy + is not a subclass of the superclass Object + of the mixin trait ScalaObject +@inline class NotOkBippy3 extends Bippy with Immutable //fail + ^ +5 errors found diff --git a/test/files/neg/anyval-children.scala b/test/files/neg/anyval-children.scala new file mode 100644 index 0000000000..5a6109f786 --- /dev/null +++ b/test/files/neg/anyval-children.scala @@ -0,0 +1,14 @@ +class Bippy extends AnyVal // fail + +@inline class NotOkDingus2 extends Immutable with AnyVal // fail + +@inline object NotOkDingus3 extends AnyVal // fail + +class NotOkBippy1 extends Bippy // fail + +class NotOkBippy2 extends Bippy with Immutable //fail + +@inline class NotOkBippy3 extends Bippy with Immutable //fail + + +@inline class OkBippy extends AnyVal // ok diff --git a/test/files/pos/anyval-children.scala b/test/files/pos/anyval-children.scala index 7a2eda8b3f..4ef10a094f 100644 --- a/test/files/pos/anyval-children.scala +++ b/test/files/pos/anyval-children.scala @@ -1 +1 @@ -class Bippy extends AnyVal \ No newline at end of file +@inline class Bippy extends AnyVal \ No newline at end of file -- cgit v1.2.3 From b4cfd1161e9f549a909d9f563f557c17dbddad00 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 3 Feb 2012 07:44:41 +0100 Subject: intermediate work towards a new starr for value classes. --- .../scala/reflect/internal/Definitions.scala | 84 ++++++++++++++-------- .../scala/reflect/internal/transform/Erasure.scala | 8 +-- src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 7 ++ .../scala/tools/nsc/ast/parser/Parsers.scala | 12 ++-- .../scala/tools/nsc/typechecker/Namers.scala | 51 ++++++------- .../scala/tools/nsc/typechecker/Typers.scala | 28 +++++--- src/library/scala/Proxy.scala | 10 +-- .../scala/collection/GenTraversableOnce.scala | 2 +- .../scala/collection/immutable/StringOps.scala | 2 +- src/library/scala/math/Ordered.scala | 2 +- src/library/scala/runtime/ScalaNumberProxy.scala | 2 +- test/files/neg/override-object-no.check | 12 ++-- 12 files changed, 134 insertions(+), 86 deletions(-) (limited to 'test/files/neg') diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index ce0505bf44..792c8ad215 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -21,7 +21,7 @@ trait Definitions extends reflect.api.StandardDefinitions { * methods. */ private type PolyMethodCreator = List[Symbol] => (Option[List[Type]], Type) - + private def enterNewClass(owner: Symbol, name: TypeName, parents: List[Type], flags: Long = 0L): Symbol = { val clazz = owner.newClassSymbol(name, NoPosition, flags) clazz setInfoAndEnter ClassInfoType(parents, newScope, clazz) @@ -104,7 +104,6 @@ trait Definitions extends reflect.api.StandardDefinitions { def isGetClass(sym: Symbol) = (sym.name == nme.getClass_) && (sym.paramss.isEmpty || sym.paramss.head.isEmpty) - lazy val AnyValClass = valueCache(tpnme.AnyVal) lazy val UnitClass = valueCache(tpnme.Unit) lazy val ByteClass = valueCache(tpnme.Byte) lazy val ShortClass = valueCache(tpnme.Short) @@ -166,7 +165,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val RuntimePackage = getRequiredModule("scala.runtime") lazy val RuntimePackageClass = RuntimePackage.moduleClass - + lazy val JavaLangEnumClass = getRequiredClass("java.lang.Enum") // convenient one-argument parameter lists @@ -178,10 +177,10 @@ trait Definitions extends reflect.api.StandardDefinitions { private def booltype = BooleanClass.typeConstructor private def inttype = IntClass.typeConstructor private def stringtype = StringClass.typeConstructor - + // Java types def javaTypeName(jclazz: Class[_]): TypeName = newTypeName(jclazz.getName) - + def javaTypeToValueClass(jtype: Class[_]): Symbol = jtype match { case java.lang.Void.TYPE => UnitClass case java.lang.Byte.TYPE => ByteClass @@ -207,6 +206,23 @@ trait Definitions extends reflect.api.StandardDefinitions { case _ => null } + private def fixupAsAnyTrait(clazz: Symbol): Symbol = { + clazz setInfo fixupAsAnyTrait(clazz.info) + clazz + } + + private def fixupAsAnyTrait(tpe: Type): Type = tpe match { + case ClassInfoType(parents, decls, clazz) => + if (parents.head.typeSymbol == AnyClass) tpe + else { + assert(parents.head.typeSymbol == ObjectClass, parents) + ClassInfoType(AnyClass.tpe :: parents.tail, decls, clazz) + } + case PolyType(tparams, restpe) => + PolyType(tparams, fixupAsAnyTrait(restpe)) +// case _ => tpe + } + // top types lazy val AnyClass = enterNewClass(ScalaPackageClass, tpnme.Any, Nil, ABSTRACT) lazy val AnyRefClass = newAlias(ScalaPackageClass, tpnme.AnyRef, ObjectClass.typeConstructor) @@ -214,6 +230,18 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val AnyCompanionClass = getRequiredClass("scala.AnyCompanion") initFlags (SEALED | ABSTRACT | TRAIT) lazy val AnyValCompanionClass = getRequiredClass("scala.AnyValCompanion") initFlags (SEALED | ABSTRACT | TRAIT) + private var oldValueScheme = true + + lazy val AnyValClass = ScalaPackageClass.info member tpnme.AnyVal orElse { +// println("new anyval") + oldValueScheme = true + val anyval = enterNewClass(ScalaPackageClass, tpnme.AnyVal, anyparam, 0L) + val av_constr = anyval.newClassConstructor(NoPosition) + anyval.info.decls enter av_constr + anyval + } + lazy val AnyVal_getClass = enterNewMethod(AnyValClass, nme.getClass_, Nil, getClassReturnType(AnyValClass.tpe)) + // bottom types lazy val RuntimeNothingClass = getClass(fulltpnme.RuntimeNothing) lazy val RuntimeNullClass = getClass(fulltpnme.RuntimeNull) @@ -274,7 +302,7 @@ trait Definitions extends reflect.api.StandardDefinitions { def Predef_identity = getMember(PredefModule, nme.identity) def Predef_conforms = getMember(PredefModule, nme.conforms) def Predef_wrapRefArray = getMember(PredefModule, nme.wrapRefArray) - + /** Is `sym` a member of Predef with the given name? * Note: DON't replace this by sym == Predef_conforms/etc, as Predef_conforms is a `def` * which does a member lookup (it can't be a lazy val because we might reload Predef @@ -316,7 +344,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val SingletonClass = enterNewClass(ScalaPackageClass, tpnme.Singleton, anyparam, ABSTRACT | TRAIT | FINAL) lazy val SerializableClass = getRequiredClass("scala.Serializable") lazy val JavaSerializableClass = getClass(sn.JavaSerializable) - lazy val ComparableClass = getRequiredClass("java.lang.Comparable") + lazy val ComparableClass = fixupAsAnyTrait(getRequiredClass("java.lang.Comparable")) lazy val JavaCloneableClass = getRequiredClass("java.lang.Cloneable") lazy val RemoteInterfaceClass = getRequiredClass("java.rmi.Remote") lazy val RemoteExceptionClass = getRequiredClass("java.rmi.RemoteException") @@ -426,7 +454,7 @@ trait Definitions extends reflect.api.StandardDefinitions { case m: ClassManifest[_] => val sym = manifestToSymbol(m) val args = m.typeArguments - + if ((sym eq NoSymbol) || args.isEmpty) sym.tpe else appliedType(sym.typeConstructor, args map manifestToType) case _ => @@ -436,7 +464,7 @@ trait Definitions extends reflect.api.StandardDefinitions { def manifestToSymbol(m: ClassManifest[_]): Symbol = m match { case x: scala.reflect.AnyValManifest[_] => getMember(ScalaPackageClass, newTypeName("" + x)) - case _ => + case _ => val name = m.erasure.getName if (name endsWith nme.MODULE_SUFFIX_STRING) getModuleIfDefined(name stripSuffix nme.MODULE_SUFFIX_STRING) @@ -496,7 +524,7 @@ trait Definitions extends reflect.api.StandardDefinitions { case DoubleClass => nme.wrapDoubleArray case BooleanClass => nme.wrapBooleanArray case UnitClass => nme.wrapUnitArray - case _ => + case _ => if ((elemtp <:< AnyRefClass.tpe) && !isPhantomClass(elemtp.typeSymbol)) nme.wrapRefArray else nme.genericWrapArray } @@ -640,7 +668,7 @@ trait Definitions extends reflect.api.StandardDefinitions { case _ => false }) } - + // members of class scala.Any lazy val Any_== = enterNewMethod(AnyClass, nme.EQ, anyparam, booltype, FINAL) lazy val Any_!= = enterNewMethod(AnyClass, nme.NE, anyparam, booltype, FINAL) @@ -662,12 +690,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val Any_isInstanceOf = newT1NullaryMethod(AnyClass, nme.isInstanceOf_, FINAL)(_ => booltype) lazy val Any_asInstanceOf = newT1NullaryMethod(AnyClass, nme.asInstanceOf_, FINAL)(_.typeConstructor) - // AnyVal_getClass is defined here. Once we have a new strap, it could also be - // defined directly in the AnyVal trait. Right now this does not work, because - // strap complains about overriding a final getClass method in Any. - lazy val AnyVal_getClass = newMethod(AnyValClass, nme.getClass_, Nil, getClassReturnType(AnyValClass.tpe)) - - // A type function from T => Class[U], used to determine the return + // A type function from T => Class[U], used to determine the return // type of getClass calls. The returned type is: // // 1. If T is a value type, Class[T]. @@ -708,7 +731,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val Object_ne = enterNewMethod(ObjectClass, nme.ne, anyrefparam, booltype, FINAL) lazy val Object_isInstanceOf = newT1NoParamsMethod(ObjectClass, nme.isInstanceOf_Ob, FINAL | SYNTHETIC)(_ => booltype) lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC)(_.typeConstructor) - lazy val Object_synchronized = newPolyMethod(1, ObjectClass, nme.synchronized_, FINAL)(tps => + lazy val Object_synchronized = newPolyMethod(1, ObjectClass, nme.synchronized_, FINAL)(tps => (Some(List(tps.head.typeConstructor)), tps.head.typeConstructor) ) lazy val String_+ = enterNewMethod(StringClass, nme.raw.PLUS, anyparam, stringtype, FINAL) @@ -816,10 +839,10 @@ trait Definitions extends reflect.api.StandardDefinitions { while (result.isAliasType) result = result.info.typeSymbol result } - + def getRequiredModule(fullname: String): Symbol = getModule(newTermNameCached(fullname)) - def getRequiredClass(fullname: String): Symbol = + def getRequiredClass(fullname: String): Symbol = getClass(newTypeNameCached(fullname)) def getClassIfDefined(fullname: String): Symbol = @@ -868,15 +891,15 @@ trait Definitions extends reflect.api.StandardDefinitions { private def newAlias(owner: Symbol, name: TypeName, alias: Type): Symbol = owner.newAliasType(name) setInfoAndEnter alias - + private def specialPolyClass(name: TypeName, flags: Long)(parentFn: Symbol => Type): Symbol = { val clazz = enterNewClass(ScalaPackageClass, name, Nil) val tparam = clazz.newSyntheticTypeParam("T0", flags) val parents = List(AnyRefClass.tpe, parentFn(tparam)) - + clazz setInfo GenPolyType(List(tparam), ClassInfoType(parents, newScope, clazz)) } - + def newPolyMethod(typeParamCount: Int, owner: Symbol, name: TermName, flags: Long)(createFn: PolyMethodCreator): Symbol = { val msym = owner.newMethod(name.encode, NoPosition, flags) val tparams = msym.newSyntheticTypeParams(typeParamCount) @@ -887,7 +910,7 @@ trait Definitions extends reflect.api.StandardDefinitions { msym setInfoAndEnter polyType(tparams, mtpe) } - + /** T1 means one type parameter. */ def newT1NullaryMethod(owner: Symbol, name: TermName, flags: Long)(createFn: Symbol => Type): Symbol = { @@ -999,7 +1022,7 @@ trait Definitions extends reflect.api.StandardDefinitions { RootClass.info.decls enter EmptyPackage RootClass.info.decls enter RootPackage - + val forced = List( // force initialization of every symbol that is entered as a side effect AnnotationDefaultAttr, // #2264 RepeatedParamClass, @@ -1029,13 +1052,18 @@ trait Definitions extends reflect.api.StandardDefinitions { Object_synchronized, Object_isInstanceOf, Object_asInstanceOf, + //AnyVal_getClass, String_+, - AnyVal_getClass + ComparableClass ) - /** Removing the anyref parent they acquire from having a source file. + /* Removing the anyref parent they acquire from having a source file. */ - setParents(AnyValClass, List(NotNullClass.tpe, AnyClass.tpe)) + if (oldValueScheme) { + setParents(AnyValClass, List(NotNullClass.tpe, AnyClass.tpe)) + } else { + AnyVal_getClass // force it! + } ScalaValueClasses foreach { sym => setParents(sym, anyvalparam) } diff --git a/src/compiler/scala/reflect/internal/transform/Erasure.scala b/src/compiler/scala/reflect/internal/transform/Erasure.scala index 38a60587a4..4775541855 100644 --- a/src/compiler/scala/reflect/internal/transform/Erasure.scala +++ b/src/compiler/scala/reflect/internal/transform/Erasure.scala @@ -62,10 +62,10 @@ trait Erasure { protected def rebindInnerClass(pre: Type, cls: Symbol): Type = { if (cls.owner.isClass) cls.owner.tpe else pre // why not cls.isNestedClass? } - - protected def unboxInlineType(clazz: Symbol): Type = + + protected def unboxInlineType(clazz: Symbol): Type = clazz.primaryConstructor.info.params.head.tpe - + protected def eraseInlineClassRef(clazz: Symbol): Type = { scalaErasure(unboxInlineType(clazz)) } @@ -87,7 +87,7 @@ trait Erasure { else if (sym == AnyClass || sym == AnyValClass || sym == SingletonClass || sym == NotNullClass) erasedTypeRef(ObjectClass) else if (sym == UnitClass) erasedTypeRef(BoxedUnitClass) else if (sym.isRefinementClass) apply(mergeParents(tp.parents)) - else if (sym.isInlineClass) eraseInlineClassRef(sym) + //else if (sym.isInlineClass) eraseInlineClassRef(sym) else if (sym.isClass) typeRef(apply(rebindInnerClass(pre, sym)), sym, List()) // #2585 else apply(sym.info) // alias type or abstract type case PolyType(tparams, restpe) => diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index 662e03d155..81a6659b3c 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -45,4 +45,11 @@ abstract class TreeInfo extends reflect.internal.TreeInfo { def isInterface(mods: HasFlags, body: List[Tree]) = mods.hasTraitFlag && (body forall isInterfaceMember) + + def isAllowedInAnyTrait(stat: Tree): Boolean = stat match { + case _: ValDef => false + case Import(_, _) | EmptyTree => true + case _: DefTree => true + case _ => false + } } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 3ee8b62bc6..acb4e9b122 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -38,7 +38,7 @@ trait ParsersCommon extends ScannersCommon { def freshTypeName(prefix: String): TypeName def deprecationWarning(off: Int, msg: String): Unit def accept(token: Int): Int - + /** Methods inParensOrError and similar take a second argument which, should * the next token not be the expected opener (e.g. LPAREN) will be returned * instead of the contents of the groupers. However in all cases accept(LPAREN) @@ -1141,7 +1141,7 @@ self => private def interpolatedString(): Tree = atPos(in.offset) { val start = in.offset val interpolator = in.name - + val partsBuf = new ListBuffer[Tree] val exprBuf = new ListBuffer[Tree] in.nextToken() @@ -1153,7 +1153,7 @@ self => } } if (in.token == STRINGLIT) partsBuf += literal() - + val t1 = atPos(o2p(start)) { Ident(nme.StringContext) } val t2 = atPos(start) { Apply(t1, partsBuf.toList) } t2 setPos t2.pos.makeTransparent @@ -2765,8 +2765,10 @@ self => } else { val parents = ( - if (!isInterface(mods, body) && !isScalaArray(name)) parents0 :+ scalaScalaObjectConstr - else if (parents0.isEmpty) List(scalaAnyRefConstr) + if (parents0.isEmpty) List(scalaAnyRefConstr) + /*if (!isInterface(mods, body) && !isScalaArray(name)) + parents0 /* :+ scalaScalaObjectConstr*/ + else*/ else parents0 ) ++ caseParents() Template(parents, self, constrMods, vparamss, argss, body, o2p(tstart)) diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 2f31347829..5f156b98e8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -113,7 +113,7 @@ trait Namers extends MethodSynthesis { private def contextFile = context.unit.source.file private def typeErrorHandler[T](tree: Tree, alt: T): PartialFunction[Throwable, T] = { case ex: TypeError => - // H@ need to ensure that we handle only cyclic references + // H@ need to ensure that we handle only cyclic references TypeSigError(tree, ex) alt } @@ -296,7 +296,7 @@ trait Namers extends MethodSynthesis { val pos = tree.pos val isParameter = tree.mods.isParameter val flags = tree.mods.flags & mask - + tree match { case TypeDef(_, _, _, _) if isParameter => owner.newTypeParameter(name.toTypeName, pos, flags) case TypeDef(_, _, _, _) => owner.newTypeSymbol(name.toTypeName, pos, flags) @@ -705,6 +705,13 @@ trait Namers extends MethodSynthesis { if (needsCycleCheck && !typer.checkNonCyclic(tree.pos, tp)) sym setInfo ErrorType } + tree match { + case cdef: ClassDef => + if (!treeInfo.isInterface(sym, cdef.impl.body) && sym != ArrayClass && + (sym.info.parents forall (_.typeSymbol != AnyValClass))) + ensureParent(sym, ScalaObjectClass) + case _ => + } } def moduleClassTypeCompleter(tree: Tree) = { @@ -837,10 +844,6 @@ trait Namers extends MethodSynthesis { val parents = typer.parentTypes(templ) map checkParent -// not yet: -// if (!treeInfo.isInterface(clazz, templ.body) && clazz != ArrayClass) -// ensureParent(ScalaObjectClass) - enterSelf(templ.self) val decls = newScope @@ -1313,6 +1316,22 @@ trait Namers extends MethodSynthesis { } } + def includeParent(tpe: Type, parent: Symbol): Type = tpe match { + case PolyType(tparams, restpe) => + PolyType(tparams, includeParent(restpe, parent)) + case ClassInfoType(parents, decls, clazz) => + if (parents exists (_.typeSymbol == parent)) tpe + else ClassInfoType(parents :+ parent.tpe, decls, clazz) + case _ => + tpe + } + + def ensureParent(clazz: Symbol, parent: Symbol) = { + val info0 = clazz.info + val info1 = includeParent(info0, parent) + if (info0 ne info1) clazz setInfo info1 + } + class LogTransitions[S](onEnter: S => String, onExit: S => String) { val enabled = settings.debug.value @inline final def apply[T](entity: S)(body: => T): T = { @@ -1390,25 +1409,9 @@ trait Namers extends MethodSynthesis { if (sym.info.typeSymbol == FunctionClass(0) && sym.isValueParameter && sym.owner.isCaseClass) fail(ByNameParameter) - def includeParent(tpe: Type, parent: Symbol): Type = tpe match { - case PolyType(tparams, restpe) => - PolyType(tparams, includeParent(restpe, parent)) - case ClassInfoType(parents, decls, clazz) => - if (parents exists (_.typeSymbol == parent)) tpe - else ClassInfoType(parents :+ parent.tpe, decls, clazz) - case _ => - tpe - } - - def ensureParent(parent: Symbol) = { - val info0 = sym.info - val info1 = includeParent(info0, parent) - if (info0 ne info1) sym setInfo info1 - } - - if (sym.isClass && sym.hasAnnotation(ScalaInlineClass) && !phase.erasedTypes) { + if (sym.isClass && sym.hasAnnotation(ScalaInlineClass) && !phase.erasedTypes) { if (!sym.isSubClass(AnyValClass)) - ensureParent(NotNullClass) + ensureParent(sym, NotNullClass) sym setFlag FINAL } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b6f555e42a..680a298230 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -154,7 +154,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { case ErrorType => fun } - + def inferView(tree: Tree, from: Type, to: Type, reportAmbiguous: Boolean): Tree = inferView(tree, from, to, reportAmbiguous, true) @@ -274,7 +274,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { } tp match { case TypeRef(pre, sym, args) => - checkNotLocked(sym) && + checkNotLocked(sym) && ((!sym.isNonClassType) || checkNonCyclic(pos, appliedType(pre.memberInfo(sym), args), sym)) // @M! info for a type ref to a type parameter now returns a polytype // @M was: checkNonCyclic(pos, pre.memberInfo(sym).subst(sym.typeParams, args), sym) @@ -939,7 +939,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { adaptType() else if (inExprModeButNot(mode, FUNmode) && tree.symbol != null && tree.symbol.isMacro && !tree.isDef) { val tree1 = expandMacro(tree) - if (tree1.isErroneous) tree1 else typed(tree1, mode, pt) + if (tree1.isErroneous) tree1 else typed(tree1, mode, pt) } else if ((mode & (PATTERNmode | FUNmode)) == (PATTERNmode | FUNmode)) adaptConstrPattern() else if (inAllModes(mode, EXPRmode | FUNmode) && @@ -1084,7 +1084,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { // Note: implicit arguments are still inferred (this kind of "chaining" is allowed) ) } - + def adaptToMember(qual: Tree, searchTemplate: Type): Tree = adaptToMember(qual, searchTemplate, true, true) def adaptToMember(qual: Tree, searchTemplate: Type, reportAmbiguous: Boolean): Tree = @@ -1099,12 +1099,12 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { } inferView(qual, qual.tpe, searchTemplate, reportAmbiguous, saveErrors) match { case EmptyTree => qual - case coercion => + case coercion => if (settings.logImplicitConv.value) unit.echo(qual.pos, "applied implicit conversion from %s to %s = %s".format( qual.tpe, searchTemplate, coercion.symbol.defString)) - + typedQualifier(atPos(qual.pos)(new ApplyImplicitView(coercion, List(qual)))) } } @@ -1205,6 +1205,8 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { supertpt = TypeTree(supertpt1.tpe.parents.head) setPos supertpt.pos.focus } } + if (supertpt.tpe.typeSymbol == AnyClass && firstParent.isTrait && firstParent != AnyValClass) + supertpt.tpe = AnyRefClass.tpe // Determine // - supertparams: Missing type parameters from supertype @@ -1407,6 +1409,10 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { _.typedTemplate(cdef.impl, parentTypes(cdef.impl)) } val impl2 = finishMethodSynthesis(impl1, clazz, context) + if (clazz.isTrait && clazz.info.parents.nonEmpty && clazz.info.parents.head.typeSymbol == AnyClass) + for (stat <- impl2.body) + if (!treeInfo.isAllowedInAnyTrait(stat)) + unit.error(stat.pos, "this statement is not allowed in trait extending from class Any: "+stat) if ((clazz != ClassfileAnnotationClass) && (clazz isNonBottomSubClass ClassfileAnnotationClass)) restrictionWarning(cdef.pos, unit, @@ -2889,10 +2895,10 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { def packSymbols(hidden: List[Symbol], tp: Type): Type = if (hidden.isEmpty) tp else existentialTransform(hidden, tp)(existentialAbstraction) - + def isReferencedFrom(ctx: Context, sym: Symbol): Boolean = - ctx.owner.isTerm && - (ctx.scope.exists { dcl => dcl.isInitialized && (dcl.info contains sym) }) || + ctx.owner.isTerm && + (ctx.scope.exists { dcl => dcl.isInitialized && (dcl.info contains sym) }) || { var ctx1 = ctx.outer while ((ctx1 != NoContext) && (ctx1.scope eq ctx.scope)) ctx1 = ctx1.outer @@ -3879,7 +3885,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { reallyExists(sym) && ((mode & PATTERNmode | FUNmode) != (PATTERNmode | FUNmode) || !sym.isSourceMethod || sym.hasFlag(ACCESSOR)) } - + if (defSym == NoSymbol) { var defEntry: ScopeEntry = null // the scope entry of defSym, if defined in a local scope @@ -4370,7 +4376,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { case ReferenceToBoxed(idt @ Ident(_)) => val id1 = typed1(idt, mode, pt) match { case id: Ident => id } - treeCopy.ReferenceToBoxed(tree, id1) setType AnyRefClass.tpe + treeCopy.ReferenceToBoxed(tree, id1) setType AnyRefClass.tpe case Literal(value) => tree setType ( diff --git a/src/library/scala/Proxy.scala b/src/library/scala/Proxy.scala index 383ff5b3bb..16c3c3fa56 100644 --- a/src/library/scala/Proxy.scala +++ b/src/library/scala/Proxy.scala @@ -22,13 +22,15 @@ package scala * @author Matthias Zenger * @version 1.0, 26/04/2004 */ -trait Proxy { +trait Proxy extends Any { def self: Any override def hashCode: Int = self.hashCode override def equals(that: Any): Boolean = that match { - case null => false - case x: AnyRef => (x eq this) || (x eq self.asInstanceOf[AnyRef]) || (x equals self) + case null => false + case _ => + val x = that.asInstanceOf[AnyRef] + (x eq this.asInstanceOf[AnyRef]) || (x eq self.asInstanceOf[AnyRef]) || (x equals self) } override def toString = "" + self } @@ -36,7 +38,7 @@ trait Proxy { object Proxy { /** A proxy which exposes the type it is proxying for via a type parameter. */ - trait Typed[T] extends Proxy { + trait Typed[T] extends /*Any with */Proxy { def self: T } } diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index 305f8d768d..18b1a96155 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -41,7 +41,7 @@ package scala.collection * @author Aleksandar Prokopec * @since 2.9 */ -trait GenTraversableOnce[+A] { +trait GenTraversableOnce[+A] extends AnyRef { def foreach[U](f: A => U): Unit diff --git a/src/library/scala/collection/immutable/StringOps.scala b/src/library/scala/collection/immutable/StringOps.scala index 8612357db9..09cbd247e9 100644 --- a/src/library/scala/collection/immutable/StringOps.scala +++ b/src/library/scala/collection/immutable/StringOps.scala @@ -28,7 +28,7 @@ import mutable.StringBuilder * @define Coll StringOps * @define coll string */ -final class StringOps(override val repr: String) extends StringLike[String] { +final class StringOps(override val repr: String) extends AnyRef with StringLike[String] { override protected[this] def thisCollection: WrappedString = new WrappedString(repr) override protected[this] def toCollection(repr: String): WrappedString = new WrappedString(repr) diff --git a/src/library/scala/math/Ordered.scala b/src/library/scala/math/Ordered.scala index 53d618db63..4397f14c94 100644 --- a/src/library/scala/math/Ordered.scala +++ b/src/library/scala/math/Ordered.scala @@ -50,7 +50,7 @@ package scala.math * @author Martin Odersky * @version 1.1, 2006-07-24 */ -trait Ordered[A] extends java.lang.Comparable[A] { +trait Ordered[A] extends /*Any with*/ java.lang.Comparable[A] { /** Result of comparing `this` with operand `that`. * diff --git a/src/library/scala/runtime/ScalaNumberProxy.scala b/src/library/scala/runtime/ScalaNumberProxy.scala index 09e1611dcd..bd19e099e0 100644 --- a/src/library/scala/runtime/ScalaNumberProxy.scala +++ b/src/library/scala/runtime/ScalaNumberProxy.scala @@ -64,7 +64,7 @@ abstract class FractionalProxy[T : Fractional] extends ScalaNumberProxy[T] with def to(end: T, step: T): NumericRange.Inclusive[T] = NumericRange.inclusive(self, end, step) } -trait OrderedProxy[T] extends Typed[T] with Ordered[T] { +trait OrderedProxy[T] extends Ordered[T] with Typed[T] { protected def ord: Ordering[T] def compare(y: T) = ord.compare(self, y) diff --git a/test/files/neg/override-object-no.check b/test/files/neg/override-object-no.check index 6e028d0add..f9fb37381b 100644 --- a/test/files/neg/override-object-no.check +++ b/test/files/neg/override-object-no.check @@ -1,13 +1,13 @@ override-object-no.scala:14: error: overriding object Bar in trait Foo with object Bar in trait Foo2: an overriding object must conform to the overridden object's class bound; - found : case1.Bippy with ScalaObject - required: case1.Bippy with case1.Bippo with ScalaObject + found : case1.Bippy + required: case1.Bippy with case1.Bippo override object Bar extends Bippy { // err ^ override-object-no.scala:21: error: overriding object Bar in trait Quux1 with object Bar in trait Quux2: an overriding object must conform to the overridden object's class bound; - found : Object with ScalaObject{def g: String} - required: Object with ScalaObject{def g: Int} + found : Object{def g: String} + required: Object{def g: Int} trait Quux2 extends Quux1 { override object Bar { def g = "abc" } } // err ^ override-object-no.scala:25: error: overriding object Bar in trait Quux3 of type object Quux4.this.Bar; @@ -16,8 +16,8 @@ override-object-no.scala:25: error: overriding object Bar in trait Quux3 of type ^ override-object-no.scala:43: error: overriding object A in class Foo with object A in class P2: an overriding object must conform to the overridden object's class bound; - found : case2.Bar[List[String]] with ScalaObject - required: case2.Bar[Traversable[String]] with ScalaObject + found : case2.Bar[List[String]] + required: case2.Bar[Traversable[String]] override object A extends Bar[List[String]] // err ^ four errors found -- cgit v1.2.3 From 2b7fb460dd1e666ed37ccba49a82aab959413c22 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 4 Feb 2012 11:22:49 -0800 Subject: Updated checkfiles to subtract ScalaObject. --- test/files/buildmanager/t2556_3/t2556_3.check | 4 ++-- test/files/jvm/manifests.check | 2 +- test/files/neg/anyval-children.check | 12 +++--------- test/files/neg/t0764.check | 2 +- test/files/neg/t2641.check | 6 +----- test/files/neg/t3691.check | 4 ++-- test/files/neg/t464-neg.check | 4 ++-- test/files/neg/t4877.check | 2 +- test/files/neg/t5060.check | 4 ++-- test/files/neg/t664.check | 4 ++-- test/files/neg/variances.check | 2 +- test/files/pos/t1050.scala | 2 +- test/files/presentation/callcc-interpreter.check | 4 ++-- test/files/run/primitive-sigs-2.check | 2 +- test/files/run/repl-parens.check | 2 +- test/files/run/t4110.check | 4 ++-- test/files/run/t4172.check | 2 +- test/files/run/t4891.check | 1 - 18 files changed, 26 insertions(+), 37 deletions(-) (limited to 'test/files/neg') diff --git a/test/files/buildmanager/t2556_3/t2556_3.check b/test/files/buildmanager/t2556_3/t2556_3.check index bf26602494..37808d2b31 100644 --- a/test/files/buildmanager/t2556_3/t2556_3.check +++ b/test/files/buildmanager/t2556_3/t2556_3.check @@ -3,8 +3,8 @@ compiling Set(A.scala, B.scala, C.scala) Changes: Map() builder > A.scala compiling Set(A.scala) -Changes: Map(class A -> List(), class B -> List(Changed(Class(B))[List((A,Object), (ScalaObject,ScalaObject))])) -invalidate C.scala because parents have changed [Changed(Class(B))[List((A,Object), (ScalaObject,ScalaObject))]] +Changes: Map(class A -> List(), class B -> List(Changed(Class(B))[List((A,Object))])) +invalidate C.scala because parents have changed [Changed(Class(B))[List((A,Object))]] invalidate B.scala because it references invalid (no longer inherited) definition [ParentChanged(Class(C))] compiling Set(B.scala, C.scala) B.scala:3: error: type mismatch; diff --git a/test/files/jvm/manifests.check b/test/files/jvm/manifests.check index 54f504b929..453db81a3b 100644 --- a/test/files/jvm/manifests.check +++ b/test/files/jvm/manifests.check @@ -29,7 +29,7 @@ x=Foo, m=Foo[scala.collection.immutable.List[Int]] x=Foo, m=Foo[Foo[Int]] x=Foo, m=Foo[scala.collection.immutable.List[Foo[Int]]] -x=Test1$$anon$1, m=Object with Bar[java.lang.String] +x=Test1$$anon$1, m=Object with Bar[java.lang.String] with Object ()=() true=true diff --git a/test/files/neg/anyval-children.check b/test/files/neg/anyval-children.check index cbb5a2b1d1..f1149a5ce3 100644 --- a/test/files/neg/anyval-children.check +++ b/test/files/neg/anyval-children.check @@ -1,6 +1,4 @@ -anyval-children.scala:7: error: illegal inheritance; superclass Bippy - is not a subclass of the superclass Object - of the mixin trait ScalaObject +anyval-children.scala:7: error: Bippy does not have a constructor class NotOkBippy1 extends Bippy // fail ^ anyval-children.scala:9: error: illegal inheritance; superclass Bippy @@ -8,9 +6,7 @@ anyval-children.scala:9: error: illegal inheritance; superclass Bippy of the mixin trait Immutable class NotOkBippy2 extends Bippy with Immutable //fail ^ -anyval-children.scala:9: error: illegal inheritance; superclass Bippy - is not a subclass of the superclass Object - of the mixin trait ScalaObject +anyval-children.scala:9: error: Bippy does not have a constructor class NotOkBippy2 extends Bippy with Immutable //fail ^ anyval-children.scala:11: error: illegal inheritance; superclass Bippy @@ -18,9 +14,7 @@ anyval-children.scala:11: error: illegal inheritance; superclass Bippy of the mixin trait Immutable @inline class NotOkBippy3 extends Bippy with Immutable //fail ^ -anyval-children.scala:11: error: illegal inheritance; superclass Bippy - is not a subclass of the superclass Object - of the mixin trait ScalaObject +anyval-children.scala:11: error: Bippy does not have a constructor @inline class NotOkBippy3 extends Bippy with Immutable //fail ^ 5 errors found diff --git a/test/files/neg/t0764.check b/test/files/neg/t0764.check index 0788db7f6e..e14c7705b8 100644 --- a/test/files/neg/t0764.check +++ b/test/files/neg/t0764.check @@ -1,5 +1,5 @@ t0764.scala:13: error: type mismatch; - found : Object with Node{type T = _1.type} where val _1: Node{type T = NextType} + found : Node{type T = _1.type} where val _1: Node{type T = NextType} required: Node{type T = Main.this.AType} new Main[AType]( (value: AType).prepend ) ^ diff --git a/test/files/neg/t2641.check b/test/files/neg/t2641.check index 9e2f02ac47..909f4f0cf3 100644 --- a/test/files/neg/t2641.check +++ b/test/files/neg/t2641.check @@ -9,11 +9,7 @@ t2641.scala:17: error: illegal inheritance; self-type ManagedSeq does not conform to scala.collection.TraversableView[A,ManagedSeqStrict[A]]'s selftype scala.collection.TraversableView[A,ManagedSeqStrict[A]] with TraversableView[A, ManagedSeqStrict[A]] ^ -t2641.scala:16: error: illegal inheritance; - self-type ManagedSeq does not conform to ScalaObject's selftype ScalaObject - extends ManagedSeqStrict[A] - ^ t2641.scala:27: error: value managedIterator is not a member of ManagedSeq override def managedIterator = self.managedIterator slice (from, until) ^ -5 errors found +four errors found diff --git a/test/files/neg/t3691.check b/test/files/neg/t3691.check index cd7b440dce..bdf6c268b2 100644 --- a/test/files/neg/t3691.check +++ b/test/files/neg/t3691.check @@ -1,10 +1,10 @@ t3691.scala:4: error: type mismatch; - found : Object with Test.A[String] + found : Test.A[String] required: AnyRef{type A[x]} val b = (new A[String]{}): { type A[x] } // not ok ^ t3691.scala:5: error: type mismatch; - found : Object with Test.A[String] + found : Test.A[String] required: AnyRef{type A} val c = (new A[String]{}): { type A } // not ok ^ diff --git a/test/files/neg/t464-neg.check b/test/files/neg/t464-neg.check index aea1987b2e..e822e7fb6b 100644 --- a/test/files/neg/t464-neg.check +++ b/test/files/neg/t464-neg.check @@ -1,7 +1,7 @@ t464-neg.scala:7: error: not found: value f1 f1() ^ -t464-neg.scala:8: error: method f1 in class A cannot be accessed in A with ScalaObject +t464-neg.scala:8: error: method f1 in class A cannot be accessed in A super.f1() ^ t464-neg.scala:9: error: value f2 is not a member of B @@ -10,7 +10,7 @@ t464-neg.scala:9: error: value f2 is not a member of B t464-neg.scala:10: error: method f3 in class A cannot be accessed in B f3() ^ -t464-neg.scala:11: error: method f3 in class A cannot be accessed in A with ScalaObject +t464-neg.scala:11: error: method f3 in class A cannot be accessed in A super.f3() ^ 5 errors found diff --git a/test/files/neg/t4877.check b/test/files/neg/t4877.check index 0f72300bb4..a4b1e6a50d 100644 --- a/test/files/neg/t4877.check +++ b/test/files/neg/t4877.check @@ -9,7 +9,7 @@ t4877.scala:6: error: type mismatch; def foo3: AnyRef { def bar(x: Int): Int } = new AnyRef { def bar(x: Int) = "abc" } ^ t4877.scala:7: error: type mismatch; - found : Object with C{def bar(x: Int): Int} + found : C{def bar(x: Int): Int} required: C{def bar(x: Int): Int; def quux(x: Int): Int} def foo4: C { def bar(x: Int): Int ; def quux(x: Int): Int } = new C { def bar(x: Int) = 5 } ^ diff --git a/test/files/neg/t5060.check b/test/files/neg/t5060.check index ab860c9d5b..e71f30ccdb 100644 --- a/test/files/neg/t5060.check +++ b/test/files/neg/t5060.check @@ -1,7 +1,7 @@ -t5060.scala:2: error: covariant type T occurs in contravariant position in type => Object with ScalaObject{def contains(x: T): Unit} of value foo0 +t5060.scala:2: error: covariant type T occurs in contravariant position in type => Object{def contains(x: T): Unit} of value foo0 val foo0 = { ^ -t5060.scala:6: error: covariant type T occurs in contravariant position in type => Object with ScalaObject{def contains(x: T): Unit} of method foo1 +t5060.scala:6: error: covariant type T occurs in contravariant position in type => Object{def contains(x: T): Unit} of method foo1 def foo1 = { ^ two errors found diff --git a/test/files/neg/t664.check b/test/files/neg/t664.check index 43a6bea074..cbdf53daea 100644 --- a/test/files/neg/t664.check +++ b/test/files/neg/t664.check @@ -1,7 +1,7 @@ -t664.scala:4: error: type Foo is not a member of test.Test with ScalaObject +t664.scala:4: error: type Foo is not a member of test.Test trait Foo extends super.Foo { ^ -t664.scala:5: error: type Bar is not a member of AnyRef with ScalaObject +t664.scala:5: error: type Bar is not a member of AnyRef trait Bar extends super.Bar; ^ two errors found diff --git a/test/files/neg/variances.check b/test/files/neg/variances.check index 4eaab56cef..dc72b05e1e 100644 --- a/test/files/neg/variances.check +++ b/test/files/neg/variances.check @@ -4,7 +4,7 @@ variances.scala:4: error: covariant type A occurs in contravariant position in t variances.scala:14: error: covariant type A occurs in contravariant position in type A of value a private[this] def setA(a : A) = this.a = a ^ -variances.scala:16: error: covariant type A occurs in invariant position in supertype test.C[A] with ScalaObject of object Baz +variances.scala:16: error: covariant type A occurs in invariant position in supertype test.C[A] of object Baz object Baz extends C[A] ^ variances.scala:63: error: covariant type A occurs in contravariant position in type => test.Covariant.T[A]{val m: A => A} of value x diff --git a/test/files/pos/t1050.scala b/test/files/pos/t1050.scala index e017e30713..d34b0cff16 100644 --- a/test/files/pos/t1050.scala +++ b/test/files/pos/t1050.scala @@ -1,7 +1,7 @@ package t1050 abstract class A { - type T <: scala.ScalaObject + type T <: scala.AnyRef class A { this: T => def b = 3 def c = b diff --git a/test/files/presentation/callcc-interpreter.check b/test/files/presentation/callcc-interpreter.check index 3385ef12b7..41b07b07dc 100644 --- a/test/files/presentation/callcc-interpreter.check +++ b/test/files/presentation/callcc-interpreter.check @@ -20,7 +20,7 @@ retrieved 64 members `method ->[B](y: B)(callccInterpreter.type, B)` `method ==(x$1: Any)Boolean` `method ==(x$1: AnyRef)Boolean` -`method add(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value]` +`method add(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Serializable with Product with callccInterpreter.Value]` `method apply(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[callccInterpreter.Value]` `method asInstanceOf[T0]=> T0` `method callCC[A](h: (A => callccInterpreter.M[A]) => callccInterpreter.M[A])callccInterpreter.M[A]` @@ -87,7 +87,7 @@ def showM(m: callccInterpreter.M[callccInterpreter.Value]): String = m.in.apply( askType at CallccInterpreter.scala(50,30) ================================================================================ [response] askTypeAt at (50,30) -def add(a: callccInterpreter.Value, b: callccInterpreter.Value): callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value] = scala.this.Predef.Pair.apply[callccInterpreter.Value, callccInterpreter.Value](a, b) match { +def add(a: callccInterpreter.Value, b: callccInterpreter.Value): callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Serializable with Product with callccInterpreter.Value] = scala.this.Predef.Pair.apply[callccInterpreter.Value, callccInterpreter.Value](a, b) match { case scala.this.Predef.Pair.unapply[callccInterpreter.Value, callccInterpreter.Value]() ((n: Int)callccInterpreter.Num((m @ _)), (n: Int)callccInterpreter.Num((n @ _))) => this.unitM[callccInterpreter.Num](callccInterpreter.this.Num.apply(m.+(n))) case _ => callccInterpreter.this.unitM[callccInterpreter.Wrong.type](callccInterpreter.this.Wrong) } diff --git a/test/files/run/primitive-sigs-2.check b/test/files/run/primitive-sigs-2.check index c69d1b54a6..0af1434cea 100644 --- a/test/files/run/primitive-sigs-2.check +++ b/test/files/run/primitive-sigs-2.check @@ -1,4 +1,4 @@ -T interface scala.ScalaObject +T class java.lang.Object List(A, char, class java.lang.Object) a public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest) diff --git a/test/files/run/repl-parens.check b/test/files/run/repl-parens.check index 944846541f..69f0a9ce30 100644 --- a/test/files/run/repl-parens.check +++ b/test/files/run/repl-parens.check @@ -66,7 +66,7 @@ scala> 55 ; () => 5 res13: () => Int = scala> () => { class X ; new X } -res14: () => Object with ScalaObject = +res14: () => Object = scala> diff --git a/test/files/run/t4110.check b/test/files/run/t4110.check index 8b005989de..dea7e5957c 100644 --- a/test/files/run/t4110.check +++ b/test/files/run/t4110.check @@ -1,2 +1,2 @@ -Object with Test$A with Test$B -Object with Test$A with Test$B +Object with Test$A with Test$B with Object +Object with Test$A with Test$B with Object diff --git a/test/files/run/t4172.check b/test/files/run/t4172.check index 95e3eb950d..da467e27ea 100644 --- a/test/files/run/t4172.check +++ b/test/files/run/t4172.check @@ -4,7 +4,7 @@ Type :help for more information. scala> scala> val c = { class C { override def toString = "C" }; ((new C, new C { def f = 2 })) } -c: (C, C{def f: Int}) forSome { type C <: Object with ScalaObject } = (C,C) +c: (C, C{def f: Int}) forSome { type C <: Object } = (C,C) scala> diff --git a/test/files/run/t4891.check b/test/files/run/t4891.check index 072f8df8d4..79fd7f6fbb 100644 --- a/test/files/run/t4891.check +++ b/test/files/run/t4891.check @@ -5,4 +5,3 @@ test.generic.C1 test.generic.C2 (m) public void test.generic.C1.m1() null -interface scala.ScalaObject -- cgit v1.2.3 From c6a783ac089d8cf5a60a98946af5e80aff5a7d32 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 4 Feb 2012 14:36:14 -0800 Subject: Making AnyVal into a class instead of a trait. -- traits can extend Any, AnyRef, or AnyVal -- classes can extend AnyRef or AnyVal but not Any. This breaks reflection for the moment as it smuggles AnyVal so far downstream that it's reflecting its way into bytecode (or something) but the following test case goes five for six as anticipated. trait Foo1 extends Any trait Foo2 extends AnyVal trait Foo3 extends AnyRef class Bar1 extends Any // fail @inline class Bar2 extends AnyVal class Bar3 extends AnyRef Eliminated various hijinx from definitions. --- lib/scala-compiler.jar.desired.sha1 | 2 +- lib/scala-library-src.jar.desired.sha1 | 2 +- lib/scala-library.jar.desired.sha1 | 2 +- .../scala/reflect/internal/Definitions.scala | 29 +++++----------------- .../scala/tools/nsc/ast/parser/Parsers.scala | 11 ++++---- .../scala/tools/nsc/transform/AddInterfaces.scala | 12 ++++++--- .../scala/tools/nsc/transform/Constructors.scala | 13 ++++++---- .../scala/tools/nsc/typechecker/Typers.scala | 2 ++ src/library/scala/AnyVal.scala | 2 +- test/files/neg/anyval-anyref-parent.check | 4 +++ test/files/neg/anyval-anyref-parent.scala | 7 ++++++ 11 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 test/files/neg/anyval-anyref-parent.check create mode 100644 test/files/neg/anyval-anyref-parent.scala (limited to 'test/files/neg') diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index 22e714ad41..79f6de5e27 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -83df84e719c0f966c67855a1b453aaff2c01e4f7 ?scala-compiler.jar +40f87533e0d03ad04ca632119286d347ee54d8ae ?scala-compiler.jar diff --git a/lib/scala-library-src.jar.desired.sha1 b/lib/scala-library-src.jar.desired.sha1 index cb39ee8604..cfb865f1e8 100644 --- a/lib/scala-library-src.jar.desired.sha1 +++ b/lib/scala-library-src.jar.desired.sha1 @@ -1 +1 @@ -04d9d47973b10ec7353e2a8199b1bd5c62fb540a ?scala-library-src.jar +4a34794dd9a45cd2e8603de559f565535e7aa74b ?scala-library-src.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 009d5f82ea..28a2c586a0 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -c8e01ec6416bd883e996cf8c6916bf0173c31486 ?scala-library.jar +3516dc2e17bf72b1e4bc665e59f6b7ec51cba48d ?scala-library.jar diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 82d7f947e6..7bd0c0f919 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -230,17 +230,12 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val AnyCompanionClass = getRequiredClass("scala.AnyCompanion") initFlags (SEALED | ABSTRACT | TRAIT) lazy val AnyValCompanionClass = getRequiredClass("scala.AnyValCompanion") initFlags (SEALED | ABSTRACT | TRAIT) - private var oldValueScheme = true - - lazy val AnyValClass = ScalaPackageClass.info member tpnme.AnyVal -// lazy val AnyValClass = ScalaPackageClass.info member tpnme.AnyVal orElse { -// // println("new anyval") -// oldValueScheme = true -// val anyval = enterNewClass(ScalaPackageClass, tpnme.AnyVal, anyparam, 0L) -// val av_constr = anyval.newClassConstructor(NoPosition) -// anyval.info.decls enter av_constr -// anyval -// } + lazy val AnyValClass = ScalaPackageClass.info member tpnme.AnyVal orElse { + val anyval = enterNewClass(ScalaPackageClass, tpnme.AnyVal, List(AnyClass.tpe, NotNullClass.tpe), 0L) + val av_constr = anyval.newClassConstructor(NoPosition) + anyval.info.decls enter av_constr + anyval + } lazy val AnyVal_getClass = enterNewMethod(AnyValClass, nme.getClass_, Nil, getClassReturnType(AnyValClass.tpe)) // bottom types @@ -1077,22 +1072,10 @@ trait Definitions extends reflect.api.StandardDefinitions { Object_synchronized, Object_isInstanceOf, Object_asInstanceOf, - //AnyVal_getClass, String_+, ComparableClass ) - /* Removing the anyref parent they acquire from having a source file. - */ - if (oldValueScheme) { - setParents(AnyValClass, List(NotNullClass.tpe, AnyClass.tpe)) - } else { - AnyVal_getClass // force it! - } - ScalaValueClasses foreach { sym => - setParents(sym, anyvalparam) - } - isInitialized = true } //init diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 8e5a0139a5..f7401c813a 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2753,7 +2753,11 @@ self => val tstart0 = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart atPos(tstart0) { - if (isPrimitiveType(name)) + if (inScalaPackage && name == tpnme.AnyVal) { + val constructor = DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(Nil), TypeTree(), Block(Nil, Literal(Constant()))) + Template(parents0, self, constructor :: body) + } + else if (isPrimitiveType(name)) Template(List(scalaAnyValConstr), self, body) else if (parents0 exists isReferenceToAnyVal) { // @inline and other restrictions enforced in refchecks @@ -2761,10 +2765,7 @@ self => } else { val parents = ( - if (parents0.isEmpty) { - if (inScalaPackage && name == tpnme.AnyVal) List(scalaAnyConstr) - else List(scalaAnyRefConstr) - } + if (parents0.isEmpty) List(scalaAnyRefConstr) /*if (!isInterface(mods, body) && !isScalaArray(name)) parents0 /* :+ scalaScalaObjectConstr*/ else*/ diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index 89dfbfd317..8fe82258e2 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -301,12 +301,16 @@ abstract class AddInterfaces extends InfoTransform { if mc.hasFlag(lateINTERFACE)) yield mixinConstructorCall(implClass(mc)) } - (tree: @unchecked) match { + tree match { case Block(stats, expr) => // needs `hasSymbol` check because `supercall` could be a block (named / default args) - val (presuper, supercall :: rest) = stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER)) - // assert(supercall.symbol.isClassConstructor, supercall) - treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr) + stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER)) match { + case (presuper, supercall :: rest) => + stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER)) + treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr) + case (Nil, Nil) => // AnyVal constructor + Literal(Constant()) + } } } diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 256f13b3fb..a672059211 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -44,11 +44,14 @@ abstract class Constructors extends Transform with ast.TreeDSL { ) // decompose primary constructor into the three entities above. val constrInfo: ConstrInfo = { - val primary = stats find (_.symbol.isPrimaryConstructor) - assert(primary.isDefined, "no constructor in template: impl = " + impl) - - val ddef @ DefDef(_, _, _, List(vparams), _, rhs @ Block(_, _)) = primary.get - ConstrInfo(ddef, vparams map (_.symbol), rhs) + stats find (_.symbol.isPrimaryConstructor) match { + case Some(ddef @ DefDef(_, _, _, List(vparams), _, rhs @ Block(_, _))) => + ConstrInfo(ddef, vparams map (_.symbol), rhs) + case x => + // assert(false, "no constructor in template: impl = " + impl) + // AnyVal constructor + return impl + } } import constrInfo._ diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1d84f7fdaf..ba3172dd06 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1610,6 +1610,8 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { * @param rhs ... */ def computeParamAliases(clazz: Symbol, vparamss: List[List[ValDef]], rhs: Tree) { + if (clazz eq AnyValClass) + return debuglog("computing param aliases for "+clazz+":"+clazz.primaryConstructor.tpe+":"+rhs)//debug def decompose(call: Tree): (Tree, List[Tree]) = call match { case Apply(fn, args) => diff --git a/src/library/scala/AnyVal.scala b/src/library/scala/AnyVal.scala index daad6f6f5e..393f0899f4 100644 --- a/src/library/scala/AnyVal.scala +++ b/src/library/scala/AnyVal.scala @@ -25,7 +25,7 @@ package scala * The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]]. * The ''floating point types'' are [[scala.Float]] and [[scala.Double]]. */ -trait AnyVal extends Any with NotNull { +abstract class AnyVal extends Any with NotNull { // disabled for now to make the standard build go through. // Once we have a new strap we can uncomment this and delete the AnyVal_getClass entry in Definitions. def getClass(): Class[_ <: AnyVal] = ??? diff --git a/test/files/neg/anyval-anyref-parent.check b/test/files/neg/anyval-anyref-parent.check new file mode 100644 index 0000000000..b40a0f2710 --- /dev/null +++ b/test/files/neg/anyval-anyref-parent.check @@ -0,0 +1,4 @@ +anyval-anyref-parent.scala:5: error: Any does not have a constructor +class Bar1 extends Any // fail + ^ +one error found diff --git a/test/files/neg/anyval-anyref-parent.scala b/test/files/neg/anyval-anyref-parent.scala new file mode 100644 index 0000000000..b7bb122ea8 --- /dev/null +++ b/test/files/neg/anyval-anyref-parent.scala @@ -0,0 +1,7 @@ +trait Foo1 extends Any +trait Foo2 extends AnyVal +trait Foo3 extends AnyRef + +class Bar1 extends Any // fail +@inline class Bar2 extends AnyVal +class Bar3 extends AnyRef -- cgit v1.2.3 From 732a080fcb84abf35b599b518849ec421cc9cbd1 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 4 Feb 2012 22:07:20 -0800 Subject: Checkfile output update for AnyVal class. And with that one, I believe all tests pass. --- test/files/neg/anyval-children.check | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/files/neg') diff --git a/test/files/neg/anyval-children.check b/test/files/neg/anyval-children.check index f1149a5ce3..769f990210 100644 --- a/test/files/neg/anyval-children.check +++ b/test/files/neg/anyval-children.check @@ -1,3 +1,6 @@ +anyval-children.scala:3: error: class AnyVal needs to be a trait to be mixed in +@inline class NotOkDingus2 extends Immutable with AnyVal // fail + ^ anyval-children.scala:7: error: Bippy does not have a constructor class NotOkBippy1 extends Bippy // fail ^ @@ -17,4 +20,4 @@ anyval-children.scala:11: error: illegal inheritance; superclass Bippy anyval-children.scala:11: error: Bippy does not have a constructor @inline class NotOkBippy3 extends Bippy with Immutable //fail ^ -5 errors found +6 errors found -- cgit v1.2.3 From 55990c9ec619cf212a31db4f818dedb5d3150157 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 14 Mar 2012 10:25:59 -0700 Subject: New starr to support new fundamental laws of reality. And grueling recovery from branch drift. Merges a portion (and only a portion) of topic/inline into master. The major changes which come with this merge are: AnyVal is unsealed, can be extended directly. ScalaObject is no longer with us. --- lib/scala-compiler.jar.desired.sha1 | 2 +- lib/scala-library-src.jar.desired.sha1 | 2 +- lib/scala-library.jar.desired.sha1 | 2 +- .../scala/tools/nsc/transform/LiftCode.scala | 571 --------------------- .../scala/tools/nsc/typechecker/RefChecks.scala | 2 +- test/files/codelib/code.jar.desired.sha1 | 2 +- test/files/neg/anyval-children-2.check | 2 +- test/files/neg/t5529.check | 4 +- test/files/presentation/callcc-interpreter.check | 4 +- test/files/run/existentials3.check | 44 +- test/files/run/programmatic-main.check | 37 +- test/files/run/reify_ann1a.check | 4 +- test/files/run/reify_ann1b.check | 4 +- test/files/run/reify_classfileann_a.check | 4 +- test/files/run/t1195.check | 12 +- test/files/run/t5224.check | 2 +- test/files/run/t5271_1.check | 2 +- test/files/run/t5271_2.check | 2 +- test/files/run/t5271_3.check | 4 +- test/files/run/t5527.check | 14 +- test/files/specialized/SI-5005.check | 4 +- 21 files changed, 75 insertions(+), 649 deletions(-) delete mode 100644 src/compiler/scala/tools/nsc/transform/LiftCode.scala (limited to 'test/files/neg') diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index 79f6de5e27..d8c99fd8a7 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -40f87533e0d03ad04ca632119286d347ee54d8ae ?scala-compiler.jar +c6fc8984eeabb722aca2d99e7afebdb96e834995 ?scala-compiler.jar diff --git a/lib/scala-library-src.jar.desired.sha1 b/lib/scala-library-src.jar.desired.sha1 index cfb865f1e8..1acb36ecd9 100644 --- a/lib/scala-library-src.jar.desired.sha1 +++ b/lib/scala-library-src.jar.desired.sha1 @@ -1 +1 @@ -4a34794dd9a45cd2e8603de559f565535e7aa74b ?scala-library-src.jar +8aca5d1d5890965ea4c8ece61a6018484566a95b ?scala-library-src.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 28a2c586a0..00fc8b0018 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -3516dc2e17bf72b1e4bc665e59f6b7ec51cba48d ?scala-library.jar +3348de294ffc98750730e835e06a84dd4e1133fc ?scala-library.jar diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala deleted file mode 100644 index 8affea56a2..0000000000 --- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala +++ /dev/null @@ -1,571 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2011 LAMP/EPFL - * @author Gilles Dubochet - * @author Martin Odersky - */ - -package scala.tools.nsc -package transform - -import symtab._ -import Flags._ -import scala.collection.{ mutable, immutable } -import scala.collection.mutable.ListBuffer -import scala.tools.nsc.util.FreshNameCreator -import scala.runtime.ScalaRunTime.{ isAnyVal, isTuple } - -/** - * Translate expressions of the form reflect.Code.lift(exp) - * to the reified "reflect trees" representation of exp. - * Also: mutable variables that are accessed from a local function are wrapped in refs. - * - * @author Martin Odersky - * @version 2.10 - */ -abstract class LiftCode extends Transform with TypingTransformers { - - import global._ // the global environment - import definitions._ // standard classes and methods - import typer.{ typed, atOwner } // methods to type trees - - val symbols: global.type = global - - /** the following two members override abstract members in Transform */ - val phaseName: String = "liftcode" - - def newTransformer(unit: CompilationUnit): Transformer = - new Codifier(unit) - - private lazy val MirrorMemberNames = - ReflectRuntimeMirror.info.nonPrivateMembers filter (_.isTerm) map (_.toString) toSet - - // Would be nice if we could use something like this to check the names, - // but it seems that info is unavailable when I need it. - private def mirrorFactoryName(value: Any): Option[String] = value match { - // Modest (inadequate) sanity check that there's a member by this name. - case x: Product if MirrorMemberNames(x.productPrefix) => - Some(x.productPrefix) - case _ => - Some(value.getClass.getName split """[$.]""" last) filter MirrorMemberNames - } - private def isMirrorMemberObject(value: Product) = value match { - case NoType | NoPrefix | NoPosition | EmptyTree => true - case _ => false - } - - class Codifier(unit: CompilationUnit) extends TypingTransformer(unit) { - - val reifyDebug = settings.Yreifydebug.value - val reifyTyperDebug = settings.Yreifytyperdebug.value - val debugTrace = util.trace when reifyDebug - - val reifyCopypaste = settings.Yreifycopypaste.value - def printCopypaste(tree: Tree) { - if (reifyDebug) println("=======================") - printCopypaste1(tree) - if (reifyDebug) println("=======================") - } - def printCopypaste1(tree: Tree) { - import scala.reflect.api.Modifier - import scala.reflect.api.Modifier._ - - def copypasteModifier(mod: Modifier.Value): String = mod match { - case mod @ ( - `protected` | `private` | `override` | - `abstract` | `final` | `sealed` | - `implicit` | `lazy` | `macro` | - `case` | `trait`) => "`" + mod.toString + "`" - case mod => mod.toString - } - - // I fervently hope this is a test case or something, not anything being - // depended upon. Of more fragile code I cannot conceive. - for (line <- (tree.toString.split(Properties.lineSeparator) drop 2 dropRight 1)) { - var s = line.trim - s = s.replace("$mr.", "") - s = s.replace(".apply", "") - s = s.replace("scala.collection.immutable.", "") - s = "List\\[List\\[.*?\\].*?\\]".r.replaceAllIn(s, "List") - s = "List\\[.*?\\]".r.replaceAllIn(s, "List") - s = s.replace("immutable.this.Nil", "List()") - s = s.replace("modifiersFromInternalFlags", "Modifiers") - s = s.replace("Modifiers(0L, newTypeName(\"\"), List())", "Modifiers()") - s = """Modifiers\((\d+)[lL], newTypeName\("(.*?)"\), List\((.*?)\)\)""".r.replaceAllIn(s, m => { - val buf = new StringBuilder - - val flags = m.group(1).toLong - val s_flags = Flags.modifiersOfFlags(flags) map copypasteModifier mkString ", " - if (s_flags != "") - buf.append("Set(" + s_flags + ")") - - val privateWithin = "" + m.group(2) - if (privateWithin != "") - buf.append(", newTypeName(\"" + privateWithin + "\")") - - val annotations = m.group(3) - if (annotations.nonEmpty) - buf.append(", List(" + annotations + ")") - - "Modifiers(" + buf.toString + ")" - }) - s = """setInternalFlags\((\d+)L\)""".r.replaceAllIn(s, m => { - val flags = m.group(1).toLong - val mods = Flags.modifiersOfFlags(flags) map copypasteModifier - "setInternalFlags(flagsOfModifiers(List(" + mods.mkString(", ") + ")))" - }) - - println(s) - } - } - - override def transformUnit(unit: CompilationUnit) { - atPhase(phase.next) { - super.transformUnit(unit) - } - } - - override def transform(tree: Tree): Tree = { - val sym = tree.symbol - tree match { - case Apply(_, List(tree)) if sym == Code_lift => // reify Code.lift[T](expr) instances - val saved = printTypings - try { - debugTrace("transforming = ")(if (settings.Xshowtrees.value) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString) - debugTrace("transformed = ") { - val untyped = codify(super.transform(tree)) - if (reifyCopypaste) printCopypaste(untyped) - - printTypings = reifyTyperDebug - val typed = localTyper.typedPos(tree.pos)(untyped) - typed - } - } catch { - case ex: ReifierError => - unit.error(ex.pos, ex.msg) - tree - } finally { - printTypings = saved - } - case _ => - super.transform(tree) - } - } - - def codify(tree: Tree): Tree = debugTrace("codified " + tree + " -> ") { - val targetType = definitions.CodeClass.primaryConstructor.info.paramTypes.head - val reifier = new Reifier() - val arg = gen.mkAsInstanceOf(reifier.reifyTopLevel(tree), targetType, wrapInApply = false) - val treetpe = // this really should use packedType(tree.tpe, context.owner) - // where packedType is defined in Typers. But we can do that only if liftCode is moved to Typers. - if (tree.tpe.typeSymbol.isAnonymousClass) tree.tpe.typeSymbol.classBound - else tree.tpe - New(TypeTree(appliedType(definitions.CodeClass.typeConstructor, List(treetpe.widen))), - List(List(arg))) - } - } - - /** - * Given a tree or type, generate a tree that when executed at runtime produces the original tree or type. - * For instance: Given - * - * var x = 1; Code(x + 1) - * - * The `x + 1` expression is reified to - * - * $mr.Apply($mr.Select($mr.Ident($mr.freeVar("x". , x), "+"), List($mr.Literal($mr.Constant(1)))))) - * - * Or, the term name 'abc' is reified to: - * - * $mr.Apply($mr.Select($mr.Ident("newTermName")), List(Literal(Constant("abc"))))) - * - * todo: Treat embedded Code blocks by merging them into containing block - * - */ - class Reifier() { - - final val scalaPrefix = "scala." - final val localPrefix = "$local" - final val memoizerName = "$memo" - - val reifyDebug = settings.Yreifydebug.value - - private val reifiableSyms = mutable.ArrayBuffer[Symbol]() // the symbols that are reified with the tree - private val symIndex = mutable.HashMap[Symbol, Int]() // the index of a reifiable symbol in `reifiableSyms` - private var boundSyms = Set[Symbol]() // set of all symbols that are bound in tree to be reified - - /** - * Generate tree of the form - * - * { val $mr = scala.reflect.runtime.Mirror - * $local1 = new TypeSymbol(owner1, NoPosition, name1) - * ... - * $localN = new TermSymbol(ownerN, NoPositiion, nameN) - * $local1.setInfo(tpe1) - * ... - * $localN.setInfo(tpeN) - * $localN.setAnnotations(annotsN) - * rtree - * } - * - * where - * - * - `$localI` are free type symbols in the environment, as well as local symbols - * of refinement types. - * - `tpeI` are the info's of `symI` - * - `rtree` is code that generates `data` at runtime, maintaining all attributes. - * - `data` is typically a tree or a type. - */ - def reifyTopLevel(data: Any): Tree = { - val rtree = reify(data) - Block(mirrorAlias :: reifySymbolTableSetup, rtree) - } - - private def isLocatable(sym: Symbol) = - sym.isPackageClass || sym.owner.isClass || sym.isTypeParameter && sym.paramPos >= 0 - - private def registerReifiableSymbol(sym: Symbol): Unit = - if (!(symIndex contains sym)) { - sym.owner.ownersIterator find (x => !isLocatable(x)) foreach registerReifiableSymbol - symIndex(sym) = reifiableSyms.length - reifiableSyms += sym - } - - // helper methods - - private def localName(sym: Symbol): TermName = - newTermName(localPrefix + symIndex(sym)) - - private def call(fname: String, args: Tree*): Tree = - Apply(termPath(fname), args.toList) - - private def mirrorSelect(name: String): Tree = - termPath(nme.MIRROR_PREFIX + name) - - private def mirrorCall(name: TermName, args: Tree*): Tree = - call("" + (nme.MIRROR_PREFIX append name), args: _*) - - private def mirrorCall(name: String, args: Tree*): Tree = - call(nme.MIRROR_PREFIX + name, args: _*) - - private def mirrorFactoryCall(value: Product, args: Tree*): Tree = - mirrorCall(value.productPrefix, args: _*) - - private def scalaFactoryCall(name: String, args: Tree*): Tree = - call(scalaPrefix + name + ".apply", args: _*) - - private def mkList(args: List[Tree]): Tree = - scalaFactoryCall("collection.immutable.List", args: _*) - - private def reifyModifiers(m: Modifiers) = - mirrorCall("modifiersFromInternalFlags", reify(m.flags), reify(m.privateWithin), reify(m.annotations)) - - private def reifyAggregate(name: String, args: Any*) = - scalaFactoryCall(name, (args map reify).toList: _*) - - /** - * Reify a list - */ - private def reifyList(xs: List[Any]): Tree = - mkList(xs map reify) - - /** Reify a name */ - private def reifyName(name: Name) = - mirrorCall(if (name.isTypeName) "newTypeName" else "newTermName", Literal(Constant(name.toString))) - - private def isFree(sym: Symbol) = - !(symIndex contains sym) - - /** - * Reify a reference to a symbol - */ - private def reifySymRef(sym: Symbol): Tree = { - symIndex get sym match { - case Some(idx) => - Ident(localName(sym)) - case None => - if (sym == NoSymbol) - mirrorSelect("NoSymbol") - else if (sym == RootPackage) - mirrorSelect("definitions.RootPackage") - else if (sym == RootClass) - mirrorSelect("definitions.RootClass") - else if (sym == EmptyPackage) - mirrorSelect("definitions.EmptyPackage") - else if (sym == EmptyPackageClass) - mirrorSelect("definitions.EmptyPackageClass") - else if (sym.isModuleClass) - Select(reifySymRef(sym.sourceModule), "moduleClass") - else if (sym.isStatic && sym.isClass) - mirrorCall("staticClass", reify(sym.fullName)) - else if (sym.isStatic && sym.isModule) - mirrorCall("staticModule", reify(sym.fullName)) - else if (isLocatable(sym)) - if (sym.isTypeParameter) - mirrorCall("selectParam", reify(sym.owner), reify(sym.paramPos)) - else { - if (reifyDebug) println("locatable: " + sym + " " + sym.isPackageClass + " " + sym.owner + " " + sym.isTypeParameter) - val rowner = reify(sym.owner) - val rname = reify(sym.name.toString) - if (sym.isType) - mirrorCall("selectType", rowner, rname) - else if (sym.isMethod && sym.owner.isClass && sym.owner.info.decl(sym.name).isOverloaded) { - val index = sym.owner.info.decl(sym.name).alternatives indexOf sym - assert(index >= 0, sym) - mirrorCall("selectOverloadedMethod", rowner, rname, reify(index)) - } else - mirrorCall("selectTerm", rowner, rname) - } - else { - if (sym.isTerm) { - if (reifyDebug) println("Free: " + sym) - val symtpe = lambdaLift.boxIfCaptured(sym, sym.tpe, erasedTypes = false) - def markIfCaptured(arg: Ident): Tree = - if (sym.isCapturedVariable) referenceCapturedVariable(arg) else arg - mirrorCall("freeVar", reify(sym.name.toString), reify(symtpe), markIfCaptured(Ident(sym))) - } else { - if (reifyDebug) println("Late local: " + sym) - registerReifiableSymbol(sym) - reifySymRef(sym) - } - } - } - } - - /** - * reify the creation of a symbol - */ - private def reifySymbolDef(sym: Symbol): Tree = { - if (reifyDebug) println("reify sym def " + sym) - - ValDef(NoMods, localName(sym), TypeTree(), - Apply( - Select(reify(sym.owner), "newNestedSymbol"), - List(reify(sym.name), reify(sym.pos), Literal(Constant(sym.flags))) - ) - ) - } - - /** - * Generate code to add type and annotation info to a reified symbol - */ - private def fillInSymbol(sym: Symbol): Tree = { - val rset = Apply(Select(reifySymRef(sym), nme.setTypeSig), List(reifyType(sym.info))) - if (sym.annotations.isEmpty) rset - else Apply(Select(rset, nme.setAnnotations), List(reify(sym.annotations))) - } - - /** Reify a scope */ - private def reifyScope(scope: Scope): Tree = { - scope foreach registerReifiableSymbol - mirrorCall(nme.newScopeWith, scope.toList map reifySymRef: _*) - } - - /** Reify a list of symbols that need to be created */ - private def reifySymbols(syms: List[Symbol]): Tree = { - syms foreach registerReifiableSymbol - mkList(syms map reifySymRef) - } - - /** Reify a type that defines some symbols */ - private def reifyTypeBinder(value: Product, bound: List[Symbol], underlying: Type): Tree = - mirrorFactoryCall(value, reifySymbols(bound), reify(underlying)) - - /** Reify a type */ - private def reifyType(tpe0: Type): Tree = { - val tpe = tpe0.normalize - val tsym = tpe.typeSymbol - if (tsym.isClass && tpe == tsym.typeConstructor && tsym.isStatic) - Select(reifySymRef(tpe.typeSymbol), nme.asTypeConstructor) - else tpe match { - case t @ NoType => - reifyMirrorObject(t) - case t @ NoPrefix => - reifyMirrorObject(t) - case tpe @ ThisType(clazz) if clazz.isModuleClass && clazz.isStatic => - mirrorCall(nme.thisModuleType, reify(clazz.fullName)) - case t @ RefinedType(parents, decls) => - registerReifiableSymbol(tpe.typeSymbol) - mirrorFactoryCall(t, reify(parents), reify(decls), reify(t.typeSymbol)) - case t @ ClassInfoType(parents, decls, clazz) => - registerReifiableSymbol(clazz) - mirrorFactoryCall(t, reify(parents), reify(decls), reify(t.typeSymbol)) - case t @ ExistentialType(tparams, underlying) => - reifyTypeBinder(t, tparams, underlying) - case t @ PolyType(tparams, underlying) => - reifyTypeBinder(t, tparams, underlying) - case t @ MethodType(params, restpe) => - reifyTypeBinder(t, params, restpe) - case _ => - reifyProductUnsafe(tpe) - } - } - - private def definedInLiftedCode(tpe: Type) = - tpe exists (tp => boundSyms contains tp.typeSymbol) - - private def isErased(tree: Tree) = tree match { - case tt: TypeTree => definedInLiftedCode(tt.tpe) && tt.original == null - case _ => false - } - - /** Reify a tree */ - private def reifyTree(tree: Tree): Tree = tree match { - case EmptyTree => - reifyMirrorObject(EmptyTree) - case This(_) if !(boundSyms contains tree.symbol) => - reifyFree(tree) - case Ident(_) if !(boundSyms contains tree.symbol) => - if (tree.symbol.isVariable && tree.symbol.owner.isTerm) { - captureVariable(tree.symbol) // Note order dependency: captureVariable needs to come before reifyTree here. - mirrorCall("Select", reifyFree(tree), reifyName(nme.elem)) - } else reifyFree(tree) - case tt: TypeTree if (tt.tpe != null) => - if (definedInLiftedCode(tt.tpe)) { - // erase non-essential (i.e. inferred) types - // reify symless counterparts of essential types - if (tt.original != null) reify(tt.original) else mirrorCall("TypeTree") - } else { - var rtt = mirrorCall(nme.TypeTree, reifyType(tt.tpe)) - if (tt.original != null) { - val setOriginal = Select(rtt, newTermName("setOriginal")) - val reifiedOriginal = reify(tt.original) - rtt = Apply(setOriginal, List(reifiedOriginal)) - } - rtt - } - case ta @ TypeApply(hk, ts) => - if (ts exists isErased) reifyTree(hk) else reifyProduct(ta) - case global.emptyValDef => - mirrorSelect(nme.emptyValDef) - case Literal(constant @ Constant(tpe: Type)) if boundSyms exists (tpe contains _) => - CannotReifyClassOfBoundType(tree, tpe) - case Literal(constant @ Constant(sym: Symbol)) if boundSyms contains sym => - CannotReifyClassOfBoundEnum(tree, constant.tpe) - case _ => - if (tree.isDef) { - if (reifyDebug) println("boundSym: " + tree.symbol) - boundSyms += tree.symbol - } - - reifyProduct(tree) - /* - if (tree.isDef || tree.isInstanceOf[Function]) - registerReifiableSymbol(tree.symbol) - if (tree.hasSymbol) - rtree = Apply(Select(rtree, nme.setSymbol), List(reifySymRef(tree.symbol))) - Apply(Select(rtree, nme.setType), List(reifyType(tree.tpe))) -*/ - } - - /** - * Reify a free reference. The result will be either a mirror reference - * to a global value, or else a mirror Literal. - */ - private def reifyFree(tree: Tree): Tree = tree match { - case This(_) if tree.symbol.isClass && !tree.symbol.isModuleClass => - val sym = tree.symbol - if (reifyDebug) println("This for %s, reified as freeVar".format(sym)) - if (reifyDebug) println("Free: " + sym) - val freeVar = mirrorCall("freeVar", reify(sym.name.toString), reify(sym.tpe), This(sym)) - mirrorCall(nme.Ident, freeVar) - case This(_) => - if (reifyDebug) println("This for %s, reified as This".format(tree.symbol)) - mirrorCall(nme.This, reifySymRef(tree.symbol)) - case _ => - mirrorCall(nme.Ident, reifySymRef(tree.symbol)) - } - - // todo: consider whether we should also reify positions - private def reifyPosition(pos: Position): Tree = - reifyMirrorObject(NoPosition) - - // !!! we must eliminate these casts. - private def reifyProductUnsafe(x: Any): Tree = - reifyProduct(x.asInstanceOf[Product]) - private def reifyProduct(x: Product): Tree = - mirrorCall(x.productPrefix, (x.productIterator map reify).toList: _*) - - /** - * Reify a case object defined in Mirror - */ - private def reifyMirrorObject(name: String): Tree = mirrorSelect(name) - private def reifyMirrorObject(x: Product): Tree = reifyMirrorObject(x.productPrefix) - - private def isReifiableConstant(value: Any) = value match { - case null => true // seems pretty reifable to me? - case _: String => true - case _ => isAnyVal(value) - } - - /** Reify an arbitary value */ - private def reify(value: Any): Tree = value match { - case tree: Tree => reifyTree(tree) - case sym: Symbol => reifySymRef(sym) - case tpe: Type => reifyType(tpe) - case xs: List[_] => reifyList(xs) - case xs: Array[_] => scalaFactoryCall(nme.Array, xs map reify: _*) - case scope: Scope => reifyScope(scope) - case x: Name => reifyName(x) - case x: Position => reifyPosition(x) - case x: Modifiers => reifyModifiers(x) - case _ => - if (isReifiableConstant(value)) Literal(Constant(value)) - else reifyProductUnsafe(value) - } - - /** - * An (unreified) path that refers to definition with given fully qualified name - * @param mkName Creator for last portion of name (either TermName or TypeName) - */ - private def path(fullname: String, mkName: String => Name): Tree = { - val parts = fullname split "\\." - val prefixParts = parts.init - val lastName = mkName(parts.last) - if (prefixParts.isEmpty) Ident(lastName) - else { - val prefixTree = ((Ident(prefixParts.head): Tree) /: prefixParts.tail)(Select(_, _)) - Select(prefixTree, lastName) - } - } - - /** An (unreified) path that refers to term definition with given fully qualified name */ - private def termPath(fullname: String): Tree = path(fullname, newTermName) - - /** An (unreified) path that refers to type definition with given fully qualified name */ - private def typePath(fullname: String): Tree = path(fullname, newTypeName) - - private def mirrorAlias = - ValDef(NoMods, nme.MIRROR_SHORT, TypeTree(), termPath(fullnme.MirrorPackage)) - - /** - * Generate code that generates a symbol table of all symbols registered in `reifiableSyms` - */ - private def reifySymbolTableSetup: List[Tree] = { - val symDefs, fillIns = new mutable.ArrayBuffer[Tree] - var i = 0 - while (i < reifiableSyms.length) { - // fillInSymbol might create new reifiableSyms, that's why this is done iteratively - symDefs += reifySymbolDef(reifiableSyms(i)) - fillIns += fillInSymbol(reifiableSyms(i)) - i += 1 - } - - symDefs.toList ++ fillIns.toList - } - } - - /** A throwable signalling a reification error */ - class ReifierError(var pos: Position, val msg: String) extends Throwable(msg) { - def this(msg: String) = this(NoPosition, msg) - } - - def CannotReifyClassOfBoundType(tree: Tree, tpe: Type) = { - val msg = "cannot reify classOf[%s] which refers to a type declared inside the block being reified".format(tpe) - throw new ReifierError(tree.pos, msg) - } - - def CannotReifyClassOfBoundEnum(tree: Tree, tpe: Type) = { - val msg = "cannot reify classOf[%s] which refers to an enum declared inside the block being reified".format(tpe) - throw new ReifierError(tree.pos, msg) - } -} diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 1e17cb2e3f..a9278a2616 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -526,7 +526,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R // #3622: erasure operates on uncurried types -- // note on passing sym in both cases: only sym.isType is relevant for uncurry.transformInfo // !!! erasure.erasure(sym, uncurry.transformInfo(sym, tp)) gives erreneous of inaccessible type - check whether that's still the case! - def uncurryAndErase(tp: Type) = erasure.erasure(sym)(uncurry.transformInfo(sym, tp)) + def uncurryAndErase(tp: Type) = erasure.erasure(sym, uncurry.transformInfo(sym, tp)) val tp1 = uncurryAndErase(clazz.thisType.memberType(sym)) val tp2 = uncurryAndErase(clazz.thisType.memberType(other)) afterErasure(tp1 matches tp2) diff --git a/test/files/codelib/code.jar.desired.sha1 b/test/files/codelib/code.jar.desired.sha1 index dbf19cafd7..8dabf404b9 100644 --- a/test/files/codelib/code.jar.desired.sha1 +++ b/test/files/codelib/code.jar.desired.sha1 @@ -1 +1 @@ -e25f1daf9010b9dc6038ae7069fc9d0f7d48a53b ?code.jar +e76a8883d275ca4870f745b505fb0a1cb9cbe446 ?code.jar diff --git a/test/files/neg/anyval-children-2.check b/test/files/neg/anyval-children-2.check index cb327faeeb..a88682ea93 100644 --- a/test/files/neg/anyval-children-2.check +++ b/test/files/neg/anyval-children-2.check @@ -1,4 +1,4 @@ -anyval-children-2.scala:1: error: Only @inline classes (not traits) are allowed to extend AnyVal +anyval-children-2.scala:1: error: Only classes (not traits) are allowed to extend AnyVal @inline trait NotOkDingus1 extends AnyVal // fail ^ one error found diff --git a/test/files/neg/t5529.check b/test/files/neg/t5529.check index 78a26aeb50..5d2175fa79 100644 --- a/test/files/neg/t5529.check +++ b/test/files/neg/t5529.check @@ -4,9 +4,7 @@ t5529.scala:12: error: File is already defined as class File t5529.scala:10: error: class type required but test.Test.File found sealed class Dir extends File { } ^ -t5529.scala:10: error: illegal inheritance; super - is not a subclass of the superclass Object - of the mixin trait ScalaObject +t5529.scala:10: error: test.Test.File does not have a constructor sealed class Dir extends File { } ^ three errors found diff --git a/test/files/presentation/callcc-interpreter.check b/test/files/presentation/callcc-interpreter.check index 41b07b07dc..3385ef12b7 100644 --- a/test/files/presentation/callcc-interpreter.check +++ b/test/files/presentation/callcc-interpreter.check @@ -20,7 +20,7 @@ retrieved 64 members `method ->[B](y: B)(callccInterpreter.type, B)` `method ==(x$1: Any)Boolean` `method ==(x$1: AnyRef)Boolean` -`method add(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Serializable with Product with callccInterpreter.Value]` +`method add(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value]` `method apply(a: callccInterpreter.Value, b: callccInterpreter.Value)callccInterpreter.M[callccInterpreter.Value]` `method asInstanceOf[T0]=> T0` `method callCC[A](h: (A => callccInterpreter.M[A]) => callccInterpreter.M[A])callccInterpreter.M[A]` @@ -87,7 +87,7 @@ def showM(m: callccInterpreter.M[callccInterpreter.Value]): String = m.in.apply( askType at CallccInterpreter.scala(50,30) ================================================================================ [response] askTypeAt at (50,30) -def add(a: callccInterpreter.Value, b: callccInterpreter.Value): callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Serializable with Product with callccInterpreter.Value] = scala.this.Predef.Pair.apply[callccInterpreter.Value, callccInterpreter.Value](a, b) match { +def add(a: callccInterpreter.Value, b: callccInterpreter.Value): callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value] = scala.this.Predef.Pair.apply[callccInterpreter.Value, callccInterpreter.Value](a, b) match { case scala.this.Predef.Pair.unapply[callccInterpreter.Value, callccInterpreter.Value]() ((n: Int)callccInterpreter.Num((m @ _)), (n: Int)callccInterpreter.Num((n @ _))) => this.unitM[callccInterpreter.Num](callccInterpreter.this.Num.apply(m.+(n))) case _ => callccInterpreter.this.unitM[callccInterpreter.Wrong.type](callccInterpreter.this.Wrong) } diff --git a/test/files/run/existentials3.check b/test/files/run/existentials3.check index 41dc1f767c..8559540f80 100644 --- a/test/files/run/existentials3.check +++ b/test/files/run/existentials3.check @@ -1,22 +1,22 @@ -_ <: scala.runtime.AbstractFunction0[_ <: Object with Test$ToS with scala.ScalaObject with scala.Product with scala.Serializable] with scala.ScalaObject with scala.Serializable with java.lang.Object -_ <: Object with Test$ToS with scala.ScalaObject with scala.Product with scala.Serializable -Object with Test$ToS with scala.ScalaObject -Object with Test$ToS with scala.ScalaObject -Object with Test$ToS with scala.ScalaObject -scala.Function0[Object with Test$ToS with scala.ScalaObject] -scala.Function0[Object with Test$ToS with scala.ScalaObject] -_ <: Object with _ <: Object with Object with Test$ToS with scala.ScalaObject -_ <: Object with _ <: Object with _ <: Object with Test$ToS with scala.ScalaObject -scala.collection.immutable.List[Object with scala.collection.Seq[Int] with scala.ScalaObject] -scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int] with scala.ScalaObject] -_ <: scala.runtime.AbstractFunction0[_ <: Object with Test$ToS with scala.ScalaObject with scala.Product with scala.Serializable] with scala.ScalaObject with scala.Serializable with java.lang.Object -_ <: Object with Test$ToS with scala.ScalaObject with scala.Product with scala.Serializable -Object with Test$ToS with scala.ScalaObject -Object with Test$ToS with scala.ScalaObject -Object with Test$ToS with scala.ScalaObject -scala.Function0[Object with Test$ToS with scala.ScalaObject] -scala.Function0[Object with Test$ToS with scala.ScalaObject] -_ <: Object with _ <: Object with Object with Test$ToS with scala.ScalaObject -_ <: Object with _ <: Object with _ <: Object with Test$ToS with scala.ScalaObject -scala.collection.immutable.List[Object with scala.collection.Seq[Int] with scala.ScalaObject] -scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int] with scala.ScalaObject] +_ <: scala.runtime.AbstractFunction0[_ <: Object with Test$ToS with scala.Product with scala.Serializable with Object] with scala.Serializable with java.lang.Object +_ <: Object with Test$ToS with scala.Product with scala.Serializable with Object +Object with Test$ToS +Object with Test$ToS with Object +Object with Test$ToS +scala.Function0[Object with Test$ToS] +scala.Function0[Object with Test$ToS] +_ <: Object with _ <: Object with Object with Test$ToS with Object with Object +_ <: Object with _ <: Object with _ <: Object with Test$ToS with Object with Object +scala.collection.immutable.List[Object with scala.collection.Seq[Int] with Object] +scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int] with Object] +_ <: scala.runtime.AbstractFunction0[_ <: Object with Test$ToS with scala.Product with scala.Serializable with Object] with scala.Serializable with java.lang.Object +_ <: Object with Test$ToS with scala.Product with scala.Serializable with Object +Object with Test$ToS +Object with Test$ToS with Object +Object with Test$ToS +scala.Function0[Object with Test$ToS] +scala.Function0[Object with Test$ToS] +_ <: Object with _ <: Object with Object with Test$ToS with Object with Object +_ <: Object with _ <: Object with _ <: Object with Test$ToS with Object with Object +scala.collection.immutable.List[Object with scala.collection.Seq[Int] with Object] +scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int] with Object] diff --git a/test/files/run/programmatic-main.check b/test/files/run/programmatic-main.check index a24de79b8a..b5a54f5ea7 100644 --- a/test/files/run/programmatic-main.check +++ b/test/files/run/programmatic-main.check @@ -8,23 +8,22 @@ superaccessors 6 add super accessors in traits and nested classes pickler 7 serialize symbol tables refchecks 8 reference/override checking, translate nested objects - liftcode 9 reify trees - uncurry 10 uncurry, translate function values to anonymous classes - tailcalls 11 replace tail calls by jumps - specialize 12 @specialized-driven class and method specialization - explicitouter 13 this refs to outer pointers, translate patterns - erasure 14 erase types, add interfaces for traits - lazyvals 15 allocate bitmaps, translate lazy vals into lazified defs - lambdalift 16 move nested functions to top level - constructors 17 move field definitions into constructors - flatten 18 eliminate inner classes - mixin 19 mixin composition - cleanup 20 platform-specific cleanups, generate reflective calls - icode 21 generate portable intermediate code - inliner 22 optimization: do inlining -inlineExceptionHandlers 23 optimization: inline exception handlers - closelim 24 optimization: eliminate uncalled closures - dce 25 optimization: eliminate dead code - jvm 26 generate JVM bytecode - terminal 27 The last phase in the compiler chain + uncurry 9 uncurry, translate function values to anonymous classes + tailcalls 10 replace tail calls by jumps + specialize 11 @specialized-driven class and method specialization + explicitouter 12 this refs to outer pointers, translate patterns + erasure 13 erase types, add interfaces for traits + lazyvals 14 allocate bitmaps, translate lazy vals into lazified defs + lambdalift 15 move nested functions to top level + constructors 16 move field definitions into constructors + flatten 17 eliminate inner classes + mixin 18 mixin composition + cleanup 19 platform-specific cleanups, generate reflective calls + icode 20 generate portable intermediate code + inliner 21 optimization: do inlining +inlineExceptionHandlers 22 optimization: inline exception handlers + closelim 23 optimization: eliminate uncalled closures + dce 24 optimization: eliminate dead code + jvm 25 generate JVM bytecode + terminal 26 The last phase in the compiler chain diff --git a/test/files/run/reify_ann1a.check b/test/files/run/reify_ann1a.check index 2822238706..97d4848a49 100644 --- a/test/files/run/reify_ann1a.check +++ b/test/files/run/reify_ann1a.check @@ -1,5 +1,5 @@ { - @new ann(immutable.this.List.apply[String]("1a")) @new ann(immutable.this.List.apply[String]("1b")) class C[@new ann(immutable.this.List.apply[String]("2a")) @new ann(immutable.this.List.apply[String]("2b")) T>: Nothing <: Any] extends Object with ScalaObject { + @new ann(immutable.this.List.apply[String]("1a")) @new ann(immutable.this.List.apply[String]("1b")) class C[@new ann(immutable.this.List.apply[String]("2a")) @new ann(immutable.this.List.apply[String]("2b")) T>: Nothing <: Any] extends scala.AnyRef { @new ann(immutable.this.List.apply[String]("3a")) @new ann(immutable.this.List.apply[String]("3b")) private[this] val x: T @ann(immutable.this.List.apply[String]("4a")) @ann(immutable.this.List.apply[String]("4b")) = _; def (@new ann(immutable.this.List.apply[String]("3a")) @new ann(immutable.this.List.apply[String]("3b")) x: T @ann(immutable.this.List.apply[String]("4a")) @ann(immutable.this.List.apply[String]("4b"))) = { super.(); @@ -14,7 +14,7 @@ () } { - @ann(immutable.this.List.apply[String]("1a")) @ann(immutable.this.List.apply[String]("1b")) class C[@ann(immutable.this.List.apply[String]("2a")) @ann(immutable.this.List.apply[String]("2b")) T>: Nothing <: Any] extends Object with ScalaObject { + @ann(immutable.this.List.apply[String]("1a")) @ann(immutable.this.List.apply[String]("1b")) class C[@ann(immutable.this.List.apply[String]("2a")) @ann(immutable.this.List.apply[String]("2b")) T>: Nothing <: Any] extends scala.AnyRef { @ann(immutable.this.List.apply[String]("3a")) @ann(immutable.this.List.apply[String]("3b")) private[this] val x: T @ann(immutable.this.List.apply[String]("4b")) @ann(immutable.this.List.apply[String]("4a")) = _; def (@ann(immutable.this.List.apply[String]("3a")) @ann(immutable.this.List.apply[String]("3b")) x: T @ann(immutable.this.List.apply[String]("4b")) @ann(immutable.this.List.apply[String]("4a"))): C[T] = { C.super.(); diff --git a/test/files/run/reify_ann1b.check b/test/files/run/reify_ann1b.check index e240e1e0ce..ceebc0e2ed 100644 --- a/test/files/run/reify_ann1b.check +++ b/test/files/run/reify_ann1b.check @@ -1,5 +1,5 @@ { - @new ann(bar = "1a") @new ann(bar = "1b") class C[@new ann(bar = "2a") @new ann(bar = "2b") T>: Nothing <: Any] extends Object with ScalaObject { + @new ann(bar = "1a") @new ann(bar = "1b") class C[@new ann(bar = "2a") @new ann(bar = "2b") T>: Nothing <: Any] extends scala.AnyRef { @new ann(bar = "3a") @new ann(bar = "3b") private[this] val x: T @ann(bar = "4a") @ann(bar = "4b") = _; def (@new ann(bar = "3a") @new ann(bar = "3b") x: T @ann(bar = "4a") @ann(bar = "4b")) = { super.(); @@ -14,7 +14,7 @@ () } { - @ann(bar = "1a") @ann(bar = "1b") class C[@ann(bar = "2a") @ann(bar = "2b") T>: Nothing <: Any] extends Object with ScalaObject { + @ann(bar = "1a") @ann(bar = "1b") class C[@ann(bar = "2a") @ann(bar = "2b") T>: Nothing <: Any] extends scala.AnyRef { @ann(bar = "3a") @ann(bar = "3b") private[this] val x: T @ann(bar = "4b") @ann(bar = "4a") = _; def (@ann(bar = "3a") @ann(bar = "3b") x: T @ann(bar = "4b") @ann(bar = "4a")): C[T] = { C.super.(); diff --git a/test/files/run/reify_classfileann_a.check b/test/files/run/reify_classfileann_a.check index 1773263a94..419d916907 100644 --- a/test/files/run/reify_classfileann_a.check +++ b/test/files/run/reify_classfileann_a.check @@ -1,5 +1,5 @@ { - @new ann(bar = "1", quux = Array("2", "3"), baz = new ann(bar = "4")) class C extends Object with ScalaObject { + @new ann(bar = "1", quux = Array("2", "3"), baz = new ann(bar = "4")) class C extends scala.AnyRef { def () = { super.(); () @@ -8,7 +8,7 @@ () } { - @ann(bar = "1", quux = ["2", "3"], baz = ann(bar = "4")) class C extends Object with ScalaObject { + @ann(bar = "1", quux = ["2", "3"], baz = ann(bar = "4")) class C extends scala.AnyRef { def (): C = { C.super.(); () diff --git a/test/files/run/t1195.check b/test/files/run/t1195.check index dc521fb8ca..1214d0c4b5 100644 --- a/test/files/run/t1195.check +++ b/test/files/run/t1195.check @@ -1,6 +1,6 @@ -_ <: scala.runtime.AbstractFunction1[Int, _ <: Object with scala.ScalaObject with scala.Product with scala.Serializable] with scala.ScalaObject with scala.Serializable with java.lang.Object -_ <: Object with scala.ScalaObject with scala.Product with scala.Serializable -Object with scala.ScalaObject with scala.Product with scala.Serializable -_ <: scala.runtime.AbstractFunction1[Int, _ <: Object with scala.ScalaObject with scala.Product with scala.Serializable] with scala.ScalaObject with scala.Serializable with java.lang.Object -_ <: Object with scala.ScalaObject with scala.Product with scala.Serializable -Object with scala.ScalaObject with scala.Product with scala.Serializable +_ <: scala.runtime.AbstractFunction1[Int, _ <: Object with scala.Product with scala.Serializable with Object] with scala.Serializable with java.lang.Object +_ <: Object with scala.Product with scala.Serializable with Object +Object with scala.Product with scala.Serializable +_ <: scala.runtime.AbstractFunction1[Int, _ <: Object with scala.Product with scala.Serializable with Object] with scala.Serializable with java.lang.Object +_ <: Object with scala.Product with scala.Serializable with Object +Object with scala.Product with scala.Serializable diff --git a/test/files/run/t5224.check b/test/files/run/t5224.check index 5bead91b36..28bc75d4fd 100644 --- a/test/files/run/t5224.check +++ b/test/files/run/t5224.check @@ -1,5 +1,5 @@ { - @new Foo(bar = "qwe") class C extends Object with ScalaObject { + @new Foo(bar = "qwe") class C extends scala.AnyRef { def () = { super.(); () diff --git a/test/files/run/t5271_1.check b/test/files/run/t5271_1.check index d4fd544e88..9b956da17a 100644 --- a/test/files/run/t5271_1.check +++ b/test/files/run/t5271_1.check @@ -1,5 +1,5 @@ { - case class C extends Object with ScalaObject with Product with Serializable { + case class C extends Object with Product with Serializable { val foo : Int = _; val bar : Int = _; def (foo: Int, bar: Int) = { diff --git a/test/files/run/t5271_2.check b/test/files/run/t5271_2.check index 5a519f265f..27297febb6 100644 --- a/test/files/run/t5271_2.check +++ b/test/files/run/t5271_2.check @@ -1,5 +1,5 @@ { - case class C extends Object with ScalaObject with Product with Serializable { + case class C extends Object with Product with Serializable { val foo : Int = _; val bar : Int = _; def (foo: Int, bar: Int) = { diff --git a/test/files/run/t5271_3.check b/test/files/run/t5271_3.check index be87696f02..9331c78959 100644 --- a/test/files/run/t5271_3.check +++ b/test/files/run/t5271_3.check @@ -1,12 +1,12 @@ { - object C extends Object with ScalaObject with Serializable { + object C extends scala.AnyRef with Serializable { def () = { super.(); () }; def qwe: Int = 4 }; - case class C extends Object with ScalaObject with Product with Serializable { + case class C extends Object with Product with Serializable { val foo : Int = _; val bar : Int = _; def (foo: Int, bar: Int) = { diff --git a/test/files/run/t5527.check b/test/files/run/t5527.check index 4a8a9ce602..bb13928fd8 100644 --- a/test/files/run/t5527.check +++ b/test/files/run/t5527.check @@ -1,13 +1,13 @@ [[syntax trees at end of parser]]// Scala source: newSource1 package { - object UselessComments extends scala.ScalaObject { + object UselessComments extends scala.AnyRef { def () = { super.(); () }; var z = 0; def test1 = { - object Maybe extends scala.ScalaObject { + object Maybe extends scala.AnyRef { def () = { super.(); () @@ -42,13 +42,13 @@ package { } }; /** comments that we should keep */ - object UsefulComments extends scala.ScalaObject { + object UsefulComments extends scala.AnyRef { def () = { super.(); () }; /** class A */ - class A extends scala.ScalaObject { + class A extends scala.AnyRef { def () = { super.(); () @@ -61,7 +61,7 @@ package { var u = 2 }; /** trait B */ - abstract trait B extends scala.ScalaObject { + abstract trait B extends scala.AnyRef { def $init$() = { () }; @@ -75,7 +75,7 @@ package { var u = 2 }; /** object C */ - object C extends scala.ScalaObject { + object C extends scala.AnyRef { def () = { super.(); () @@ -88,7 +88,7 @@ package { var u = 2 }; /** class D */ - @new deprecated("use ... instead", "2.10.0") class D extends scala.ScalaObject { + @new deprecated("use ... instead", "2.10.0") class D extends scala.AnyRef { def () = { super.(); () diff --git a/test/files/specialized/SI-5005.check b/test/files/specialized/SI-5005.check index d2a97512ae..9fc63a2b1d 100644 --- a/test/files/specialized/SI-5005.check +++ b/test/files/specialized/SI-5005.check @@ -1,6 +1,6 @@ [[syntax trees at end of specialize]]// Scala source: newSource1 package { - class C2[@specialized(scala.Boolean) U >: Nothing <: Any] extends Object with ScalaObject { + class C2[@specialized(scala.Boolean) U >: Nothing <: Any] extends Object { def (): C2[U] = { C2.super.(); () @@ -8,7 +8,7 @@ package { def apply(x: U): U = x; def apply$mcZ$sp(x: Boolean): Boolean = C2.this.apply(x.asInstanceOf[U]()).asInstanceOf[Boolean]() }; - class B extends Object with ScalaObject { + class B extends Object { def (): B = { B.super.(); () -- cgit v1.2.3