From fdbf838399faa7dbd4076e978bb87ae353f05ce9 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 6 May 2021 15:07:12 +0200 Subject: [PATCH 1/3] Fix #12344: tune splicing of default getters --- .../dotty/tools/dotc/typer/Applications.scala | 15 +++++++++++- tests/neg/i12344.scala | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i12344.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 2d30b925a7eb..74b068b6c274 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -261,7 +261,20 @@ object Applications { /** Splice new method reference `meth` into existing application `app` */ private def spliceMeth(meth: Tree, app: Tree)(using Context): Tree = app match { case Apply(fn, args) => - spliceMeth(meth, fn).appliedToArgs(args) + // Constructors always have one leading non-implicit parameter list. + // Empty list is inserted for constructors where the first parameter list is implicit. + // + // Therefore, we need to ignore the first empty parameter block. + // This is needed for the test tests/neg/i12344.scala + // + // see NamerOps.normalizeIfConstructor + // + if args == Nil + && fn.symbol.isConstructor + && !fn.isInstanceOf[Apply] + && app.tpe.isImplicitMethod + then meth + else spliceMeth(meth, fn).appliedToArgs(args) case TypeApply(fn, targs) => // Note: It is important that the type arguments `targs` are passed in new trees // instead of being spliced in literally. Otherwise, a type argument to a default diff --git a/tests/neg/i12344.scala b/tests/neg/i12344.scala new file mode 100644 index 000000000000..ce0aceacb729 --- /dev/null +++ b/tests/neg/i12344.scala @@ -0,0 +1,23 @@ +import scala.quoted.* + +class C(using q: Quotes)(i: Int = 1, f: q.reflect.Flags = q.reflect.Flags.EmptyFlags) + +def test1a(using q: Quotes) = new C() // error +def test2a(using q: Quotes) = new C(1) // error +def test3a(using q: Quotes) = new C(1, q.reflect.Flags.Lazy) // error +def test4a(using q: Quotes) = new C(f = q.reflect.Flags.Lazy) // error + +def test1b(using q: Quotes) = C() // error +def test2b(using q: Quotes) = C(1) // error +def test3b(using q: Quotes) = C(1, q.reflect.Flags.Lazy) // error +def test4b(using q: Quotes) = C(f = q.reflect.Flags.Lazy) // error + +def test1c(using q: Quotes) = new C(using q)() +def test2c(using q: Quotes) = new C(using q)(1) +def test3c(using q: Quotes) = new C(using q)(1, q.reflect.Flags.Lazy) +def test4c(using q: Quotes) = new C(using q)(f = q.reflect.Flags.Lazy) + +def test1d(using q: Quotes) = C(using q)() +def test2d(using q: Quotes) = C(using q)(1) +def test3d(using q: Quotes) = C(using q)(1, q.reflect.Flags.Lazy) +def test4d(using q: Quotes) = C(using q)(f = q.reflect.Flags.Lazy) From 10d75e929bb4131e0378b4829662652ec8095fd8 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 6 May 2021 15:47:44 +0200 Subject: [PATCH 2/3] Performance tweak --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 74b068b6c274..79cafc26e6f0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -264,15 +264,15 @@ object Applications { // Constructors always have one leading non-implicit parameter list. // Empty list is inserted for constructors where the first parameter list is implicit. // - // Therefore, we need to ignore the first empty parameter block. + // Therefore, we need to ignore the first empty argument list. // This is needed for the test tests/neg/i12344.scala // // see NamerOps.normalizeIfConstructor // if args == Nil - && fn.symbol.isConstructor && !fn.isInstanceOf[Apply] && app.tpe.isImplicitMethod + && fn.symbol.isConstructor then meth else spliceMeth(meth, fn).appliedToArgs(args) case TypeApply(fn, targs) => From c8b823fd300ee3b56655a0adbe4bcdf59212e416 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 6 May 2021 19:12:46 +0200 Subject: [PATCH 3/3] Add test --- tests/neg/i12344.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/neg/i12344.scala b/tests/neg/i12344.scala index ce0aceacb729..88daf535e699 100644 --- a/tests/neg/i12344.scala +++ b/tests/neg/i12344.scala @@ -21,3 +21,6 @@ def test1d(using q: Quotes) = C(using q)() def test2d(using q: Quotes) = C(using q)(1) def test3d(using q: Quotes) = C(using q)(1, q.reflect.Flags.Lazy) def test4d(using q: Quotes) = C(using q)(f = q.reflect.Flags.Lazy) + +def test1e(using q: Quotes) = new C()() +def test2e(using q: Quotes) = C()()