aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/ast/TypedTrees.scala16
-rw-r--r--src/dotty/tools/dotc/core/Annotations.scala6
-rw-r--r--src/dotty/tools/dotc/core/Types.scala20
-rw-r--r--src/dotty/tools/dotc/core/pickling/ClassfileParser.scala9
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala6
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala2
-rw-r--r--tests/pos/collections.scala1
-rw-r--r--tests/pos/inferred.scala3
-rw-r--r--tests/pos/varargs.scala2
9 files changed, 50 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/ast/TypedTrees.scala b/src/dotty/tools/dotc/ast/TypedTrees.scala
index a498346f5..827e6cd87 100644
--- a/src/dotty/tools/dotc/ast/TypedTrees.scala
+++ b/src/dotty/tools/dotc/ast/TypedTrees.scala
@@ -46,8 +46,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
case fntpe @ MethodType(pnames, ptypes) =>
check(sameLength(ptypes, args), s"${fn.show}: ${fntpe.show} to ${args.map(_.show).mkString(", ")}")
fntpe.instantiate(args map (_.tpe))
- case _ =>
- check(false)
+ case t =>
+ check(false, s"fn = $fn, args = $args, tp = $t")
ErrorType
}
untpd.Apply(fn, args).withType(owntype).checked
@@ -308,12 +308,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
// ------ Creating typed equivalents of trees that exist only in untyped form -------
/** new C(args) */
- def New(tp: Type, args: List[Tree])(implicit ctx: Context): Apply =
+ def New(tp: Type, args: List[Tree])(implicit ctx: Context): Apply = {
+ val targs = tp.typeArgs
Apply(
Select(
- New(tp),
- TermRef.withSym(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm)),
+ New(tp withoutArgs targs),
+ TermRef.withSym(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm))
+ .appliedToTypes(targs),
args)
+ }
/** An object def
*
@@ -399,6 +402,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def changeOwner(from: Symbol, to: Symbol)(implicit ctx: Context): ThisTree =
new TreeMapper(ownerMap = (sym => if (sym == from) to else sym)).apply(tree)
+
+ def appliedToTypes(targs: List[Type])(implicit ctx: Context): Tree =
+ if (targs.isEmpty) tree else TypeApply(tree, targs map (TypeTree(_)))
}
implicit class ListOfTreeDecorator(val xs: List[tpd.Tree]) extends AnyVal {
diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala
index 221f5c160..8b7cb7bd7 100644
--- a/src/dotty/tools/dotc/core/Annotations.scala
+++ b/src/dotty/tools/dotc/core/Annotations.scala
@@ -61,6 +61,8 @@ object Annotations {
apply(defn.ChildAnnot.typeConstructor.appliedTo(NamedType(sym.owner.thisType, sym.name).withDenot(sym)), Nil)
}
- def ThrowsAnnotation(cls: ClassSymbol)(implicit ctx: Context) =
- Annotation(defn.ThrowsAnnot, Ident(cls.symTypeRef))
+ def ThrowsAnnotation(cls: ClassSymbol)(implicit ctx: Context) = {
+ val tref = cls.symTypeRef
+ Annotation(defn.ThrowsAnnot.typeConstructor.appliedTo(tref), Ident(tref))
+ }
} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 5f60454b5..ea4d1f572 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -901,6 +901,17 @@ object Types {
if (buf == null) Nil else buf.toList
}
+ /** The core type without any type arguments.
+ * @param `typeArgs` must be the type arguments of this type.
+ */
+ final def withoutArgs(typeArgs: List[Type]): Type = typeArgs match {
+ case _ :: typeArgs1 =>
+ val RefinedType(tycon, _) = this
+ tycon.withoutArgs(typeArgs.tail)
+ case nil =>
+ this
+ }
+
/** If this is the image of a type argument to type parameter `tparam`,
* recover the type argument, otherwise NoType.
*/
@@ -1504,10 +1515,17 @@ object Types {
def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(implicit ctx: Context): RefinedType = {
def originalName = parent.typeParams.apply(refinedName.hkParamIndex).name
+ def checkForTypeParams(tpe: Type): Boolean = tpe match {
+ case tpe: NamedType => tpe.symbol.isCompleted
+ case ThisType(cls) => cls.isCompleted
+ case tpe: BoundType => false
+ case tp: TypeProxy => checkForTypeParams(tp.underlying)
+ case _ => true
+ }
if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo))
this
else if (refinedName.isHkParamName &&
- parent.typeSymbol.isCompleted && // to avoid cyclic reference errors
+ checkForTypeParams(parent) && // to avoid cyclic reference errors
refinedName.hkParamIndex < typeParams.length &&
originalName != refinedName)
derivedRefinedType(parent, originalName, refinedInfo)
diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
index b65fc55bb..a641e10cc 100644
--- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
+++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
@@ -174,7 +174,7 @@ class ClassfileParser(
val isEnum = (jflags & JAVA_ACC_ENUM) != 0
val name = pool.getName(in.nextChar)
val isConstructor = name eq nme.CONSTRUCTOR
-
+
/** Strip leading outer param from constructor.
* Todo: Also strip trailing access tag for private inner constructors?
*/
@@ -190,10 +190,9 @@ class ClassfileParser(
*/
def normalizeConstructorInfo() = {
val mt @ MethodType(paramnames, paramtypes) = denot.info
- val typeParams = classRoot.typeParams
- val rt = classRoot.typeConstructor appliedTo (typeParams map (_.symRef))
- denot.info = PolyType.fromSymbols(typeParams,
- mt.derivedMethodType(paramnames, paramtypes, rt))
+ val rt = classRoot.typeConstructor appliedTo (classRoot.typeParams map (_.symRef))
+ denot.info = mt.derivedMethodType(paramnames, paramtypes, rt)
+ addConstructorTypeParams(denot)
}
denot.info = pool.getType(in.nextChar)
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index 4570d0654..cc777ce9b 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -62,6 +62,11 @@ object UnPickler {
case tp => tp
}
+ def addConstructorTypeParams(denot: SymDenotation)(implicit ctx: Context) = {
+ assert(denot.isConstructor)
+ denot.info = PolyType.fromSymbols(denot.owner.typeParams, denot.info)
+ }
+
/** Convert array parameters denoting a repeated parameter of a Java method
* to `JavaRepeatedParamClass` types.
*/
@@ -497,6 +502,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
case denot =>
val tp1 = depoly(tp, denot)
denot.info = if (tag == ALIASsym) TypeAlias(tp1) else tp1
+ if (denot.isConstructor) addConstructorTypeParams(denot)
if (atEnd) {
assert(!(denot is SuperAccessor), denot)
} else {
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index c6d419675..47eee5d4d 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1099,7 +1099,7 @@ class Typer extends Namer with Applications with Implicits {
val tracked = ctx.track(poly)
ctx.newTypeVars(tracked, tree.pos)
}
- adapt(tpd.TypeApply(tree, tvars map (tpd.TypeTree(_))), pt)
+ adapt(tree appliedToTypes tvars, pt)
}
case wtp =>
pt match {
diff --git a/tests/pos/collections.scala b/tests/pos/collections.scala
index 0d00b91fe..e91a90a90 100644
--- a/tests/pos/collections.scala
+++ b/tests/pos/collections.scala
@@ -9,6 +9,7 @@ object collections {
val ints2 = 1 :: 2 :: Nil
val ints3: List[Int] = ints2
val f = (x: Int) => x + 1
+ val ints4: List[Int] = List(1, 2, 3, 5)
val ys = ints3 map (x => x + 1)
val zs = ys filter (y => y != 0)
diff --git a/tests/pos/inferred.scala b/tests/pos/inferred.scala
index 88038147c..441ae9650 100644
--- a/tests/pos/inferred.scala
+++ b/tests/pos/inferred.scala
@@ -53,4 +53,7 @@ object Inferred {
val ints2 = ints map (_ + 1)
+ val ints3 = new CONS[Int](1, NIL)
+
+ val ints4 = new CONS(1, NIL)
} \ No newline at end of file
diff --git a/tests/pos/varargs.scala b/tests/pos/varargs.scala
index 4d5e68eb4..3739636b8 100644
--- a/tests/pos/varargs.scala
+++ b/tests/pos/varargs.scala
@@ -1,4 +1,5 @@
object varargs {
+ List(1, 2, 3)
def g(x: Int*) = x.length
g(1, 2, 3, 4)
val x = if (true) 1 else 2
@@ -9,5 +10,4 @@ object varargs {
g(Nil: _*)
g(1)
g()
- List.apply(1, 2, 3)
} \ No newline at end of file