aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-01 13:17:05 +0100
committerMartin Odersky <odersky@gmail.com>2014-03-01 13:41:00 +0100
commitd8356b6dc9221bfc38b1f167e5cfafcc9261f3d7 (patch)
tree3bb6fda0feb33680f68f61908a7076162159701e /src/dotty/tools/dotc/typer/Namer.scala
parent5a8f4c822be82e23a0c230071673425423664442 (diff)
downloaddotty-d8356b6dc9221bfc38b1f167e5cfafcc9261f3d7.tar.gz
dotty-d8356b6dc9221bfc38b1f167e5cfafcc9261f3d7.tar.bz2
dotty-d8356b6dc9221bfc38b1f167e5cfafcc9261f3d7.zip
Reorganization of template parents.
Template parents always were constructor calls before. This is not correct because in a situation like the one elaborated in templateParents, the trait D has the class C as supertype, but it does not call its constructor (in fact, if we added a () parameter list to make it into a constructor this would be wrong because C takes parameters. Now parents can be either types or constructor calls. The logic in Namer and Typer that deals with parents is cleaned up. In particular, we now construct any synthetic class parent as a full type, before calling normalizeToClassRefs. This obviates the forwardRefs logic that needed to be done in a cleanup of Namers. Also added two more checks: (1) All parents except the first one must point to traits. (2) A trait may not call a parent class constructor.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 4f4e8300e..019432c61 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -409,11 +409,11 @@ class Namer { typer: Typer =>
/** The type of a parent constructor. Types constructor arguments
* only if parent type contains uninstantiated type parameters.
*/
- def parentType(constr: untpd.Tree)(implicit ctx: Context): Type =
- if (constr.isType) { // this case applies to desugared refined types
- typedAheadType(constr).tpe
+ def parentType(parent: untpd.Tree)(implicit ctx: Context): Type =
+ if (parent.isType) {
+ typedAheadType(parent).tpe
} else {
- val (core, targs) = stripApply(constr) match {
+ val (core, targs) = stripApply(parent) match {
case TypeApply(core, targs) => (core, targs)
case core => (core, Nil)
}
@@ -421,29 +421,27 @@ class Namer { typer: Typer =>
val targs1 = targs map (typedAheadType(_))
val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes
if (ptype.uninstantiatedTypeParams.isEmpty) ptype
- else typedAheadExpr(constr).tpe
+ else typedAheadExpr(parent).tpe
}
+ def checkedParentType(parent: untpd.Tree): Type = {
+ val ptype = parentType(parent)(ctx.fresh addMode Mode.InSuperCall)
+ checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head)
+ }
+
val selfInfo =
if (self.isEmpty) NoType
else if (cls is Module) cls.owner.thisType select sourceModule
else createSymbol(self)
// pre-set info, so that parent types can refer to type params
denot.info = ClassInfo(cls.owner.thisType, cls, Nil, decls, selfInfo)
- val parentTypes = parents map (parentType(_)(ctx.fresh addMode Mode.InSuperCall))
+ val parentTypes = ensureFirstIsClass(parents map checkedParentType)
val parentRefs = ctx.normalizeToClassRefs(parentTypes, cls, decls)
- val parentClsRefs =
- for ((parentRef, constr) <- parentRefs zip parents)
- yield checkClassTypeWithStablePrefix(parentRef, constr.pos)
- val normalizedParentClsRefs = ensureFirstIsClass(parentClsRefs)
+ typr.println(s"completing $denot, parents = $parents, parentTypes = $parentTypes, parentRefs = $parentRefs")
index(constr)
index(rest)(inClassContext(selfInfo))
- denot.info = ClassInfo(cls.owner.thisType, cls, normalizedParentClsRefs, decls, selfInfo)
- if (parentClsRefs ne normalizedParentClsRefs) {
- forwardTypeParams(normalizedParentClsRefs.head.symbol.asClass, cls, decls)
- typr.println(i"expanded parents of $denot: $normalizedParentClsRefs%, %")
- }
+ denot.info = ClassInfo(cls.owner.thisType, cls, parentRefs, decls, selfInfo)
}
}