diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 669c702b4466..64572d5af9ee 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -101,7 +101,9 @@ object ProtoTypes { val mbr = if (privateOK) tp1.member(name) else tp1.nonPrivateMember(name) def qualifies(m: SingleDenotation) = memberProto.isRef(defn.UnitClass) || - compat.normalizedCompatible(m.info, memberProto) + compat.normalizedCompatible(NamedType(tp1, name, m), memberProto) + // Note: can't use `m.info` here because if `m` is a method, `m.info` + // loses knowledge about `m`'s default arguments. mbr match { // hasAltWith inlined for performance case mbr: SingleDenotation => mbr.exists && qualifies(mbr) case _ => mbr hasAltWith qualifies @@ -431,6 +433,7 @@ object ProtoTypes { * - skips implicit parameters of methods and functions; * if result type depends on implicit parameter, replace with fresh type dependent parameter. * - converts non-dependent method types to the corresponding function types + * unless the expected type is an ApplyingProto or IgnoredProto. * - dereferences parameterless method types * - dereferences nullary method types provided the corresponding function type * is not a subtype of the expected type. @@ -451,8 +454,11 @@ object ProtoTypes { else { val rt = normalize(mt.resultType, pt) pt match { - case pt: IgnoredProto => mt - case pt: ApplyingProto => mt.derivedLambdaType(mt.paramNames, mt.paramInfos, rt) + case pt: IgnoredProto => + tp + case pt: ApplyingProto => + if (rt eq mt.resultType) tp + else mt.derivedLambdaType(mt.paramNames, mt.paramInfos, rt) case _ => val ft = defn.FunctionOf(mt.paramInfos, rt) if (mt.paramInfos.nonEmpty || ft <:< pt) ft else rt diff --git a/tests/pending/neg/i3253.scala b/tests/pending/neg/i3253.scala new file mode 100644 index 000000000000..5d84da786dfd --- /dev/null +++ b/tests/pending/neg/i3253.scala @@ -0,0 +1,5 @@ +import Test.test + +object Test { + def test = " " * 10 +} diff --git a/tests/pos/i3352.scala b/tests/pos/i3352.scala new file mode 100644 index 000000000000..4870f9c722e6 --- /dev/null +++ b/tests/pos/i3352.scala @@ -0,0 +1,13 @@ +class Test { + class Foo { + def bar(x: String): Int = 1 + } + + implicit class FooOps(foo: Foo) { + def bar(x: Int, y: Int = 2): Int = 2 // compiles with no default argument + } + + def test(foo: Foo): Unit = { + foo.bar(1) + } +}