-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Check flags for newMethod
, newVal
and newBind
#16565
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
e4ddc97
to
b60afdc
Compare
b60afdc
to
164e407
Compare
* A trait that has only abstract methods as members | ||
* and therefore can be represented by a Java interface. |
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.
That description looks incorrect abstract override
is a specific concept in Scala that is unrelated to Java interfaces: https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#abstract-override
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.
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 part of the documentation comment is for PureInterface, not for AbsOverride
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.
I updated the docs.
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.
I noticed that AbsOverride
is pickled as Abstract | Override
and then unpickled as AbsOverride
. Maybe we should not have this flag in the reflection interface and handle AbsOverride
as if both Abstract
and Override
.
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.
I noticed that AbsOverride is pickled as Abstract | Override and then unpickled as AbsOverride. Maybe we should not have this flag in the reflection interface and handle AbsOverride as if both Abstract and Override.
I'm not sure diverging from the compiler implementation is a good idea here. In the specification, abstract override
is a separate concept from abstract
and override
, it just reuses existing keywords. The tasty serialization format also reuses the flags bits, but that's just an optimization.
@@ -2484,13 +2486,28 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |||
def newMethod(owner: Symbol, name: String, tpe: TypeRepr): Symbol = | |||
newMethod(owner, name, tpe, Flags.EmptyFlags, noSymbol) | |||
def newMethod(owner: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol = | |||
import Flags.* | |||
// TODO: missing AbsOverride | |||
checkValidFlags(flags.toTermFlags, Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | JavaStatic) // Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible |
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.
It would be nicer to create a val for each of these long lists of flags. Also couldn't this be checked in -Ycheck?
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.
The idea of the -Xcheck-macros
flag is to help users find the location in their implementation where the bug started. Additionally, waiting until -Ycheck
can result in other derived failures or crashes before we reach the checks.
9fdfb4a
to
09cf574
Compare
959064f
to
a85d0ea
Compare
a85d0ea
to
a4db0c1
Compare
a4db0c1
to
91a6b57
Compare
private[QuotesImpl] def validMethodFlags: Flags = Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | JavaStatic | AbsOverride // Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible | ||
private[QuotesImpl] def validValFlags: Flags = Private | Protected | Override | Deferred | Final | Param | Implicit | Lazy | Mutable | Local | ParamAccessor | Module | Package | Case | CaseAccessor | Given | Enum | JavaStatic | AbsOverride // Synthetic | Erased | Invisible | ||
private[QuotesImpl] def validBindFlags: Flags = Case // | Implicit | Given | Erased |
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.
What are the commented-out flags meant to represent? A comment might be helpful.
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.
Added comments
@@ -2842,6 +2854,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |||
def Synthetic: Flags = dotc.core.Flags.Synthetic | |||
def Trait: Flags = dotc.core.Flags.Trait | |||
def Transparent: Flags = dotc.core.Flags.Transparent | |||
|
|||
private[QuotesImpl] def validMethodFlags: Flags = Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | JavaStatic | AbsOverride // Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible |
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.
- It looks like the list here is duplicated in the documentation of newMethod, we should add a comment here to remember to update the list in the documentation.
- I don't think users can create JavaStatic methods.
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.
I don't think users can create JavaStatic methods.
We have one use case of this with the main macro annotation in tests/run-macros/annot-macro-main
.
@@ -3816,7 +3816,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => | |||
* | |||
* @param parent The owner of the binding | |||
* @param name The name of the binding | |||
* @param flags extra flags to with which the symbol should be constructed | |||
* @param flags extra flags to with which the symbol should be constructed. `Case` flag will be added. Can be `Case` |
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.
If Case is always added and Case is the only valid flag, it sounds like this parameter is not actually necessary?
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.
In the future, we might have more flags (see validBindFlags
).
We could add an overload of newBind
that does not require the flags.
d3a9810
to
d04a7e2
Compare
Co-authored-by: Guillaume Martres <[email protected]>
d04a7e2
to
3c3c0fb
Compare
No description provided.