Skip to content

Commit 3898dea

Browse files
committed
Fix #815.
Need to handle hk-aliases specially in typedNew
1 parent cbb565a commit 3898dea

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
347347
val clsDef = TypeDef(x, templ).withFlags(Final)
348348
typed(cpy.Block(tree)(clsDef :: Nil, New(Ident(x), Nil)), pt)
349349
case _ =>
350-
val tpt1 = typedType(tree.tpt)
350+
var tpt1 = typedType(tree.tpt)
351+
if (tpt1.tpe.isHK) {
352+
val deAliased = tpt1.tpe.dealias.EtaReduce
353+
if (deAliased.exists && deAliased.ne(tpt1.tpe))
354+
tpt1 = tpt1.withType(deAliased)
355+
}
351356
checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos, traitReq = false)
352357
assignType(cpy.New(tree)(tpt1), tpt1)
353358
// todo in a later phase: checkInstantiatable(cls, tpt1.pos)

tests/pos/i815.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.collection.immutable.::
2+
class C[T](x: T)
3+
object A {
4+
def main(args: Array[String]): Unit = {
5+
val x = new C("A")
6+
val y = new ::(args, Nil)
7+
val z = ::(args, Nil)
8+
println(y)
9+
println(z)
10+
}
11+
}

0 commit comments

Comments
 (0)