Skip to content

Fix #6862, fix #6863: Do not adapt contextual closures while inlining #6880

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
/** An extractor for terms equivalent to `new C(args)`, returning the class `C`,
* a list of bindings, and the arguments `args`. Can see inside blocks and Inlined nodes and can
* follow a reference to an inline value binding to its right hand side.
*
*
* @return optionally, a triple consisting of
* - the class `C`
* - the arguments `args`
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,8 @@ class Typer extends Namer
xtree.isTerm &&
!untpd.isContextualClosure(xtree) &&
!ctx.mode.is(Mode.Pattern) &&
!ctx.isAfterTyper)
!ctx.isAfterTyper &&
!ctx.isInlineContext)
makeContextualFunction(xtree, ifpt)
else xtree match {
case xtree: untpd.NameTree => typedNamed(xtree, pt)
Expand Down Expand Up @@ -2660,7 +2661,8 @@ class Typer extends Namer
!isApplyProto(pt) &&
pt != AssignProto &&
!ctx.mode.is(Mode.Pattern) &&
!ctx.isAfterTyper) {
!ctx.isAfterTyper &&
!ctx.isInlineContext) {
typr.println(i"insert apply on implicit $tree")
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked)
}
Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i6862/lib_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait Ctx
inline def foo(): Unit = given (x: Ctx) => ()
def bar[T](b: given Ctx => Unit): Unit = ???
3 changes: 3 additions & 0 deletions tests/pos/i6862/test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Test {
foo()
}
8 changes: 8 additions & 0 deletions tests/pos/i6862b/lib.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

trait Expr[+T]

trait Ctx

inline def foo(): Int = splice( bar() )
def bar() given Ctx: Expr[Int] = ???
def splice[T](f: given Ctx => Expr[T]): T = ???
4 changes: 4 additions & 0 deletions tests/pos/i6862b/test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

class Test {
foo()
}
2 changes: 2 additions & 0 deletions tests/pos/i6863/lib_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait Ctx
inline def foo(): Unit = given (x: Ctx) => ()
3 changes: 3 additions & 0 deletions tests/pos/i6863/test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Test {
foo()
}