File tree 2 files changed +19
-2
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1932,13 +1932,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1932
1932
adapt(typed(original, WildcardType ), pt, EmptyTree )
1933
1933
}
1934
1934
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)
1935
1945
val arity =
1936
- if (defn.isFunctionType(pt ))
1946
+ if (defn.isFunctionType(ptNorm ))
1937
1947
if (! isFullyDefined(pt, ForceDegree .none) && isFullyDefined(wtp, ForceDegree .none))
1938
1948
// if method type is fully defined, but expected type is not,
1939
1949
// prioritize method parameter types as parameter types of the eta-expanded closure
1940
1950
0
1941
- else defn.functionArity(pt )
1951
+ else defn.functionArity(ptNorm )
1942
1952
else if (pt eq AnyFunctionProto ) wtp.paramInfos.length
1943
1953
else - 1
1944
1954
if (arity >= 0 && ! tree.symbol.isConstructor)
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments