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

Conversation

hamzaremmal
Copy link
Member

Closes #22061

@hamzaremmal hamzaremmal self-assigned this Jan 10, 2025
// 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)

Comment on lines +1 to +5
abstract class A()(implicit val x: Int = 3)
trait B extends A

abstract class C()(using y: Int = 9)
class D extends C()
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()

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When a trait which extends a class with constructor is initialised directly, it may give confusing message
2 participants