-
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
Add class term parameters, flags, and privateWithin to newClass in reflect API #21880
base: main
Are you sure you want to change the base?
Add class term parameters, flags, and privateWithin to newClass in reflect API #21880
Conversation
* | ||
* Parameters can be obtained via classSymbol.memberField | ||
*/ | ||
@experimental def newClass(parent: Symbol, name: String, parents: List[TypeRepr], decls: Symbol => List[Symbol], selfType: Option[TypeRepr], paramNames: List[String], paramTypes: List[TypeRepr], flags: Flags, privateWithin: 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.
would it be possible to reformulate such that parents
is also a function (to support param refs?)
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.
Do you mean that it should be a Symbol => List[TypeRepr]
type? I have some trouble visualizing where we would need that classSymbol to define the parent TypeRepr (class Cls extends Cls.InnerCls
?, is that legal?). Could you give me an example of a tree like that?
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 saw class Cls extends Cls.InnerCls
in the wild but in that case, Cls also had a companion object which contained InnerCls - not sure if that is possible to define right now but I'll have to look into the newModule method and see if it also needs updates
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 mean something like class anon(x: Int) extends Box[x.type]
- I don't know the best solution, but this would be good to be able to support I assume - same with tracked eventually, but maybe that can be cleanly added later?
28cb854
to
33fbd5f
Compare
import quotes.reflect.* | ||
|
||
val name = nameExpr.valueOrAbort | ||
val parents = List(TypeTree.of[Object]) |
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 should be a test case where the parent needs an argument supplied via the constructor parameters
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 tried doing that in the not-very-well-named tests/run-macros/newClassParamsExtendsClassParams, which generates something like this:
'{
class `name`(idx: Int) extends Foo(idx)
new `name`(22)
}
Or do you mean something else?
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.
yeah that looks good
To be clear, this is not ready, I did put this up since I wanted some feedback if anyone had some (Thank You @bishabosha!) and did not want to rush it last minute, that's why it a draft |
Still some TODOs here, like tests for flags and privateWithin, scaladoc, adding assertions and adding similar updates to newModule. I probably will need to split off the changes relating to
-Xmacro-check
from here to a separate PR.Fixes #21739 and addresses some old TODOs