File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 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
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)
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