Skip to content

Commit 3a6cab4

Browse files
committed
Merge pull request #384 from dotty-staging/fix/constructor-alias
Fix bug which prevented New over type-instantiated aliases.
2 parents 4e99877 + 83d4356 commit 3a6cab4

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,12 +1408,7 @@ object Parsers {
14081408
}
14091409

14101410
/** Wrap annotation or constructor in New(...).<init> */
1411-
def wrapNew(tpt: Tree) = tpt match {
1412-
case AppliedTypeTree(tpt1, targs) =>
1413-
TypeApply(Select(New(tpt1), nme.CONSTRUCTOR), targs)
1414-
case _ =>
1415-
Select(New(tpt), nme.CONSTRUCTOR)
1416-
}
1411+
def wrapNew(tpt: Tree) = Select(New(tpt), nme.CONSTRUCTOR)
14171412

14181413
/** Adjust start of annotation or constructor to position of preceding @ or new */
14191414
def adjustStart(start: Offset)(tree: Tree): Tree = {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ 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)
351-
checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos, traitReq = false)
350+
val tpt1 = typedType(tree.tpt)
351+
checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos, traitReq = false)
352352
assignType(cpy.New(tree)(tpt1), tpt1)
353353
// todo in a later phase: checkInstantiatable(cls, tpt1.pos)
354354
}
@@ -1366,9 +1366,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13661366
case poly: PolyType =>
13671367
if (pt.isInstanceOf[PolyProto]) tree
13681368
else {
1369-
val (_, tvars) = constrained(poly, tree)
1369+
var typeArgs = tree match {
1370+
case Select(New(tpt), nme.CONSTRUCTOR) => tpt.tpe.dealias.argTypesLo
1371+
case _ => Nil
1372+
}
1373+
if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2
13701374
convertNewArray(
1371-
adaptInterpolated(tree.appliedToTypes(tvars), pt, original))
1375+
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original))
13721376
}
13731377
case wtp =>
13741378
pt match {

tests/pos/aliasNew.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object test {
2+
3+
type Map = collection.mutable.HashMap[String, Int]
4+
5+
val xs = new Map
6+
xs("abc") = 1
7+
8+
}

0 commit comments

Comments
 (0)