Skip to content

Commit 8c1e994

Browse files
committed
Fix #6060: Don't insert apply or implicits on constructor calls
This mirrors scalac's behavior.
1 parent b537220 commit 8c1e994

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
106106
case _ => Nil
107107
}
108108

109+
/** Is tree a constructor call this(...) or new C(...)? */
110+
def isConstrCall(tree: Tree): Boolean = methPart(tree) match {
111+
case Select(_, nme.CONSTRUCTOR) => true
112+
case _ => false
113+
}
114+
109115
/** Is tree a self constructor call this(...)? I.e. a call to a constructor of the
110116
* same object?
111117
*/

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,10 @@ class Typer extends Namer
22822282
pt.markAsDropped()
22832283
tree
22842284
case _ =>
2285-
if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit(fallBack)
2285+
if (isConstrCall(tree))
2286+
fallBack
2287+
if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree))
2288+
tryImplicit(fallBack)
22862289
else tryEither(tryApply(_)) { (app, appState) =>
22872290
tryImplicit {
22882291
if (tree.tpe.member(nme.apply).exists) {

tests/neg/i6060.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class I1(i2: Int) {
2+
def apply(i3: Int) = 1 // error: constructor I1 in class I1 does not take more parameters
3+
new I1(1)(2) {}
4+
}
5+
6+
class I0(i1: Int) {
7+
class I0[I2] {
8+
def apply(i3: Int) = 1
9+
new I0[Int]()(2) {} // error: constructor I0 in class I0 does not take more parameters
10+
}
11+
}

0 commit comments

Comments
 (0)