From aa7ca3599c51702c3c03b27384d25d54ec76afab Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 7 Feb 2012 18:30:29 +0100 Subject: Making the Meter test expand and compile. --- src/compiler/scala/reflect/internal/Symbols.scala | 4 +++- .../scala/tools/nsc/ast/parser/Parsers.scala | 4 +++- .../scala/tools/nsc/typechecker/Namers.scala | 12 ++++------ .../scala/tools/nsc/typechecker/RefChecks.scala | 26 +++++++++++----------- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 6093b0962f..2a218a251d 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -499,7 +499,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => // class C extends D( { class E { ... } ... } ). Here, E is a class local to a constructor final def isClassLocalToConstructor = isClass && hasFlag(INCONSTRUCTOR) - final def isInlineClass = isClass && hasAnnotation(ScalaInlineClass) + final def isInlineClass = + isClass && info.parents.headOption.getOrElse(AnyClass.tpe).typeSymbol == AnyValClass && + !isValueClass final def isAnonymousClass = isClass && (name containsName tpnme.ANON_CLASS_NAME) final def isAnonymousFunction = isSynthetic && (name containsName tpnme.ANON_FUN_NAME) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 20c35e952f..383eaa283d 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2748,7 +2748,9 @@ self => val tstart0 = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart atPos(tstart0) { - if ((inScalaPackage && name == tpnme.AnyVal) || (parents0 exists isReferenceToAnyVal)) + // [Martin to Paul: This needs to be refined. We should only include the 9 primitive classes, + // not any other value classes that happen to be defined in the Scala package. + if (inScalaPackage && (name == tpnme.AnyVal || (parents0 exists isReferenceToAnyVal))) Template(parents0, self, anyvalConstructor :: body) else Template(anyrefParents, 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 a5e3c3e25d..dcf5005538 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1263,7 +1263,10 @@ trait Namers extends MethodSynthesis { val clazz = tree.symbol val result = createNamer(tree).classSig(tparams, impl) clazz setInfo result - if (clazz.isInlineClass) ensureCompanionObject(cdef) + if (clazz.isInlineClass) { + clazz setFlag FINAL + ensureCompanionObject(cdef) + } result case ModuleDef(_, _, impl) => @@ -1413,13 +1416,6 @@ trait Namers extends MethodSynthesis { if (sym.info.typeSymbol == FunctionClass(0) && sym.isValueParameter && sym.owner.isCaseClass) fail(ByNameParameter) - if (sym.isClass && sym.hasAnnotation(ScalaInlineClass) && !phase.erasedTypes) { - if (!sym.isSubClass(AnyValClass)) - ensureParent(sym, NotNullClass) - - sym setFlag FINAL - } - if (sym.isDeferred) { // Is this symbol type always allowed the deferred flag? def symbolAllowsDeferred = ( diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 04213cfda7..bcdb59cf2e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -150,7 +150,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R } // Override checking ------------------------------------------------------------ - + def isJavaVarargsAncestor(clazz: Symbol) = ( clazz.isClass && clazz.isJavaDefined @@ -167,14 +167,14 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R log("Found java varargs ancestor in " + clazz.fullLocationString + ".") val self = clazz.thisType val bridges = new ListBuffer[Tree] - + def varargBridge(member: Symbol, bridgetpe: Type): Tree = { log("Generating varargs bridge for " + member.fullLocationString + " of type " + bridgetpe) - + val bridge = member.cloneSymbolImpl(clazz, member.flags | VBRIDGE) setPos clazz.pos bridge.setInfo(bridgetpe.cloneInfo(bridge)) clazz.info.decls enter bridge - + val params = bridge.paramss.head val elemtp = params.last.tpe.typeArgs.head val idents = params map Ident @@ -183,7 +183,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R localTyper typed DefDef(bridge, body) } - + // For all concrete non-private members that have a (Scala) repeated parameter: // compute the corresponding method type `jtpe` with a Java repeated parameter // if a method with type `jtpe` exists and that method is not a varargs bridge @@ -203,7 +203,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R } } } - + bridges.toList } else Nil @@ -334,7 +334,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R def deferredCheck = member.isDeferred || !other.isDeferred def subOther(s: Symbol) = s isSubClass other.owner def subMember(s: Symbol) = s isSubClass member.owner - + if (subOther(member.owner) && deferredCheck) { //Console.println(infoString(member) + " shadows1 " + infoString(other) " in " + clazz);//DEBUG return @@ -420,12 +420,12 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R if( !(sameLength(member.typeParams, other.typeParams) && (memberTp.substSym(member.typeParams, other.typeParams) =:= otherTp)) ) // (1.6) overrideTypeError(); - } + } else if (other.isAbstractType) { //if (!member.typeParams.isEmpty) // (1.7) @MAT // overrideError("may not be parameterized"); val otherTp = self.memberInfo(other) - + if (!(otherTp.bounds containsType memberTp)) { // (1.7.1) overrideTypeError(); // todo: do an explaintypes with bounds here explainTypes(_.bounds containsType _, otherTp, memberTp) @@ -1531,17 +1531,17 @@ 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") + unit.error(clazz.pos, "Only classes (not traits) are allowed to extend AnyVal") + /* [Martin] That one is already taken care of by Typers if (clazz.tpe <:< AnyRefClass.tpe) unit.error(clazz.pos, "Classes which extend AnyVal may not have an ancestor which inherits AnyRef") + */ } } -- cgit v1.2.3