aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-12-05 12:05:49 +0100
committerMartin Odersky <odersky@gmail.com>2013-12-05 12:05:49 +0100
commitc2f101a33ea7f89681d6b74731bbcff948e7e6da (patch)
tree52a67e7ea6001944ac2216c6e55e9dad9fe0b42f /src/dotty/tools/dotc/typer
parent8bb6ccae5c4f3ec91877fcfe032902f92aa5d2b4 (diff)
downloaddotty-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')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala35
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala21
2 files changed, 29 insertions, 27 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)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 6f5739396..fd97c2c22 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -619,18 +619,10 @@ class Typer extends Namer with Applications with Implicits {
}
def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree = track("typedTypeTree") {
- val (original1, ownType) = tree.original match {
- case untpd.EmptyTree =>
- assert(isFullyDefined(pt, ForceDegree.none))
- (EmptyTree, pt)
- case original: ValDef =>
- val meth = original.symbol // ??? was: symbolOfTree(original) TODO: come back to this
- assert(meth.exists, meth)
- (EmptyTree, meth.info)
- case original =>
- val original1 = typed(original)
- (original1, original1.tpe)
- }
+ val original1 = typed(tree.original)
+ val ownType =
+ if (tree.original.isEmpty) { assert(isFullyDefined(pt, ForceDegree.none)); pt }
+ else original1.tpe
cpy.TypeTree(tree, original1) withType ownType
}
@@ -1011,9 +1003,10 @@ class Typer extends Namer with Applications with Implicits {
noMatches
}
case alts =>
+ def all = if (altDenots.length == 2) "both" else "all"
errorTree(tree,
- i"""Ambiguous overload. The ${err.overloadedAltsStr(altDenots take 2)}
- |both match $expectedStr""".stripMargin)
+ i"""Ambiguous overload. The ${err.overloadedAltsStr(altDenots)}
+ |$all match $expectedStr""".stripMargin)
}
}