diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-17 15:53:34 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-17 15:53:34 +0100 |
commit | ab4ae7ada45201684c91550815f85a2cfab24e34 (patch) | |
tree | c78d457afb4d8e1e4cbbd9dd02f4ca416b60db5d /src | |
parent | e3fdf97df2ce1ea7cd3a98cbdcce53789db1b3d3 (diff) | |
download | dotty-ab4ae7ada45201684c91550815f85a2cfab24e34.tar.gz dotty-ab4ae7ada45201684c91550815f85a2cfab24e34.tar.bz2 dotty-ab4ae7ada45201684c91550815f85a2cfab24e34.zip |
Fixes to desugaring and indexing package objects
Plus some small tweaks in Typer
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 24 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 15 |
3 files changed, 25 insertions, 21 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 267e1a607..2e1aa48bf 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -305,16 +305,20 @@ object desugar { */ def moduleDef(mdef: ModuleDef)(implicit ctx: Context): Tree = { val ModuleDef(mods, name, tmpl @ Template(constr, parents, self, body)) = mdef - val clsName = name.moduleClassName - val clsRef = Ident(clsName) - val modul = ValDef(mods | ModuleCreationFlags, name, clsRef, New(clsRef, Nil)) withPos mdef.pos - val ValDef(selfMods, selfName, selfTpt, selfRhs) = self - if (!selfTpt.isEmpty) ctx.error("object definition may not have a self type", self.pos) - val clsSelf = ValDef(selfMods, selfName, SingletonTypeTree(Ident(name)), selfRhs) - .withPos(self.pos orElse tmpl.pos.startPos) - val clsTmpl = cpy.Template(tmpl, constr, parents, clsSelf, body) - val cls = TypeDef(mods.toTypeFlags & AccessFlags | ModuleClassCreationFlags, clsName, clsTmpl) - Thicket(modul, classDef(cls)) + if (mods is Package) + PackageDef(Ident(name), cpy.ModuleDef(mdef, mods &~ Package, nme.PACKAGE, tmpl) :: Nil) + else { + val clsName = name.moduleClassName + val clsRef = Ident(clsName) + val modul = ValDef(mods | ModuleCreationFlags, name, clsRef, New(clsRef, Nil)) withPos mdef.pos + val ValDef(selfMods, selfName, selfTpt, selfRhs) = self + if (!selfTpt.isEmpty) ctx.error("object definition may not have a self type", self.pos) + val clsSelf = ValDef(selfMods, selfName, SingletonTypeTree(Ident(name)), selfRhs) + .withPos(self.pos orElse tmpl.pos.startPos) + val clsTmpl = cpy.Template(tmpl, constr, parents, clsSelf, body) + val cls = TypeDef(mods.toTypeFlags & AccessFlags | ModuleClassCreationFlags, clsName, clsTmpl) + Thicket(modul, classDef(cls)) + } } /** val p1, ..., pN: T = E diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 3e39c3926..e0b9c399f 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -265,7 +265,7 @@ class Namer { typer: Typer => /** Create top-level symbols for all statements in the expansion of this statement and * enter them into symbol table */ - def indexExpanded(stat: Tree)(implicit ctx: Context): Context = stat match { + def indexExpanded(stat: Tree)(implicit ctx: Context): Context = expanded(stat) match { case pcl: PackageDef => val pkg = createPackageSymbol(pcl.pid) index(pcl.stats)(ctx.fresh.withOwner(pkg.moduleClass)) @@ -273,7 +273,10 @@ class Namer { typer: Typer => case imp: Import => importContext(createSymbol(imp), imp.selectors) case mdef: DefTree => - expandedTree(mdef).toList foreach (tree => enterSymbol(createSymbol(tree))) + enterSymbol(createSymbol(mdef)) + ctx + case stats: Thicket => + for (tree <- stats.toList) enterSymbol(createSymbol(tree)) ctx case _ => ctx diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f590b7b87..df0757da2 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1009,25 +1009,22 @@ class Typer extends Namer with Applications with Implicits { val altDenots = ref.denot.alternatives println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%, %") val alts = altDenots map (alt => - TermRef.withSig(ref.prefix, ref.name, alt.info.signature).withDenot(alt)) + TermRef.withSig(ref.prefix, ref.name, alt.info.signature, alt)) def expectedStr = err.expectedTypeStr(pt) resolveOverloaded(alts, pt)(ctx.fresh.withExploreTyperState) match { case alt :: Nil => - adaptInterpolated(tree.withType(alt), pt) + adapt(tree.withType(alt), pt) case Nil => def noMatches = errorTree(tree, i"""none of the ${err.overloadedAltsStr(altDenots)} |match $expectedStr""".stripMargin) - def hasEmptyParams(denot: SingleDenotation) = denot.info.paramTypess match { - case Nil :: _ => true - case _ => false - } + def hasEmptyParams(denot: SingleDenotation) = denot.info.paramTypess == ListOfNil pt match { case pt: FunProto => tryInsertApply(tree, pt)((_, _) => noMatches) case _ => - if (altDenots exists hasEmptyParams) + if (altDenots exists (_.info.paramTypess == ListOfNil)) typed(untpd.Apply(untpd.TypedSplice(tree), Nil), pt) else noMatches @@ -1071,7 +1068,7 @@ class Typer extends Namer with Applications with Implicits { } } adapt(tpd.Apply(tree, args), wtp.resultType) - case wtp: MethodType if !pt.isInstanceOf[SingletonType] => + case wtp: MethodType if !pt.isInstanceOf[SingletonType] => if ((defn.isFunctionType(pt) || (pt eq AnyFunctionProto)) && !tree.symbol.isConstructor) etaExpand(tree, wtp) @@ -1086,7 +1083,7 @@ class Typer extends Namer with Applications with Implicits { else if (ctx.mode is Mode.Pattern) tree // no subtype check for pattern else { println(s"adapt to subtype ${tree.tpe} !<:< $pt") // !!!DEBUG - println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt)) // !!!DEBUG + // println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt)) // !!!DEBUG adaptToSubType(wtp) } } |