diff options
author | Martin Odersky <odersky@gmail.com> | 2014-03-28 13:07:22 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-31 14:52:08 +0200 |
commit | a73b510b82460247524a07a6dd4f0bfaac74ccfc (patch) | |
tree | c3b6ab1e6159d31cfda21b5011577b98ef745e3f /src | |
parent | e5d51859bd3d6fd0b286aa6c8e710f33f95b97cd (diff) | |
download | dotty-a73b510b82460247524a07a6dd4f0bfaac74ccfc.tar.gz dotty-a73b510b82460247524a07a6dd4f0bfaac74ccfc.tar.bz2 dotty-a73b510b82460247524a07a6dd4f0bfaac74ccfc.zip |
Avoiding type applications after erasure.
Methods appliedTo and translateParameterizes only apply before erasure (except on arrays).
Also, computation of a potential expensive yet redundant lub in assignType(SeqLiteral) is
avoided.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeApplications.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 8 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 9cd635cd9..4b251f183 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -39,6 +39,8 @@ import TypeApplications._ /** A decorator that provides methods for modeling type application */ class TypeApplications(val self: Type) extends AnyVal { + def canHaveTypeParams(implicit ctx: Context) = !ctx.erasedTypes || self.isRef(defn.ArrayClass) + /** The type parameters of this type are: * For a ClassInfo type, the type parameters of its class. * For a typeref referring to a class, the type parameters of the class. @@ -128,7 +130,7 @@ class TypeApplications(val self: Type) extends AnyVal { defn.hkTrait(args map alwaysZero).typeParams } - if (args.isEmpty) self + if (args.isEmpty || !canHaveTypeParams) self else self match { case tp: TypeRef => val tsym = tp.symbol @@ -228,8 +230,11 @@ class TypeApplications(val self: Type) extends AnyVal { * `from` and `to` must be static classes, both with one type parameter, and the same variance. */ def translateParameterized(from: ClassSymbol, to: ClassSymbol)(implicit ctx: Context): Type = - if (self derivesFrom from) - RefinedType(to.typeRef, to.typeParams.head.name, self.member(from.typeParams.head.name).info) + if (self.derivesFrom(from)) + if (canHaveTypeParams) + RefinedType(to.typeRef, to.typeParams.head.name, self.member(from.typeParams.head.name).info) + else + to.typeRef else self /** If this is an encoding of a (partially) applied type, return its arguments, diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 8be73ac82..3060f3951 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -274,8 +274,12 @@ trait TypeAssigner { def assignType(tree: untpd.Throw)(implicit ctx: Context) = tree.withType(defn.NothingType) - def assignType(tree: untpd.SeqLiteral, elems: List[Tree])(implicit ctx: Context) = - tree.withType(defn.SeqType.appliedTo(ctx.typeComparer.lub(elems.tpes))) + def assignType(tree: untpd.SeqLiteral, elems: List[Tree])(implicit ctx: Context) = { + val ownType = + if (ctx.erasedTypes) defn.SeqType + else defn.SeqType.appliedTo(ctx.typeComparer.lub(elems.tpes)) + tree.withType(ownType) + } def assignType(tree: untpd.SingletonTypeTree, ref: Tree)(implicit ctx: Context) = tree.withType(ref.tpe) |