diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-05 12:05:49 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-05 12:05:49 +0100 |
commit | c2f101a33ea7f89681d6b74731bbcff948e7e6da (patch) | |
tree | 52a67e7ea6001944ac2216c6e55e9dad9fe0b42f /src/dotty/tools/dotc/typer/Namer.scala | |
parent | 8bb6ccae5c4f3ec91877fcfe032902f92aa5d2b4 (diff) | |
download | dotty-c2f101a33ea7f89681d6b74731bbcff948e7e6da.tar.gz dotty-c2f101a33ea7f89681d6b74731bbcff948e7e6da.tar.bz2 dotty-c2f101a33ea7f89681d6b74731bbcff948e7e6da.zip |
Changes to Desugar and Namer.
In particular: Changed the scheme to represent the types of setter parameters.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 66d238614..bcdb4a43f 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -18,6 +18,11 @@ import language.implicitConversions trait NamerContextOps { this: Context => + /** Enter symbol into current class, if current class is owner of current context, + * or into current scope, if not. Should always be called instead of scope.enter + * in order to make sure that updates to class members are reflected in + * finger prints. + */ def enter(sym: Symbol): Symbol = { ctx.owner match { case cls: ClassSymbol => cls.enter(sym) @@ -26,6 +31,7 @@ trait NamerContextOps { this: Context => sym } + /** The denotation with the given name in current context */ def denotNamed(name: Name): Denotation = if (owner.isClass) if (outer.owner == owner) @@ -35,12 +41,15 @@ trait NamerContextOps { this: Context => else scope.denotsNamed(name).toDenot(NoPrefix) - def effectiveScope = + /** Either the current scope, or, if the current context owner is a class, + * the declarations of the current class. + */ + def effectiveScope: Scope = if (owner != null && owner.isClass) owner.asClass.decls else scope } -/** This class attaches creates symbols from definitions and imports and gives them +/** This class creates symbols from definitions and imports and gives them * lazy types. * * Timeline: @@ -64,7 +73,6 @@ class Namer { typer: Typer => import untpd._ - /** A partial map from unexpanded member and pattern defs and to their expansions. * Populated during enterSyms, emptied during typer. */ @@ -186,7 +194,7 @@ class Namer { typer: Typer => sym } - /** All PackageClassInfoTypes come from here. */ + /** Create package if it does not yet exist. */ private def createPackageSymbol(pid: RefTree)(implicit ctx: Context): Symbol = { val pkgOwner = pid match { case Ident(_) => if (ctx.owner eq defn.EmptyPackageClass) defn.RootClass else ctx.owner @@ -242,12 +250,6 @@ class Namer { typer: Typer => /** Create top-level symbols for statements and enter them into symbol table */ def index(stats: List[Tree])(implicit ctx: Context): Context = { - @tailrec def traverse(stats: List[Tree])(implicit ctx: Context): Context = stats match { - case stat :: stats1 => - traverse(stats1)(index(stat)) - case nil => - ctx - } /** Merge the definitions of a synthetic companion generated by a case class * and the real companion, if both exist. @@ -270,7 +272,7 @@ class Namer { typer: Typer => } } - val result = traverse(stats) + val result = (ctx /: stats) ((ctx, stat) => index(stat)(ctx)) mergeCompanionDefs() result } @@ -377,9 +379,16 @@ class Namer { typer: Typer => lazy val schema = paramFn(WildcardType) val site = sym.owner.thisType val inherited = { - // TODO: Look only at member of supertype instead? - if (sym.owner.isTerm) NoType + if ((sym is Param) && sym.owner.isSetter) { // fill in type from getter result type + val getterCtx = ctx.outersIterator + .dropWhile(_.owner != sym.owner) + .dropWhile(_.owner == sym.owner) + .next + getterCtx.denotNamed(sym.owner.asTerm.name.setterToGetter).info.widenExpr + } + else if (sym.owner.isTerm) NoType else + // TODO: Look only at member of supertype instead? ((NoType: Type) /: sym.owner.info.baseClasses.tail) { (tp, cls) => val itpe = cls.info .nonPrivateDecl(sym.name) |