-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1378: Propagate more knowledge of result type into applications #1395
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
Changes from 1 commit
5e34031
bd45ecc
0eb2d76
9d66f86
bdb3cc8
9ccb47a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,6 +553,16 @@ trait Applications extends Compatibility { self: Typer with Dynamic => | |
// a modified tree but this would be more convoluted and less efficient. | ||
if (proto.isTupled) proto = proto.tupled | ||
|
||
// If some of the application's arguments are function literals without explicitly declared | ||
// parameter types, and the expected type is a value type, relate the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This says |
||
// normalized result type of the application with the expected type through `<:<`. | ||
// This can add more constraints which help sharpen the inferred parameter | ||
// types for the argument function literal(s). | ||
// This tweak is needed to make i1348 compile. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean |
||
if (tree.args.exists(untpd.isFunctionWithImplicitParamType(_))) | ||
if (!constrainResult(fun1.tpe.widen, proto.derivedFunProto(resultType = pt))) | ||
typr.println(i"result failure for $tree with type ${fun1.tpe.widen}, expected = $pt") | ||
|
||
fun1.tpe match { | ||
case ErrorType => tree.withType(ErrorType) | ||
case TryDynamicCallType => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,6 +597,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
untpd.TypeTree(defn.FunctionClass(args.length).typeRef), args :+ body), pt) | ||
else { | ||
val params = args.asInstanceOf[List[untpd.ValDef]] | ||
|
||
pt match { | ||
case pt: TypeVar if untpd.isFunctionWithImplicitParamType(tree) => | ||
isFullyDefined(pt, ForceDegree.noBottom) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment should clarify that this method is called for its side-effects, and why we don't need to do anything special when it returns |
||
case _ => | ||
} | ||
|
||
val (protoFormals, protoResult) = decomposeProtoFunction(pt, params.length) | ||
|
||
def refersTo(arg: untpd.Tree, param: untpd.ValDef): Boolean = arg match { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Test { | ||
(1, x => 2): (Int, Int => Int) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the use of
implicit
in this context confusing, how aboutunknown
instead?