Skip to content
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

Splicing of default getters should not special case constructors with implicits #22344

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
16 changes: 1 addition & 15 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,7 @@ 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) =>
// 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
Copy link
Member Author

@hamzaremmal hamzaremmal Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to keep track of some info, this test is now tests/neg-macros/i12344.scala and it seems that some of the discussions that led to this change are not relevant now (See #12344 (comment) and https://github.com/scala/scala3/pull/14840/files#diff-a602b2ba421d0da906b1d1915ca14c84b336da38e2ab907b695c441c5d58f5b3)

//
// see NamerOps.normalizeIfConstructor
//
if args == Nil
&& !fn.isInstanceOf[Apply]
&& app.tpe.isImplicitMethod
&& fn.symbol.isConstructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should rather add another condition that checks if meth actually requires the empty argument list i.e.

&& !meth.tpe.widen.isNullaryMethod

then meth
else spliceMeth(meth, fn).appliedToArgs(args)
case Apply(fn, args) => 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
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i22061.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abstract class A()(implicit val x: Int = 3)
trait B extends A

abstract class C()(using y: Int = 9)
class D extends C()
Comment on lines +1 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you extend the test case to one that also includes the syntactically inserted param lists, you will see that the current fix doesn't work. Test case:

abstract class A()(implicit val x: Int = 3)
class A1 extends A
class A2 extends A()

abstract class B()(using y: Int = 9)
class B1 extends B
class B2 extends B()

abstract class C(implicit val x: Int = 3)
class C1 extends C
class C2 extends C()

abstract class D(using y: Int = 9)
class D1 extends D
class D2 extends D()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably even extend it to:

abstract class A()(implicit val x: Int = 3)
class A1 extends A
class A2 extends A()

abstract class B()(using y: Int = 9)
class B1 extends B
class B2 extends B()

abstract class C(implicit val x: Int = 3)
class C1 extends C
class C2 extends C()

abstract class D(using y: Int = 9)
class D1 extends D
class D2 extends D()

abstract class E()(implicit val x: Int = 3, val y: Int = 4)
class E1 extends E
class E2 extends E()

abstract class F()(using y: Int = 9, x: Int = 8)
class F1 extends F
class F2 extends F()

abstract class G(implicit val x: Int = 3, val y: Int = 4)
class G1 extends G
class G2 extends G()

abstract class H(using y: Int = 9, x: Int = 8)
class H1 extends H
class H2 extends H()

Loading