Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Nov 3, 2024

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

@jchyb jchyb added the needs-minor-release This PR cannot be merged until the next minor release label Nov 3, 2024
*
* 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
Copy link
Member

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?)

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Member

@bishabosha bishabosha Nov 5, 2024

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?

@jchyb jchyb force-pushed the improvement/quotes-new-class-upgrades branch from 28cb854 to 33fbd5f Compare November 4, 2024 11:13
import quotes.reflect.*

val name = nameExpr.valueOrAbort
val parents = List(TypeTree.of[Object])
Copy link
Member

@bishabosha bishabosha Nov 4, 2024

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

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that looks good

@tgodzik tgodzik requested a review from sjrd November 6, 2024 15:51
@jchyb
Copy link
Contributor Author

jchyb commented Nov 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol.newClass does not support class parameters
2 participants