-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
// | ||
// see NamerOps.normalizeIfConstructor | ||
// | ||
if args == Nil | ||
&& !fn.isInstanceOf[Apply] | ||
&& app.tpe.isImplicitMethod | ||
&& fn.symbol.isConstructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.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 | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
There was a problem hiding this comment.
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)