diff options
author | Martin Odersky <odersky@gmail.com> | 2006-02-01 13:21:09 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-02-01 13:21:09 +0000 |
commit | c9a4b1fd73e4900814f32fca4c740aa027036230 (patch) | |
tree | 8def0dad1e08cf73c3ad074b6476e457d1b1c684 | |
parent | dc4e5a3fbd5e524c57cc9651cc4b7043ea110150 (diff) | |
download | scala-c9a4b1fd73e4900814f32fca4c740aa027036230.tar.gz scala-c9a4b1fd73e4900814f32fca4c740aa027036230.tar.bz2 scala-c9a4b1fd73e4900814f32fca4c740aa027036230.zip |
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 16 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 22 |
2 files changed, 16 insertions, 22 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index a435b2a2b2..0a6b09ac3f 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -30,7 +30,6 @@ import symtab.Flags._; abstract class UnCurry extends InfoTransform { import global._; // the global environment import definitions._; // standard classes and methods - import typer.{typed}; // methods to type trees import posAssigner.atPos; // for filling in tree positions val phaseName: String = "uncurry"; @@ -68,6 +67,7 @@ abstract class UnCurry extends InfoTransform { private var needTryLift = false; private var inPattern = false; private var inConstructorFlag = 0L; + private var localTyper: analyzer.Typer = typer; override def transform(tree: Tree): Tree = try { //debug postTransform(mainTransform(tree)); @@ -156,7 +156,7 @@ abstract class UnCurry extends InfoTransform { } members = DefDef(isDefinedAtMethod, vparamss => idbody(vparamss.head.head)) :: members; } - typer.atOwner(currentOwner).typed { + localTyper.atOwner(currentOwner).typed { atPos(fun.pos) { Block( List(ClassDef(anonClass, List(List()), List(List()), members)), @@ -192,7 +192,7 @@ abstract class UnCurry extends InfoTransform { if (formal.symbol != ByNameParamClass) arg else if (isByNameRef(arg)) arg setType functionType(List(), arg.tpe) else { - val fun = typer.atOwner(currentOwner).typed( + val fun = localTyper.atOwner(currentOwner).typed( Function(List(), arg) setPos arg.pos).asInstanceOf[Function]; new ChangeOwnerTraverser(currentOwner, fun.symbol).traverse(arg); transformFunction(fun) @@ -277,7 +277,7 @@ abstract class UnCurry extends InfoTransform { sym.setInfo(MethodType(List(), tree.tpe)); new ChangeOwnerTraverser(currentOwner, sym).traverse(tree); - transform(typed(atPos(tree.pos)( + transform(localTyper.typed(atPos(tree.pos)( Block(List(DefDef(sym, List(List()), tree)), Apply(Ident(sym), Nil))))) } else @@ -293,12 +293,16 @@ abstract class UnCurry extends InfoTransform { mainTransform(transformFunction(fun)) case Template(_, _) => - withInConstructorFlag(0) { super.transform(tree) } + val savedLocalTyper = localTyper; + localTyper = localTyper.atOwner(tree, currentOwner); + val tree1 = withInConstructorFlag(0) { super.transform(tree) } + localTyper = savedLocalTyper; + tree1 case _ => val tree1 = super.transform(tree); if (isByNameRef(tree1)) - typed(atPos(tree1.pos)( + localTyper.typed(atPos(tree1.pos)( Apply(Select(tree1 setType functionType(List(), tree1.tpe), nme.apply), List()))) else tree1; } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index aff80d4812..87ddef778e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -534,9 +534,6 @@ mixin class Typers requires Analyzer { * - no two parents define same symbol. */ def validateParentClasses(parents: List[Tree], selfType: Type): unit = { - var c = context - do { c = c.outer } while (c.owner == context.owner) - val defscope = c.scope def validateParentClass(parent: Tree, isFirst: boolean): unit = if (!parent.tpe.isError) { @@ -550,20 +547,13 @@ mixin class Typers requires Analyzer { error(parent.pos, ""+psym+" is not declared to be a mixin class") else if (psym.hasFlag(FINAL)) error(parent.pos, "illegal inheritance from final class") - else if (psym.isSealed && !phase.erasedTypes) { - // are we in same scope as base type definition? - val e = defscope.lookupEntry(psym.name) - if (c.owner.isPackageClass || !(e != null && e.sym == psym && e.owner == defscope)) { - // we are not within same statement sequence - var c = context - while (c != NoContext && c.owner != psym) c = c.outer.enclClass - if (c == NoContext) error(parent.pos, "illegal inheritance from sealed "+psym) - } - } + else if (!phase.erasedTypes && psym.isSealed && + context.unit.source.file != psym.sourceFile) + error(parent.pos, "illegal inheritance from sealed "+psym) if (!(selfType <:< parent.tpe.typeOfThis) && !phase.erasedTypes) { - System.out.println(context.owner);//debug - System.out.println(context.owner.unsafeTypeParams);//debug - System.out.println(List.fromArray(context.owner.info.closure));//debug + //System.out.println(context.owner);//DEBUG + //System.out.println(context.owner.unsafeTypeParams);//DEBUG + //System.out.println(List.fromArray(context.owner.info.closure));//DEBUG error(parent.pos, "illegal inheritance;\n self-type "+ selfType+" does not conform to "+parent + "'s selftype "+parent.tpe.typeOfThis) |