Skip to content

Commit 8d22a17

Browse files
authored
Merge pull request #2208 from dotty-staging/fix-#2192
Fix #2192: Follow supertypes when determining whether an expect type …
2 parents c82db74 + 14fde01 commit 8d22a17

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,13 +1932,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
19321932
adapt(typed(original, WildcardType), pt, EmptyTree)
19331933
}
19341934
case wtp: MethodType if !pt.isInstanceOf[SingletonType] =>
1935+
// Follow proxies and approximate type paramrefs by their upper bound
1936+
// in the current constraint in order to figure out robustly
1937+
// whether an expected type is some sort of function type.
1938+
def underlyingRefined(tp: Type): Type = tp.stripTypeVar match {
1939+
case tp: RefinedType => tp
1940+
case tp: TypeParamRef => underlyingRefined(ctx.typeComparer.bounds(tp).hi)
1941+
case tp: TypeProxy => underlyingRefined(tp.superType)
1942+
case _ => tp
1943+
}
1944+
val ptNorm = underlyingRefined(pt)
19351945
val arity =
1936-
if (defn.isFunctionType(pt))
1946+
if (defn.isFunctionType(ptNorm))
19371947
if (!isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none))
19381948
// if method type is fully defined, but expected type is not,
19391949
// prioritize method parameter types as parameter types of the eta-expanded closure
19401950
0
1941-
else defn.functionArity(pt)
1951+
else defn.functionArity(ptNorm)
19421952
else if (pt eq AnyFunctionProto) wtp.paramInfos.length
19431953
else -1
19441954
if (arity >= 0 && !tree.symbol.isConstructor)

tests/pos/i2192.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def foo(x: Int): Int = x
3+
4+
Some(foo): Option[Int => Int]
5+
// missing arguments for method foo
6+
// follow this method with `_' if you want to treat it as a partially applied function
7+
}

0 commit comments

Comments
 (0)