Skip to content

Commit 76d12ce

Browse files
committed
Fix #6862, fix #6863: Do not adapt contextual closures while inlining
1 parent a35d724 commit 76d12ce

File tree

8 files changed

+20
-2
lines changed

8 files changed

+20
-2
lines changed

app.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test {
2+
foo()
3+
}

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
573573
/** An extractor for terms equivalent to `new C(args)`, returning the class `C`,
574574
* a list of bindings, and the arguments `args`. Can see inside blocks and Inlined nodes and can
575575
* follow a reference to an inline value binding to its right hand side.
576-
*
576+
*
577577
* @return optionally, a triple consisting of
578578
* - the class `C`
579579
* - the arguments `args`

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,8 @@ class Typer extends Namer
26602660
!isApplyProto(pt) &&
26612661
pt != AssignProto &&
26622662
!ctx.mode.is(Mode.Pattern) &&
2663-
!ctx.isAfterTyper) {
2663+
!ctx.isAfterTyper &&
2664+
!ctx.isInlineContext) {
26642665
typr.println(i"insert apply on implicit $tree")
26652666
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked)
26662667
}

lib.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait Ctx
2+
inline def foo(): Unit = given (x: Ctx) => ()
3+
def bar[T](b: given Ctx => Unit): Unit = ???

tests/pos/i6862/lib_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait Ctx
2+
inline def foo(): Unit = given (x: Ctx) => ()
3+
def bar[T](b: given Ctx => Unit): Unit = ???

tests/pos/i6862/test_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test {
2+
foo()
3+
}

tests/pos/i6863/lib_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait Ctx
2+
inline def foo(): Unit = given (x: Ctx) => ()

tests/pos/i6863/test_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test {
2+
foo()
3+
}

0 commit comments

Comments
 (0)