diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 2d30b925a7eb..79cafc26e6f0 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 argument list. + // This is needed for the test tests/neg/i12344.scala + // + // see NamerOps.normalizeIfConstructor + // + if args == Nil + && !fn.isInstanceOf[Apply] + && app.tpe.isImplicitMethod + && fn.symbol.isConstructor + 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..88daf535e699 --- /dev/null +++ b/tests/neg/i12344.scala @@ -0,0 +1,26 @@ +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) + +def test1e(using q: Quotes) = new C()() +def test2e(using q: Quotes) = C()()