-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2142: Skolemize arguments of dependent methods if necessary #2215
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 3 commits
529346d
b3d683a
bb0faff
ab06e2d
0cf17c5
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 |
---|---|---|
|
@@ -315,10 +315,28 @@ trait TypeAssigner { | |
} | ||
} | ||
|
||
/** Substitute argument type `argType` for parameter `pref` in type `tp`, | ||
* skolemizing the argument type if it is not stable and `pref` occurs in `tp`. | ||
*/ | ||
def substArgForParam(tp: Type, argType: Type, pref: ParamRef)(implicit ctx: Context) = { | ||
val tp1 = tp.substParam(pref, argType) | ||
if ((tp1 eq tp) || argType.isStable) tp1 | ||
else tp.substParam(pref, SkolemType(argType.widen)) | ||
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. I would have expected 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. For SkolemTypes, it's widen also elsewhere. We don't want to get ExprTypes in there. |
||
} | ||
|
||
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context) = { | ||
val ownType = fn.tpe.widen match { | ||
case fntpe: MethodType => | ||
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping) fntpe.instantiate(args.tpes) | ||
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. Would it make sense to change the definition of 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. No, I think that's too low-level. By analogy, asSeenFrom does not do skolemization, but reports back that skolemization is needed, and then Typer does it. |
||
def substArgsForParams(tp: Type, args: List[Tree], params: List[ParamRef]): Type = params match { | ||
case param :: params1 => | ||
val tp1 = substArgForParam(tp, args.head.tpe, param) | ||
substArgsForParams(tp1, args.tail, params1) | ||
case Nil => | ||
tp | ||
} | ||
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping) | ||
if (fntpe.isDependent) substArgsForParams(fntpe.resultType, args, fntpe.paramRefs) | ||
else fntpe.resultType | ||
else | ||
errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.pos) | ||
case t => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
object Foo { | ||
|
||
class A | ||
val a1 = new A() | ||
val a2 = new A() | ||
|
||
def f(x: A, y: x.type) = () | ||
f(a1, a1) // ok | ||
f(a1, a2) // error | ||
f(new A(), new A()) // error | ||
f(new A(), a1) // error | ||
|
||
def g(x: A)(y: x.type) = () | ||
g(a1)(a1) // ok | ||
g(a1)(a2) // error | ||
g(new A())(new A()) // error | ||
g(new A())(a1) // error | ||
|
||
val x0 = g(new A()) _ | ||
x0 (new A()) // error | ||
|
||
class C[T] | ||
|
||
def h(x: A): C[x.type] = ??? | ||
val x = h(a1) | ||
val y = h(new A()) | ||
|
||
} |
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.
Minor suggestion: all the
subst*
methods have thefrom
argument before theto
argument, here it's the reverse order which can be a bit confusing. If this is changed it probably makes sense to rename the method tosubstParamWithArg
too.