diff options
26 files changed, 120 insertions, 71 deletions
@@ -17,7 +17,7 @@ programName=$(basename "$0") declare -a java_args scala_args residual_args -unset verbose quiet cygwin toolcp colors saved_stty +unset verbose quiet cygwin toolcp colors saved_stty CDPATH CompilerMain=dotty.tools.dotc.Main diff --git a/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/src/dotty/tools/dotc/ast/TreeTypeMap.scala index 846c661f5..98027cd39 100644 --- a/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -170,7 +170,7 @@ final class TreeTypeMap( val symsChanged = syms ne mapped val substMap = withSubstitution(syms, mapped) val fullMap = (substMap /: mapped.filter(_.isClass)) { (tmap, cls) => - val origDcls = cls.decls.toList + val origDcls = cls.info.decls.toList val mappedDcls = ctx.mapSymbols(origDcls, tmap) val tmap1 = tmap.withMappedSyms(origDcls, mappedDcls) if (symsChanged) (origDcls, mappedDcls).zipped.foreach(cls.asClass.replace) diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index a7c7ac3c6..5daeed0f8 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -64,7 +64,7 @@ class Definitions { private def newAliasType(name: TypeName, tpe: Type, flags: FlagSet = EmptyFlags): TypeSymbol = { val sym = newSymbol(ScalaPackageClass, name, flags, TypeAlias(tpe)) - ScalaPackageClass.preDecls.enter(sym) + ScalaPackageClass.currentPackageDecls.enter(sym) sym } diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index cd1eacc91..70bcbdee6 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -93,7 +93,7 @@ object Scopes { /** Lookup next entry with same name as this one */ def lookupNextEntry(entry: ScopeEntry)(implicit ctx: Context): ScopeEntry - + /** Lookup a symbol */ final def lookup(name: Name)(implicit ctx: Context): Symbol = { val e = lookupEntry(name) @@ -138,7 +138,9 @@ object Scopes { } def implicitDecls(implicit ctx: Context): List[TermRef] = Nil - + + def openForMutations: MutableScope = unsupported("openForMutations") + final def toText(printer: Printer): Text = printer.toText(this) } @@ -374,6 +376,8 @@ object Scopes { } syms } + + override def openForMutations: MutableScope = this } /** Create a new scope */ @@ -404,7 +408,7 @@ object Scopes { /** The empty scope (immutable). */ object EmptyScope extends Scope { - override def lastEntry = null + override private[dotc] def lastEntry = null override def size = 0 override def nestingLevel = 0 override def toList = Nil diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index eccdcbfb9..b4927b5d4 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -45,7 +45,7 @@ trait SymDenotations { this: Context => val owner = denot.owner.denot stillValid(owner) && ( !owner.isClass - || (owner.decls.lookupAll(denot.name) contains denot.symbol) + || (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol) || denot.isSelfSym ) } catch { @@ -234,24 +234,31 @@ object SymDenotations { final def ensureCompleted()(implicit ctx: Context): Unit = info /** The symbols defined in this class or object. + * Careful! This coes not force the type, so is compilation order dependent. + * This method should be used only in the following circumstances: + * + * 1. When accessing type parameters or type parameter accessors (both are entered before + * completion). + * 2. When obtaining the current scope in order to enter, rename or delete something there. + * 3. When playing it safe in order not to raise CylicReferences, e.g. for printing things + * or taking more efficient shortcuts (e.g. the stillValid test). */ - final def decls(implicit ctx: Context): Scope = myInfo match { + final def unforcedDecls(implicit ctx: Context): Scope = myInfo match { case cinfo: LazyType => val knownDecls = cinfo.decls if (knownDecls ne EmptyScope) knownDecls - else { completeFrom(cinfo); decls } // complete-once + else { completeFrom(cinfo); unforcedDecls } // complete-once case _ => info.decls } /** If this is a package class, the symbols entered in it * before it is completed. (this is needed to eagerly enter synthetic * aliases such as AnyRef into a package class without forcing it. - * Right now, I believe the only usage is for the AnyRef alias - * in Definitions. + * Right now, the only usage is for the AnyRef alias in Definitions. */ - final def preDecls(implicit ctx: Context): MutableScope = myInfo match { - case pinfo: SymbolLoaders # PackageLoader => pinfo.preDecls - case _ => decls.asInstanceOf[MutableScope] + final private[core] def currentPackageDecls(implicit ctx: Context): MutableScope = myInfo match { + case pinfo: SymbolLoaders # PackageLoader => pinfo.currentDecls + case _ => unforcedDecls.openForMutations } // ------ Names ---------------------------------------------- @@ -997,7 +1004,7 @@ object SymDenotations { def computeTypeParams = { if (ctx.erasedTypes || is(Module)) Nil // fast return for modules to avoid scanning package decls else if (this ne initial) initial.asSymDenotation.typeParams - else decls.filter(sym => + else unforcedDecls.filter(sym => (sym is TypeParam) && sym.owner == symbol).asInstanceOf[List[TypeSymbol]] } if (myTypeParams == null) myTypeParams = computeTypeParams @@ -1228,7 +1235,7 @@ object SymDenotations { def enter(sym: Symbol, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = { val mscope = scope match { case scope: MutableScope => scope - case _ => decls.asInstanceOf[MutableScope] + case _ => unforcedDecls.openForMutations } if (this is PackageClass) { val entry = mscope.lookupEntry(sym.name) @@ -1258,7 +1265,7 @@ object SymDenotations { */ def replace(prev: Symbol, replacement: Symbol)(implicit ctx: Context): Unit = { require(!(this is Frozen)) - decls.asInstanceOf[MutableScope].replace(prev, replacement) + unforcedDecls.openForMutations.replace(prev, replacement) if (myMemberCache != null) myMemberCache invalidate replacement.name } @@ -1269,7 +1276,7 @@ object SymDenotations { */ def delete(sym: Symbol)(implicit ctx: Context) = { require(!(this is Frozen)) - info.decls.asInstanceOf[MutableScope].unlink(sym) + info.decls.openForMutations.unlink(sym) if (myMemberFingerPrint != FingerPrint.unknown) computeMemberFingerPrint if (myMemberCache != null) @@ -1281,7 +1288,7 @@ object SymDenotations { * have existing symbols. */ final def membersNamed(name: Name)(implicit ctx: Context): PreDenotation = { - val privates = decls.denotsNamed(name, selectPrivate) + val privates = info.decls.denotsNamed(name, selectPrivate) privates union nonPrivateMembersNamed(name).filterDisjoint(privates) } @@ -1311,7 +1318,7 @@ object SymDenotations { (memberFingerPrint contains name)) { Stats.record("computeNPMembersNamed after fingerprint") ensureCompleted() - val ownDenots = decls.denotsNamed(name, selectNonPrivate) + val ownDenots = info.decls.denotsNamed(name, selectNonPrivate) if (debugTrace) // DEBUG println(s"$this.member($name), ownDenots = $ownDenots") def collect(denots: PreDenotation, parents: List[TypeRef]): PreDenotation = parents match { @@ -1458,14 +1465,14 @@ object SymDenotations { override def primaryConstructor(implicit ctx: Context): Symbol = { val cname = if (this is ImplClass) nme.IMPLCLASS_CONSTRUCTOR else nme.CONSTRUCTOR - decls.denotsNamed(cname).last.symbol // denotsNamed returns Symbols in reverse order of occurrence + info.decls.denotsNamed(cname).last.symbol // denotsNamed returns Symbols in reverse order of occurrence } /** The parameter accessors of this class. Term and type accessors, * getters and setters are all returned int his list */ def paramAccessors(implicit ctx: Context): List[Symbol] = - decls.filter(_ is ParamAccessor).toList + unforcedDecls.filter(_ is ParamAccessor).toList /** If this class has the same `decls` scope reference in `phase` and * `phase.next`, install a new denotation with a cloned scope in `phase.next`. diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index 76ba3885e..0ad34e16a 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -148,13 +148,13 @@ class SymbolLoaders { override def sourceModule(implicit ctx: Context) = _sourceModule def description = "package loader " + classpath.name - private[core] val preDecls: MutableScope = newScope + private[core] val currentDecls: MutableScope = newScope def doComplete(root: SymDenotation)(implicit ctx: Context): Unit = { assert(root is PackageClass, root) def maybeModuleClass(classRep: ClassPath#ClassRep) = classRep.name.last == '$' val pre = root.owner.thisType - root.info = ClassInfo(pre, root.symbol.asClass, Nil, preDecls, pre select sourceModule) + root.info = ClassInfo(pre, root.symbol.asClass, Nil, currentDecls, pre select sourceModule) if (!sourceModule.isCompleted) sourceModule.completer.complete(sourceModule) if (!root.isRoot) { @@ -162,7 +162,7 @@ class SymbolLoaders { if (!maybeModuleClass(classRep)) initializeFromClassPath(root.symbol, classRep) for (classRep <- classpath.classes) - if (maybeModuleClass(classRep) && !root.decls.lookup(classRep.name.toTypeName).exists) + if (maybeModuleClass(classRep) && !root.unforcedDecls.lookup(classRep.name.toTypeName).exists) initializeFromClassPath(root.symbol, classRep) } if (!root.isEmptyPackage) diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 2be97691f..33f8b460c 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -25,7 +25,7 @@ import Denotations.{ Denotation, SingleDenotation, MultiDenotation } import collection.mutable import io.AbstractFile import language.implicitConversions -import util.DotClass +import util.{NoSource, DotClass} /** Creation methods for symbols */ trait Symbols { this: Context => @@ -192,7 +192,7 @@ trait Symbols { this: Context => def stubCompleter = new StubInfo() val normalizedOwner = if (owner is ModuleVal) owner.moduleClass else owner println(s"creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, file = $file") - println(s"decls = ${normalizedOwner.decls.toList.map(_.debugString).mkString("\n ")}") // !!! DEBUG + println(s"decls = ${normalizedOwner.unforcedDecls.toList.map(_.debugString).mkString("\n ")}") // !!! DEBUG //if (base.settings.debug.value) throw new Error() val stub = name match { case name: TermName => @@ -515,6 +515,8 @@ object Symbols { object NoSymbol extends Symbol(NoCoord) { denot = NoDenotation + + override def associatedFile(implicit ctx: Context): AbstractFile = NoSource.file } implicit class Copier[N <: Name](sym: Symbol { type ThisName = N })(implicit ctx: Context) { diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 6443c5054..539ef5e0d 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -141,7 +141,7 @@ class TypeApplications(val self: Type) extends AnyVal { case arg :: args1 => if (tparams.isEmpty) { println(s"applied type mismatch: $self $args, typeParams = $typeParams, tsym = ${self.typeSymbol.debugString}") // !!! DEBUG - println(s"precomplete decls = ${self.typeSymbol.decls.toList.map(_.denot).mkString("\n ")}") + println(s"precomplete decls = ${self.typeSymbol.unforcedDecls.toList.map(_.denot).mkString("\n ")}") } val tparam = tparams.head val arg1 = diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 141b29ab7..e520ea172 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -895,7 +895,7 @@ object Types { * no symbol it tries `member` as an alternative. */ def typeParamNamed(name: TypeName)(implicit ctx: Context): Symbol = - classSymbol.decls.lookup(name) orElse member(name).symbol + classSymbol.unforcedDecls.lookup(name) orElse member(name).symbol /** If this is a prototype with some ignored component, reveal one more * layer of it. Otherwise the type itself. diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index cc3d3eb7f..a8be0bb94 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -368,7 +368,7 @@ class ClassfileParser( val s = ctx.newSymbol( owner, expname, owner.typeParamCreationFlags, typeParamCompleter(index), coord = indexCoord(index)) - if (owner.isClass) owner.asClass.enter(s, owner.decls) + if (owner.isClass) owner.asClass.enter(s) tparams = tparams + (tpname -> s) sig2typeBounds(tparams, skiptvs = true) newTParams += s @@ -553,12 +553,15 @@ class ClassfileParser( newType } - /** Add a synthetic constructor and potentially also default getters which + /** Add synthetic constructor(s) and potentially also default getters which * reflects the fields of the annotation with given `classInfo`. * Annotations in Scala are assumed to get all their arguments as constructor * parameters. For Java annotations we need to fake it by making up the constructor. * Note that default getters have type Nothing. That's OK because we need * them only to signal that the corresponding parameter is optional. + * If the constructor takes as last parameter an array, it can also accept + * a vararg argument. We solve this by creating two constructors, one with + * an array, the other with a repeated parameter. */ def addAnnotationConstructor(classInfo: Type, tparams: List[Symbol] = Nil)(implicit ctx: Context): Unit = { def addDefaultGetter(attr: Symbol, n: Int) = @@ -574,21 +577,33 @@ class ClassfileParser( case classInfo: TempClassInfoType => val attrs = classInfo.decls.toList.filter(_.isTerm) val targs = tparams.map(_.typeRef) - val methType = MethodType( - attrs.map(_.name.asTermName), - attrs.map(_.info.resultType), - classRoot.typeRef.appliedTo(targs)) - val constr = ctx.newSymbol( + val paramNames = attrs.map(_.name.asTermName) + val paramTypes = attrs.map(_.info.resultType) + + def addConstr(ptypes: List[Type]) = { + val mtype = MethodType(paramNames, ptypes, classRoot.typeRef.appliedTo(targs)) + val constrType = if (tparams.isEmpty) mtype else TempPolyType(tparams, mtype) + val constr = ctx.newSymbol( owner = classRoot.symbol, name = nme.CONSTRUCTOR, flags = Flags.Synthetic, - info = if (tparams.isEmpty) methType else TempPolyType(tparams, methType) + info = constrType ).entered - for ((attr, i) <- attrs.zipWithIndex) - if (attr.hasAnnotation(defn.AnnotationDefaultAnnot)) { - constr.setFlag(Flags.HasDefaultParams) - addDefaultGetter(attr, i) - } + for ((attr, i) <- attrs.zipWithIndex) + if (attr.hasAnnotation(defn.AnnotationDefaultAnnot)) { + constr.setFlag(Flags.HasDefaultParams) + addDefaultGetter(attr, i) + } + } + + addConstr(paramTypes) + if (paramTypes.nonEmpty) + paramTypes.last match { + case defn.ArrayType(elemtp) => + addConstr(paramTypes.init :+ defn.RepeatedParamType.appliedTo(elemtp)) + case _ => + } + } } diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 728048700..f7aef3aaf 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -343,7 +343,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: if (denot.exists && !denot1.exists) { // !!!DEBUG val alts = denot.alternatives map (d => d+":"+d.info+"/"+d.signature) System.err.println(s"!!! disambiguation failure: $alts") - val members = denot.alternatives.head.symbol.owner.decls.toList map (d => d+":"+d.info+"/"+d.signature) + val members = denot.alternatives.head.symbol.owner.info.decls.toList map (d => d+":"+d.info+"/"+d.signature) System.err.println(s"!!! all members: $members") } if (tag == EXTref) sym else sym.moduleClass @@ -445,7 +445,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: ) owner.asClass.enter(sym, symScope(owner)) else if (isRefinementClass(owner)) - symScope(owner).asInstanceOf[MutableScope].enter(sym) + symScope(owner).openForMutations.enter(sym) sym } @@ -475,7 +475,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: val unpickler = new LocalUnpickler() withDecls symScope(cls) if (flags is ModuleClass) unpickler withSourceModule (implicit ctx => - cls.owner.decls.lookup(cls.name.sourceModuleName) + cls.owner.info.decls.lookup(cls.name.sourceModuleName) .suchThat(_ is Module).symbol) else unpickler } @@ -637,7 +637,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: // and also for the inner Transform class in all views. We fix it by // replacing the this with the appropriate super. if (sym.owner != thispre.cls) { - val overriding = thispre.cls.decls.lookup(sym.name) + val overriding = thispre.cls.info.decls.lookup(sym.name) if (overriding.exists && overriding != sym) { val base = pre.baseTypeWithArgs(sym.owner) assert(base.exists) diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index 933252ccd..a0370feca 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -443,7 +443,7 @@ object Erasure extends TypeTestsCasts{ if (isRequired) { // check for clashes - val clash: Option[Symbol] = oldSymbol.owner.decls.lookupAll(bridge.name).find { + val clash: Option[Symbol] = oldSymbol.owner.info.decls.lookupAll(bridge.name).find { sym => (sym.name eq bridge.name) && sym.info.widen =:= bridge.info.widen }.orElse( diff --git a/src/dotty/tools/dotc/transform/LambdaLift.scala b/src/dotty/tools/dotc/transform/LambdaLift.scala index c8dacd1d7..1363615a5 100644 --- a/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -275,7 +275,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform initFlags = local.flags | Private | maybeStatic | maybeNotJavaPrivate, info = liftedInfo(local)).installAfter(thisTransform) if (local.isClass) - for (member <- local.asClass.decls) + for (member <- local.asClass.info.decls) if (member.isConstructor) { val linfo = liftedInfo(member) if (linfo ne member.info) diff --git a/src/dotty/tools/dotc/transform/Mixin.scala b/src/dotty/tools/dotc/transform/Mixin.scala index 230763fae..7e307c736 100644 --- a/src/dotty/tools/dotc/transform/Mixin.scala +++ b/src/dotty/tools/dotc/transform/Mixin.scala @@ -148,13 +148,13 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform => ctx.atPhase(thisTransform) { implicit ctx => sym is Deferred } def traitInits(mixin: ClassSymbol): List[Tree] = - for (getter <- mixin.decls.filter(getr => getr.isGetter && !wasDeferred(getr)).toList) + for (getter <- mixin.info.decls.filter(getr => getr.isGetter && !wasDeferred(getr)).toList) yield { DefDef(implementation(getter.asTerm), superRef(initializer(getter)).appliedToNone) } def setters(mixin: ClassSymbol): List[Tree] = - for (setter <- mixin.decls.filter(setr => setr.isSetter && !wasDeferred(setr)).toList) + for (setter <- mixin.info.decls.filter(setr => setr.isSetter && !wasDeferred(setr)).toList) yield DefDef(implementation(setter.asTerm), unitLiteral.withPos(cls.pos)) cpy.Template(impl)( diff --git a/src/dotty/tools/dotc/transform/OverridingPairs.scala b/src/dotty/tools/dotc/transform/OverridingPairs.scala index bc3c085a9..f631dcf9a 100644 --- a/src/dotty/tools/dotc/transform/OverridingPairs.scala +++ b/src/dotty/tools/dotc/transform/OverridingPairs.scala @@ -53,7 +53,7 @@ object OverridingPairs { def fillDecls(bcs: List[Symbol], deferred: Boolean): Unit = bcs match { case bc :: bcs1 => fillDecls(bcs1, deferred) - var e = bc.info.decls.asInstanceOf[MutableScope].lastEntry + var e = bc.info.decls.lastEntry while (e != null) { if (e.sym.is(Deferred) == deferred && !exclude(e.sym)) decls.enter(e.sym) diff --git a/src/dotty/tools/dotc/transform/ResolveSuper.scala b/src/dotty/tools/dotc/transform/ResolveSuper.scala index 9f952f6de..953c8b74d 100644 --- a/src/dotty/tools/dotc/transform/ResolveSuper.scala +++ b/src/dotty/tools/dotc/transform/ResolveSuper.scala @@ -75,7 +75,7 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th import ops._ def superAccessors(mixin: ClassSymbol): List[Tree] = - for (superAcc <- mixin.decls.filter(_ is SuperAccessor).toList) + for (superAcc <- mixin.info.decls.filter(_ is SuperAccessor).toList) yield polyDefDef(implementation(superAcc.asTerm), forwarder(rebindSuper(cls, superAcc))) def methodOverrides(mixin: ClassSymbol): List[Tree] = { @@ -84,7 +84,7 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th meth.is(Method, butNot = PrivateOrDeferred) && !isOverridden(meth) && !meth.allOverriddenSymbols.forall(_ is Deferred) - for (meth <- mixin.decls.toList if needsDisambiguation(meth)) + for (meth <- mixin.info.decls.toList if needsDisambiguation(meth)) yield polyDefDef(implementation(meth.asTerm), forwarder(meth)) } diff --git a/src/dotty/tools/dotc/transform/SuperAccessors.scala b/src/dotty/tools/dotc/transform/SuperAccessors.scala index f727201b2..0d89e9d74 100644 --- a/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -146,7 +146,7 @@ class SuperAccessors extends MacroTransform with IdentityDenotTransformer { this if (needsExpansion(s)) { ctx.deprecationWarning(s"private qualified with a class has been deprecated, use package enclosing ${s.privateWithin} instead", s.pos) /* disabled for now - decls.asInstanceOf[MutableScope].unlink(s) + decls.openForMutations.unlink(s) s.copySymDenotation(name = s.name.expandedName(s.privateWithin)) .installAfter(thisTransformer) decls1.enter(s)(nextCtx) diff --git a/src/dotty/tools/dotc/transform/SymUtils.scala b/src/dotty/tools/dotc/transform/SymUtils.scala index 9274150b1..0a5854ea7 100644 --- a/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/src/dotty/tools/dotc/transform/SymUtils.scala @@ -80,7 +80,7 @@ class SymUtils(val self: Symbol) extends AnyVal { self.owner.info.decl(name).suchThat(_ is Accessor).symbol def caseAccessors(implicit ctx:Context) = - self.decls.filter(_ is CaseAccessor).toList + self.info.decls.filter(_ is CaseAccessor).toList def getter(implicit ctx: Context): Symbol = if (self.isGetter) self else accessorNamed(self.asTerm.name.getterName) diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 1026bea50..d1f34f3c9 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -27,7 +27,7 @@ trait NamerContextOps { this: Context => def enter(sym: Symbol): Symbol = { ctx.owner match { case cls: ClassSymbol => cls.enter(sym) - case _ => this.scope.asInstanceOf[MutableScope].enter(sym) + case _ => this.scope.openForMutations.enter(sym) } sym } @@ -37,7 +37,7 @@ trait NamerContextOps { this: Context => if (owner.isClass) if (outer.owner == owner) { // inner class scope; check whether we are referring to self if (scope.size == 1) { - val elem = scope.asInstanceOf[MutableScope].lastEntry + val elem = scope.lastEntry if (elem.name == name) return elem.sym.denot // return self } assert(scope.size <= 1, scope) @@ -52,7 +52,7 @@ trait NamerContextOps { this: Context => * the declarations of the current class. */ def effectiveScope: Scope = - if (owner != null && owner.isClass) owner.asClass.decls + if (owner != null && owner.isClass) owner.asClass.unforcedDecls else scope /** The symbol (stored in some typer's symTree) of an enclosing context definition */ @@ -306,7 +306,7 @@ class Namer { typer: Typer => val localCtx: Context = ctx.fresh.setNewScope selfInfo match { case sym: Symbol if sym.exists && sym.name != nme.WILDCARD => - localCtx.scope.asInstanceOf[MutableScope].enter(sym) + localCtx.scope.openForMutations.enter(sym) case _ => } localCtx diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 46aa2e953..f4b0ef4f2 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -43,7 +43,7 @@ trait TypeAssigner { } def apply(tp: Type) = tp match { case tp: TermRef if toAvoid(tp) && variance > 0 => - apply(tp.info) + apply(tp.info.widenExpr) case tp: TypeRef if (forbidden contains tp.symbol) || toAvoid(tp.prefix) => tp.info match { case TypeAlias(ref) => diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 0ff47b36d..dedff0e3a 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -454,7 +454,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def classLeaks(sym: ClassSymbol): Boolean = (ctx.owner is Method) || // can't hoist classes out of method bodies (sym.info.parents exists typeLeaks) || - (sym.decls.toList exists (t => typeLeaks(t.info))) + (sym.info.decls.toList exists (t => typeLeaks(t.info))) leakingTypes(block.tpe) } diff --git a/test/test/DottyTest.scala b/test/test/DottyTest.scala index 90a0154ec..21eebd660 100644 --- a/test/test/DottyTest.scala +++ b/test/test/DottyTest.scala @@ -14,7 +14,7 @@ import dotty.tools.dotc.Compiler import dotty.tools.dotc import dotty.tools.dotc.core.Phases.Phase -class DottyTest extends ContextEscapeDetection{ +class DottyTest /*extends ContextEscapeDetection*/ { dotty.tools.dotc.parsing.Scanners // initialize keywords @@ -36,11 +36,12 @@ class DottyTest extends ContextEscapeDetection{ base.definitions.init(ctx) ctx } - +/* override def getCtx: Context = ctx override def clearCtx() = { ctx = null } +*/ private def compilerWithChecker(phase: String)(assertion:(tpd.Tree, Context) => Unit) = new Compiler { self => override def phases = { diff --git a/tests/pending/pos/annot.scala b/tests/pending/pos/annot.scala deleted file mode 100644 index 8e21803b4..000000000 --- a/tests/pending/pos/annot.scala +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - - @SuppressWarnings("hi") def foo() = ??? - -} diff --git a/tests/pos/annot-bootstrap.scala b/tests/pos/annot-bootstrap.scala new file mode 100644 index 000000000..bef877dcd --- /dev/null +++ b/tests/pos/annot-bootstrap.scala @@ -0,0 +1,8 @@ +package scala.annotation.unchecked + +// note: if the case class is not inside an object, the error disappears +object test { + case class L(a: Int) +} + +final class uncheckedVariance extends scala.annotation.StaticAnnotation {} diff --git a/tests/pos/annot.scala b/tests/pos/annot.scala index ab80aba27..c3a17ff1d 100644 --- a/tests/pos/annot.scala +++ b/tests/pos/annot.scala @@ -2,11 +2,11 @@ import java.beans.Transient class Test { - @SuppressWarnings(Array("hi")) def foo() = ??? // evalutation of annotation on type cannot be deffered as requires implicit resolution(only generic Array$.apply applies here) + @SuppressWarnings(Array("hi")) def foo() = ??? // evalutation of annotation on type cannot be deferred as requires implicit resolution(only generic Array$.apply applies here) - @SuppressWarnings(Array("hi", "foo")) def foo2() = ??? //can be deffered as there is a non-generic method + @SuppressWarnings(Array("hi", "foo")) def foo2() = ??? //can be deferred as there is a non-generic method -// @SuppressWarnings("hi") def foo3() = ??? // can be written in java and is serialized this way in bytecode. doesn't typecheck + @SuppressWarnings("hi") def foo3() = ??? // can be written in java and is serialized this way in bytecode. doesn't typecheck @Transient(false) def bar = ??? diff --git a/tests/pos/i0306.scala b/tests/pos/i0306.scala new file mode 100644 index 000000000..5a242fa83 --- /dev/null +++ b/tests/pos/i0306.scala @@ -0,0 +1,17 @@ +object bar { + + class C[T <: Seq[_]] + + val x: AnyRef = new C + + val y = x match { + case x: C[u] => + def xx: u = xx + xx + } + + val z= { + def xx: String = xx + xx + } +} |