Skip to content

Fix #2192: Follow supertypes when determining whether an expect type … #2208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2017
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
14 changes: 12 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1932,13 +1932,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
adapt(typed(original, WildcardType), pt, EmptyTree)
}
case wtp: MethodType if !pt.isInstanceOf[SingletonType] =>
// Follow proxies and approximate type paramrefs by their upper bound
// in the current constraint in order to figure out robustly
// whether an expected type is some sort of function type.
def underlyingRefined(tp: Type): Type = tp.stripTypeVar match {
case tp: RefinedType => tp
case tp: TypeParamRef => underlyingRefined(ctx.typeComparer.bounds(tp).hi)
case tp: TypeProxy => underlyingRefined(tp.superType)
case _ => tp
}
val ptNorm = underlyingRefined(pt)
val arity =
if (defn.isFunctionType(pt))
if (defn.isFunctionType(ptNorm))
if (!isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none))
// if method type is fully defined, but expected type is not,
// prioritize method parameter types as parameter types of the eta-expanded closure
0
else defn.functionArity(pt)
else defn.functionArity(ptNorm)
else if (pt eq AnyFunctionProto) wtp.paramInfos.length
else -1
if (arity >= 0 && !tree.symbol.isConstructor)
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i2192.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
def foo(x: Int): Int = x

Some(foo): Option[Int => Int]
// missing arguments for method foo
// follow this method with `_' if you want to treat it as a partially applied function
}