Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

nicolasstucki
Copy link
Contributor

Closes #15035

@nicolasstucki nicolasstucki self-assigned this May 23, 2022
@nicolasstucki nicolasstucki force-pushed the fix-15035 branch 3 times, most recently from 0886295 to bbebc00 Compare November 23, 2022 13:59
@nicolasstucki nicolasstucki marked this pull request as ready for review November 25, 2022 08:58
* @param overridden The symbol being overridden
*/
@experimental
def newMethodOverride(parent: Symbol, overridden: Symbol): Symbol
Copy link
Member

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.
Copy link
Member

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?

Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

A reflect newMethodOverride
2 participants