-
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 all 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 safeSubstParam(tp: Type, pref: ParamRef, argType: Type)(implicit ctx: Context) = { | ||
val tp1 = tp.substParam(pref, argType) | ||
if ((tp1 eq tp) || argType.isStable) tp1 | ||
else tp.substParam(pref, SkolemType(argType.widen)) | ||
} | ||
|
||
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 safeSubstParams(tp: Type, params: List[ParamRef], args: List[Tree]): Type = params match { | ||
case param :: params1 => | ||
val tp1 = safeSubstParam(tp, param, args.head.tpe) | ||
safeSubstParams(tp1, params1, args.tail) | ||
case Nil => | ||
tp | ||
} | ||
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping) | ||
if (fntpe.isDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args) | ||
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.
Was this change also needed to make a test pass? It seems more suspicious.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, pos/z1720 started failing without the fix. The commit comment indicates this.