Skip to content

Commit e5b4788

Browse files
committed
Fix scala#3352: defaults parameters require named type in compatibility check
1 parent 174444d commit e5b4788

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ object ProtoTypes {
4141
/** Test compatibility after normalization in a fresh typerstate. */
4242
def normalizedCompatible(tp: Type, pt: Type)(implicit ctx: Context) = ctx.typerState.test {
4343
val normTp = normalize(tp, pt)
44-
isCompatible(normTp, pt) || pt.isRef(defn.UnitClass) && normTp.isParameterless
44+
isCompatible(normTp, pt) ||
45+
pt.isRef(defn.UnitClass) && normTp.isParameterless ||
46+
pt.isInstanceOf[ApplyingProto] && isCompatible(tp, pt) // check i3352
4547
}
4648

4749
private def disregardProto(pt: Type)(implicit ctx: Context): Boolean = pt.dealias match {
@@ -101,7 +103,8 @@ object ProtoTypes {
101103
val mbr = if (privateOK) tp1.member(name) else tp1.nonPrivateMember(name)
102104
def qualifies(m: SingleDenotation) =
103105
memberProto.isRef(defn.UnitClass) ||
104-
compat.normalizedCompatible(m.info, memberProto)
106+
compat.normalizedCompatible(m.info, memberProto) ||
107+
memberProto.isInstanceOf[ApplyingProto] && compat.normalizedCompatible(m.namedType, memberProto) // check i3352
105108
mbr match { // hasAltWith inlined for performance
106109
case mbr: SingleDenotation => mbr.exists && qualifies(mbr)
107110
case _ => mbr hasAltWith qualifies

tests/pos/i3352.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Test {
2+
class Foo {
3+
def bar(x: String): Int = 1
4+
}
5+
6+
implicit class FooOps(foo: Foo) {
7+
def bar(x: Int, y: Int = 2): Int = 2 // compiles with no default argument
8+
}
9+
10+
def test(foo: Foo): Unit = {
11+
foo.bar(1)
12+
}
13+
}

0 commit comments

Comments
 (0)