Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/pending/neg/i3253.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.test

object Test {
def test = " " * 10
}
13 changes: 13 additions & 0 deletions tests/pos/i3352.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}