Skip to content

Commit e6558e5

Browse files
authored
Box arguments in type application (#15938)
Fixes #15923.
2 parents 9c2e3d9 + ebde449 commit e6558e5

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class TypeApplications(val self: Type) extends AnyVal {
346346
}
347347
if ((dealiased eq stripped) || followAlias)
348348
try
349-
val instantiated = dealiased.instantiate(args)
349+
val instantiated = dealiased.instantiate(args.mapConserve(_.boxedUnlessFun(self)))
350350
if (followAlias) instantiated.normalized else instantiated
351351
catch
352352
case ex: IndexOutOfBoundsException =>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Cap { def use(): Int }
2+
type Id[X] = [T] -> (op: X => T) -> T
3+
def mkId[X](x: X): Id[X] = [T] => (op: X => T) => op(x)
4+
5+
def foo(x: Id[{*} Cap]) = {
6+
x(_.use()) // error
7+
}
8+
9+
def bar(io: {*} Cap, x: Id[{io} Cap]) = {
10+
x(_.use())
11+
}
12+
13+
def barAlt(a: {*} Cap, b: {*} Cap, x: Id[{a, b} Cap]) = {
14+
x(_.use())
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Cap { def use(): Int }
2+
type Id[X] = [T] -> (op: X => T) -> T
3+
def mkId[X](x: X): Id[X] = [T] => (op: X => T) => op(x)
4+
5+
def bar() = {
6+
def withCap[X](op: ({*} Cap) => X): X = {
7+
val cap: {*} Cap = new Cap { def use() = { println("cap is used"); 0 } }
8+
val result = op(cap)
9+
result
10+
}
11+
12+
val leak = withCap(cap => mkId(cap))
13+
leak { cap => cap.use() } // error
14+
}

0 commit comments

Comments
 (0)