Skip to content

Commit 791bac2

Browse files
authored
Merge pull request #6880 from dotty-staging/do-not-addapt-contextual-closures-while-inlining
Fix #6862, fix #6863: Do not adapt contextual closures while inlining
2 parents 6195104 + 12a466a commit 791bac2

File tree

8 files changed

+28
-3
lines changed

8 files changed

+28
-3
lines changed

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,8 @@ class Typer extends Namer
20482048
xtree.isTerm &&
20492049
!untpd.isContextualClosure(xtree) &&
20502050
!ctx.mode.is(Mode.Pattern) &&
2051-
!ctx.isAfterTyper)
2051+
!ctx.isAfterTyper &&
2052+
!ctx.isInlineContext)
20522053
makeContextualFunction(xtree, ifpt)
20532054
else xtree match {
20542055
case xtree: untpd.NameTree => typedNamed(xtree, pt)
@@ -2660,7 +2661,8 @@ class Typer extends Namer
26602661
!isApplyProto(pt) &&
26612662
pt != AssignProto &&
26622663
!ctx.mode.is(Mode.Pattern) &&
2663-
!ctx.isAfterTyper) {
2664+
!ctx.isAfterTyper &&
2665+
!ctx.isInlineContext) {
26642666
typr.println(i"insert apply on implicit $tree")
26652667
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked)
26662668
}

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/i6862b/lib.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
trait Expr[+T]
3+
4+
trait Ctx
5+
6+
inline def foo(): Int = splice( bar() )
7+
def bar() given Ctx: Expr[Int] = ???
8+
def splice[T](f: given Ctx => Expr[T]): T = ???

tests/pos/i6862b/test.scala

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

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)