From 12a466a5557a97bdc146e03f35b0c28643109b4c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 18 Jul 2019 10:22:23 +0200 Subject: [PATCH] Fix #6862, fix #6863: Do not adapt contextual closures while inlining --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Typer.scala | 6 ++++-- tests/pos/i6862/lib_1.scala | 3 +++ tests/pos/i6862/test_1.scala | 3 +++ tests/pos/i6862b/lib.scala | 8 ++++++++ tests/pos/i6862b/test.scala | 4 ++++ tests/pos/i6863/lib_1.scala | 2 ++ tests/pos/i6863/test_1.scala | 3 +++ 8 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i6862/lib_1.scala create mode 100644 tests/pos/i6862/test_1.scala create mode 100644 tests/pos/i6862b/lib.scala create mode 100644 tests/pos/i6862b/test.scala create mode 100644 tests/pos/i6863/lib_1.scala create mode 100644 tests/pos/i6863/test_1.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 5319af6b97a2..518c4f8a1990 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -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` diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 43e09b5f3234..c246c50f1138 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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) @@ -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) } diff --git a/tests/pos/i6862/lib_1.scala b/tests/pos/i6862/lib_1.scala new file mode 100644 index 000000000000..af8821681501 --- /dev/null +++ b/tests/pos/i6862/lib_1.scala @@ -0,0 +1,3 @@ +trait Ctx +inline def foo(): Unit = given (x: Ctx) => () +def bar[T](b: given Ctx => Unit): Unit = ??? diff --git a/tests/pos/i6862/test_1.scala b/tests/pos/i6862/test_1.scala new file mode 100644 index 000000000000..024d001423ba --- /dev/null +++ b/tests/pos/i6862/test_1.scala @@ -0,0 +1,3 @@ +class Test { + foo() +} diff --git a/tests/pos/i6862b/lib.scala b/tests/pos/i6862b/lib.scala new file mode 100644 index 000000000000..de9d25d7691d --- /dev/null +++ b/tests/pos/i6862b/lib.scala @@ -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 = ??? diff --git a/tests/pos/i6862b/test.scala b/tests/pos/i6862b/test.scala new file mode 100644 index 000000000000..3c0fcfeb8d53 --- /dev/null +++ b/tests/pos/i6862b/test.scala @@ -0,0 +1,4 @@ + +class Test { + foo() +} diff --git a/tests/pos/i6863/lib_1.scala b/tests/pos/i6863/lib_1.scala new file mode 100644 index 000000000000..09f57ba0f639 --- /dev/null +++ b/tests/pos/i6863/lib_1.scala @@ -0,0 +1,2 @@ +trait Ctx +inline def foo(): Unit = given (x: Ctx) => () diff --git a/tests/pos/i6863/test_1.scala b/tests/pos/i6863/test_1.scala new file mode 100644 index 000000000000..024d001423ba --- /dev/null +++ b/tests/pos/i6863/test_1.scala @@ -0,0 +1,3 @@ +class Test { + foo() +}