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 a method to create a new type symbol #19448

Open
nicolasstucki opened this issue Jan 15, 2024 · 2 comments · May be fixed by #20347
Open

Add a method to create a new type symbol #19448

nicolasstucki opened this issue Jan 15, 2024 · 2 comments · May be fixed by #20347
Assignees
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:enhancement

Comments

@nicolasstucki
Copy link
Contributor

How can I get a type symbol for a type alias to use TypeDef.apply?

You can get it from an existing type alias. We currently do not have a method to create new type symbol. We might want to add this as Symbol.newType or Symbol.newTypeAlias.

Originally posted by @nicolasstucki in #19344 (comment)

@nicolasstucki nicolasstucki added the area:metaprogramming:reflection Issues related to the quotes reflection API label Jan 15, 2024
@nicolasstucki nicolasstucki changed the title > How can I get a type symbol for a type alias to use TypeDef.apply? How can I get a type symbol for a type alias to use TypeDef.apply? Jan 15, 2024
@Gedochao Gedochao changed the title How can I get a type symbol for a type alias to use TypeDef.apply? Add a method to create a new type symbol Jan 16, 2024
@hamzaremmal hamzaremmal self-assigned this Feb 1, 2024
@jchyb
Copy link
Contributor

jchyb commented Apr 3, 2024

I was asked by @Gedochao to elaborate a bit on the requirements here.

The idea is to add Symbol.newType in scala.quoted.Quotes.reflectModule.SymbolModule implementation, which would generate a type alias/type member. This method would likely have a signature like:

def newType(parent: Symbol, name: String, tpe: TypeRepr)

It would have to work with the preexisting TypeDef.apply(symbol: Symbol), which means:

  1. the aliased type should be included in the Symbol definition
  2. the resulting type alias/member either cannot be made abstract, or we should include that information in Symbol.newType(parent: Symbol, name: String, tpe: Option[TypeRepr]).

I would personally prefer if it could be made abstract for completeness' sake, but the original issue raised in the discussion linked above does not require that.

@pweisenburger
Copy link
Contributor

the resulting type alias/member either cannot be made abstract, or we should include that information in Symbol.newType(parent: Symbol, name: String, tpe: Option[TypeRepr]).

Generally, type members define a lower and an upper bound. Maybe newType should take a TypeBounds instead of a TypeRepr (abstract types without explicit bounds could then be created using TypeBounds.empty):

def newType(parent: Symbol, name: String, bounds: TypeBounds)

I think, this would also be more consistent with the rest of the API.

Please also allow for passing a flags and a privateWithin argument, like for newMethod and newVal (unfortunately, newClass is missing this feature but it should also have it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants