-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add reflect newMethodOverride and newValOverride #15041
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
Conversation
c4bef92
to
9fbb3b4
Compare
0886295
to
bbebc00
Compare
* @param overridden The symbol being overridden | ||
*/ | ||
@experimental | ||
def newMethodOverride(parent: Symbol, overridden: Symbol): Symbol |
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.
This API isn't flexible enough to handle situations where you need to override two methods at once. For example:
trait X; trait Y
trait A { def foo: X }
trait B { def foo: Y }
class C extends A with B {
// ...
}
In C, if I try to override only A#foo
or only B#foo
, I will get a type error, I'm forced to override both at once.
@@ -3687,6 +3696,15 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => | |||
*/ | |||
def newVal(parent: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol | |||
|
|||
/** Generates a new `val` or `lazy val` symbol that overrides another definition. |
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.
Does it also work with var
?
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.
No. This design does not compose well. It might be better to have an API to compute the methodic type of the override signature and use the other newVal
overloads to create the symbol with the appropriate flags. This would require the introduction of .info
.
bbebc00
to
2489fe5
Compare
Closes #15035