diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-17 19:19:41 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-17 19:19:41 +0100 |
commit | 9a839d706291fdd57aeb48c3f64654afbd144a83 (patch) | |
tree | 1f3701eedc3b03920747f3833e08c93f545b3fa1 /src | |
parent | c1c933d6f936a7975ca316c69d7639145eed36e7 (diff) | |
download | dotty-9a839d706291fdd57aeb48c3f64654afbd144a83.tar.gz dotty-9a839d706291fdd57aeb48c3f64654afbd144a83.tar.bz2 dotty-9a839d706291fdd57aeb48c3f64654afbd144a83.zip |
Three bugfixes to typing.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/ast/TreeInfo.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inferencing.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 5 |
5 files changed, 14 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/ast/TreeInfo.scala b/src/dotty/tools/dotc/ast/TreeInfo.scala index e52ff9d62..2d6f8bfef 100644 --- a/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -80,7 +80,7 @@ trait TreeInfo[T >: Untyped] { self: Trees.Instance[T] => case TypeApply(fn, _) => methPart(fn) case AppliedTypeTree(fn, _) => methPart(fn) // !!! should not be needed case Block(stats, expr) => methPart(expr) - case _ => tree + case mp => mp } /** If this is an application, its function part, stripping all diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 6f65cd231..104fe0555 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -483,6 +483,8 @@ trait Applications extends Compatibility { self: Typer => fun1.tpe match { case ErrorType => tree.withType(ErrorType) + case tp => + throw new Error(s"unexpected type.\n fun1 = $fun1,\n methPart(fun1) = ${methPart(fun1)},\n methPart(fun1).tpe = ${methPart(fun1).tpe},\n tpe = $tp") } } } diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index 418bf44d1..1d1220824 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -233,17 +233,17 @@ object Inferencing { if (!tp.isStable) ctx.error(i"Prefix of type ${tp.widenIfUnstable} is not stable", pos) /** Check that `tp` is a class type with a stable prefix. - * @return Underlying class symbol if type checks out OK, ObjectClass if not. + * @return Underlying class type if type checks out OK, ObjectClass.typeRef if not. */ - def checkClassTypeWithStablePrefix(tp: Type, pos: Position)(implicit ctx: Context): ClassSymbol = tp.dealias match { + def checkClassTypeWithStablePrefix(tp: Type, pos: Position)(implicit ctx: Context): Type = tp.dealias match { case tp: TypeRef if tp.symbol.isClass => checkStable(tp.prefix, pos) - tp.symbol.asClass + tp case _: TypeVar | _: AnnotatedType => checkClassTypeWithStablePrefix(tp.asInstanceOf[TypeProxy].underlying, pos) case _ => ctx.error(i"$tp is not a class type", pos) - defn.ObjectClass + defn.ObjectClass.typeRef } /** Check that class does not define */ diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index e0b9c399f..9d0ec539c 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -7,7 +7,7 @@ import ast._ import Trees._, Constants._, StdNames._, Scopes._, Denotations._ import Contexts._, Symbols._, Types._, SymDenotations._, Names._, NameOps._, Flags._, Decorators._ import ast.desugar, ast.desugar._ -import Inferencing.{fullyDefinedType, AnySelectionProto} +import Inferencing.{fullyDefinedType, AnySelectionProto, checkClassTypeWithStablePrefix} import util.Positions._ import util.SourcePosition import collection.mutable @@ -348,9 +348,9 @@ class Namer { typer: Typer => } val Select(New(tpt), nme.CONSTRUCTOR) = core val targs1 = targs map (typedAheadType(_)) - val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes - if (ptype.uninstantiatedTypeParams.isEmpty) ptype - else typedAheadExpr(constr).tpe + var ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes + if (ptype.uninstantiatedTypeParams.nonEmpty) ptype = typedAheadExpr(constr).tpe + checkClassTypeWithStablePrefix(ptype, core.pos) } val TypeDef(_, name, impl @ Template(constr, parents, self, body)) = cdef diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 456a87ca4..7493fb42d 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -391,7 +391,7 @@ class Typer extends Namer with Applications with Implicits { typed(cpy.Block(tree, clsDef :: Nil, New(Ident(x), Nil)), pt) case _ => val tpt1 = typedType(tree.tpt) - val cls = checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos) + val clsref = checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos) // todo in a later phase: checkInstantiatable(cls, tpt1.pos) cpy.New(tree, tpt1).withType(tpt1.tpe) } @@ -717,7 +717,8 @@ class Typer extends Namer with Applications with Implicits { def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = track("typedBind") { val body1 = typed(tree.body, pt) - val sym = ctx.newSymbol(ctx.owner, tree.name.asTermName, EmptyFlags, pt, coord = tree.pos) + // println(i"typed bind $tree pt = $pt bodytpe = ${body1.tpe}") + val sym = ctx.newSymbol(ctx.owner, tree.name.asTermName, EmptyFlags, body1.tpe, coord = tree.pos) cpy.Bind(tree, tree.name, body1) withType TermRef(NoPrefix, sym) } |