diff options
-rw-r--r-- | build.xml | 22 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 20 | ||||
-rw-r--r-- | src/library/scala/package.scala | 2 | ||||
-rw-r--r-- | src/library/scala/util/control/Breaks.scala | 25 | ||||
-rwxr-xr-x | test/files/pos/t2545.scala | 10 |
9 files changed, 93 insertions, 21 deletions
@@ -523,7 +523,20 @@ QUICK BUILD (QUICK) params="${scalac.args.quick}" srcdir="${src.dir}/swing" jvmargs="${scalacfork.jvmargs}"> + <include name="scala/swing/package.scala"/> + <compilationpath> + <pathelement location="${build-quick.dir}/classes/library"/> + </compilationpath> + </scalacfork> + <scalacfork + destdir="${build-quick.dir}/classes/library" + compilerpathref="locker.classpath" + srcpath="${src.dir}/library" + params="${scalac.args.quick}" + srcdir="${src.dir}/swing" + jvmargs="${scalacfork.jvmargs}"> <include name="**/*.scala"/> + <exclude name="scala/swing/package.scala"/> <compilationpath> <pathelement location="${build-quick.dir}/classes/library"/> </compilationpath> @@ -969,7 +982,16 @@ BOOTSTRAPPING BUILD (STRAP) classpath="${build-strap.dir}/classes/library" target="jvm-1.5" addparams="${scalac.args.all}"> + <include name="scala/swing/package.scala"/> + </scalac> + <scalac + srcdir="${src.dir}/swing" + destdir="${build-strap.dir}/classes/library" + classpath="${build-strap.dir}/classes/library" + target="jvm-1.5" + addparams="${scalac.args.all}"> <include name="**/*.scala"/> + <exclude name="scala/swing/package.scala"/> </scalac> <propertyfile file="${build-strap.dir}/classes/library/library.properties"> <entry key="version.number" value="${version.number}"/> diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index db5c2f2afe..bca52c1d44 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -240,6 +240,20 @@ abstract class TreeGen } // var m$: T = null; or, if class member: local var m$: T = _; + /*!!! + def mkModuleValDef(accessor: Symbol) = { + val mval = accessor.owner.newValue(accessor.pos.focus, nme.moduleVarName(accessor.name)) + .setInfo(accessor.tpe.finalResultType) + .setFlag(LAZY); + if (mval.owner.isClass) { + mval setFlag (PRIVATE | LOCAL | SYNTHETIC) + mval.owner.info.decls.enter(mval) + } + ValDef(mval, New(TypeTree(mval.tpe), List(List()))) + } + */ + + // var m$: T = null; or, if class member: local var m$: T = _; def mkModuleVarDef(accessor: Symbol) = { val mvar = accessor.owner.newVariable(accessor.pos.focus, nme.moduleVarName(accessor.name)) .setInfo(accessor.tpe.finalResultType) diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index 6a6b25cb99..d55b0bf957 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -164,9 +164,10 @@ abstract class SymbolLoaders { // if there's a $member object, enter its members as well. val pkgModule = root.info.decl(nme.PACKAGEkw) - if (pkgModule.isModule && !(pkgModule.rawInfo.isInstanceOf[SourcefileLoader] && - classpath.name == "scala")) + if (pkgModule.isModule && !pkgModule.rawInfo.isInstanceOf[SourcefileLoader]) { + //println("open "+pkgModule)//DEBUG openPackageModule(pkgModule) + } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 7360a9e07f..d4a7b9e1e7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -359,9 +359,6 @@ trait Namers { self: Analyzer => tree.symbol = enterModuleSymbol(tree) tree.symbol.moduleClass.setInfo(namerOf(tree.symbol).moduleClassTypeCompleter((tree))) finish - if (tree.symbol.name == nme.PACKAGEkw && tree.symbol.owner != ScalaPackageClass) { - loaders.openPackageModule(tree.symbol) - } case vd @ ValDef(mods, name, tp, rhs) => if ((!context.owner.isClass || @@ -392,7 +389,7 @@ trait Namers { self: Analyzer => if (mods.isDeferred) { getter setPos tree.pos // unfocus getter position, because there won't be a separate value } else { - var vsym = + val vsym = if (!context.owner.isClass) { assert(mods.isLazy) // if not a field, it has to be a lazy val owner.newValue(tree.pos, name + "$lzy" ).setFlag(mods.flags | MUTABLE) @@ -1132,14 +1129,13 @@ trait Namers { self: Analyzer => newNamer(context.makeNewScope(tree, sym)).classSig(tparams, impl) case ModuleDef(_, _, impl) => - /** no, does not work here. - if (tree.symbol.name == nme.PACKAGEkw) { - loaders.openPackageModule(tree.symbol) - } - */ val clazz = sym.moduleClass clazz.setInfo(newNamer(context.makeNewScope(tree, clazz)).templateSig(impl)) //clazz.typeOfThis = singleType(sym.owner.thisType, sym); + tree.symbol.setInfo(clazz.tpe) // initialize module to avoid cycles + if (tree.symbol.name == nme.PACKAGEkw) { + loaders.openPackageModule(tree.symbol) + } clazz.tpe case DefDef(mods, _, tparams, vparamss, tpt, rhs) => diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 7a074aad5c..d273af60c5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -780,7 +780,7 @@ abstract class RefChecks extends InfoTransform { val cdef = ClassDef(mods | MODULE, name, List(), impl) .setPos(tree.pos) .setSymbol(sym.moduleClass) - .setType(NoType); + .setType(NoType) if (sym.isStatic) { if (!sym.allOverriddenSymbols.isEmpty) { val factory = sym.owner.newMethod(sym.pos, sym.name) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 31bddb55d2..2b3a8561d8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1420,10 +1420,17 @@ trait Typers { self: Analyzer => templ setSymbol clazz.newLocalDummy(templ.pos) val self1 = templ.self match { case vd @ ValDef(mods, name, tpt, EmptyTree) => - val tpt1 = checkNoEscaping.privates(clazz.thisSym, typedType(tpt)) + val tpt1 = + checkNoEscaping.privates( + clazz.thisSym, + treeCopy.TypeTree(tpt) setType vd.symbol.tpe) treeCopy.ValDef(vd, mods, name, tpt1, EmptyTree) setType NoType } - if (self1.name != nme.WILDCARD) context.scope enter self1.symbol +// was: +// val tpt1 = checkNoEscaping.privates(clazz.thisSym, typedType(tpt)) +// treeCopy.ValDef(vd, mods, name, tpt1, EmptyTree) setType NoType +// but this leads to cycles for existential self types ==> #2545 + if (self1.name != nme.WILDCARD) context.scope enter self1.symbol val selfType = if (clazz.isAnonymousClass && !phase.erasedTypes) intersectionType(clazz.info.parents, clazz.owner) @@ -2944,13 +2951,18 @@ trait Typers { self: Analyzer => .setOriginal(tpt1) .setType(appliedType(tpt1.tpe, context.undetparams map (_.tpe))) } + /** If current tree <tree> appears in <val x(: T)? = <tree>> * return `tp with x.type' else return `tp'. */ def narrowRhs(tp: Type) = { var sym = context.tree.symbol - if (sym != null && sym != NoSymbol && sym.owner.isClass && sym.getter(sym.owner) != NoSymbol) - sym = sym.getter(sym.owner) + if (sym != null && sym != NoSymbol) + if (sym.owner.isClass) { + if (sym.getter(sym.owner) != NoSymbol) sym = sym.getter(sym.owner) + } else if (sym hasFlag LAZY) { + if (sym.lazyAccessor != NoSymbol) sym = sym.lazyAccessor + } context.tree match { case ValDef(mods, _, _, Apply(Select(`tree`, _), _)) if !(mods hasFlag MUTABLE) => val pre = if (sym.owner.isClass) sym.owner.thisType else NoPrefix diff --git a/src/library/scala/package.scala b/src/library/scala/package.scala index 230d664f06..34ba3c1ff2 100644 --- a/src/library/scala/package.scala +++ b/src/library/scala/package.scala @@ -11,7 +11,7 @@ package object scala { - type Travarsable[+A] = scala.collection.Traversable[A] + type Traversable[+A] = scala.collection.Traversable[A] val Traversable = scala.collection.Traversable type Iterable[+A] = scala.collection.Iterable[A] diff --git a/src/library/scala/util/control/Breaks.scala b/src/library/scala/util/control/Breaks.scala index 25adf80573..6e7f4d6267 100644 --- a/src/library/scala/util/control/Breaks.scala +++ b/src/library/scala/util/control/Breaks.scala @@ -11,10 +11,11 @@ package scala.util.control -/** An object that can be used for the break control abstraction. +/** A class that can be instantiated for the break control abstraction. * Example usage:<pre> * - * <b>import</b> Breaks.{break, breakable} + * val mybreaks = new Breaks + * import</b> mybreaks.{break, breakable} * * breakable { * <b>for</b> (...) { @@ -22,6 +23,8 @@ package scala.util.control * } * }</pre> * + * Calls to break from one instantiation of Breaks will never + * target breakable objects of some other instantion. */ class Breaks { @@ -37,11 +40,25 @@ class Breaks { } } - /* Break from closest enclosing breakable block */ + /* Break from dynamically closest enclosing breakable block + * @note this might be different than the statically closest enclosing + * block! + */ def break { throw breakException } } -/** A singleton object providing the Break functionality */ +/** An object that can be used for the break control abstraction. + * Example usage:<pre> + * + * <b>import</b> Breaks.{break, breakable} + * + * breakable { + * <b>for</b> (...) { + * <b>if</b> (...) break + * } + * }</pre> + * + */ object Breaks extends Breaks private class BreakException extends RuntimeException with ControlException diff --git a/test/files/pos/t2545.scala b/test/files/pos/t2545.scala new file mode 100755 index 0000000000..6ad994223c --- /dev/null +++ b/test/files/pos/t2545.scala @@ -0,0 +1,10 @@ +trait Frog[T] { + def hello: T + def size: Int + } + + trait OnlyWithFrogs { + self: Frog[_] => + + def sizeStr = size.toString + } |