diff options
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 23 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 11 |
2 files changed, 16 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 18a26e0cf..0b8c1ada2 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -104,7 +104,7 @@ class Namer { typer: Typer => def privateWithinClass(mods: Modifiers) = enclosingClassNamed(mods.privateWithin, mods.pos) val sym = tree match { - case tree: ClassDef => + case tree: TypeDef if tree.isClassDef => ctx.enter(ctx.newClassSymbol( ctx.owner, tree.name, tree.mods.flags, new Completer(tree), privateWithinClass(tree.mods), tree.pos, ctx.source.file)) @@ -166,17 +166,17 @@ class Namer { typer: Typer => * and the real companion, if both exist. */ def mergeCompanionDefs() = { - val caseClassDef = mutable.Map[TypeName, ClassDef]() - for (cdef @ ClassDef(mods, name, _) <- stats) + val caseClassDef = mutable.Map[TypeName, TypeDef]() + for (cdef @ TypeDef(mods, name, _) <- stats) if (mods is Case) caseClassDef(name) = cdef for (mdef @ ModuleDef(_, name, _) <- stats) caseClassDef get name.toTypeName match { case Some(cdef) => - val Thicket((mcls @ ClassDef(_, _, impl)) :: mrest) = expandedTree(mdef) - val Thicket(cls :: (companion: ClassDef) :: crest) = expandedTree(cdef) - val mcls1 = mcls.derivedClassDef(mcls.mods, mcls.name, + val Thicket((mcls @ TypeDef(_, _, impl: Template)) :: mrest) = expandedTree(mdef) + val Thicket(cls :: TypeDef(_, _, compimpl: Template) :: crest) = expandedTree(cdef) + val mcls1 = mcls.derivedTypeDef(mcls.mods, mcls.name, impl.derivedTemplate(impl.constr, impl.parents, impl.self, - companion.impl.body ++ impl.body)) + compimpl.body ++ impl.body)) expandedTree(mdef) = Thicket(mcls1 :: mrest) expandedTree(cdef) = Thicket(cls :: crest) case none => @@ -203,9 +203,8 @@ class Namer { typer: Typer => nestedTyper(sym) = typer1 typer1.defDefSig(tree, sym)(localContext.withTyper(typer1)) case tree: TypeDef => - typeDefSig(tree, sym)(localContext.withNewScope) - case tree: ClassDef => - classDefSig(tree, sym.asClass)(localContext) + if (tree.isClassDef) classDefSig(tree, sym.asClass)(localContext) + else typeDefSig(tree, sym)(localContext.withNewScope) case imp: Import => val expr1 = typedAhead(imp.expr) ImportType(SharedTree(expr1)) @@ -298,7 +297,7 @@ class Namer { typer: Typer => } /** The type signature of a ClassDef with given symbol */ - def classDefSig(cdef: ClassDef, cls: ClassSymbol)(implicit ctx: Context): Type = { + def classDefSig(cdef: TypeDef, cls: ClassSymbol)(implicit ctx: Context): Type = { def parentType(constr: untpd.Tree): Type = { val Trees.Select(Trees.New(tpt), _) = TreeInfo.methPart(constr) @@ -307,7 +306,7 @@ class Namer { typer: Typer => else typedAhead(constr, Mode.Expr).tpe } - val ClassDef(_, _, impl @ Template(_, parents, self, body)) = cdef + val TypeDef(_, _, impl @ Template(_, parents, self, body)) = cdef val decls = newScope val (params, rest) = body span { diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 1b3c2f22b..0d78e070d 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -48,8 +48,8 @@ class Typer extends Namer { tdef.withType(sym.symRef).derivedTypeDef(mods1, name, rhs1) } - def typedClassDef(cdef: untpd.ClassDef, cls: ClassSymbol)(implicit ctx: Context) = { - val Trees.ClassDef(mods, name, impl @ Template(constr, parents, self, body)) = cdef + def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(implicit ctx: Context) = { + val Trees.TypeDef(mods, name, impl @ Template(constr, parents, self, body)) = cdef val mods1 = typedModifiers(mods) val constr1 = typed(constr).asInstanceOf[DefDef] val parents1 = parents mapconserve (typed(_)) @@ -61,7 +61,7 @@ class Typer extends Namer { val impl1 = impl.withType(localDummy.symRef).derivedTemplate( constr1, parents1, self1, body1) - cdef.withType(cls.symRef).derivedClassDef(mods1, name, impl1) + cdef.withType(cls.symRef).derivedTypeDef(mods1, name, impl1) // todo later: check that // 1. If class is non-abstract, it is instantiatable: @@ -90,9 +90,8 @@ class Typer extends Namer { val typer1 = nestedTyper.remove(sym).get typer1.typedDefDef(tree, sym)(localContext.withTyper(typer1)) case tree: untpd.TypeDef => - typedTypeDef(tree, sym)(localContext.withNewScope) - case tree: untpd.ClassDef => - typedClassDef(tree, sym.asClass)(localContext) + if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext) + else typedTypeDef(tree, sym)(localContext.withNewScope) case tree: untpd.Import => typedImport(tree, sym) case tree: untpd.TypeTree => |