slinc icon indicating copy to clipboard operation
slinc copied to clipboard

Struct field alias

Open donderom opened this issue 2 years ago • 5 comments

Is there any way to map the following definition

case class foo(type: Int, value: Int) derives Struct

where type is a keyword in Scala?

donderom avatar Aug 02 '23 10:08 donderom

@donderom Have you tried

case class foo(`type`: Int, value: Int) derives Struct

?

azolotko avatar Aug 02 '23 10:08 azolotko

It might work but I can only pass such a structure, and it looks like, in this case, the field name doesn't even matter.

donderom avatar Aug 02 '23 17:08 donderom

Field names don't matter for struct defiinitions, only the order of members.

re: `type`, this works, but using backtick names in Scala is always a bit clumsy. If you want to name a struct member this way, go ahead, but I'd suggest using a name that will not require wrapping it in backticks.

markehammons avatar Aug 03 '23 08:08 markehammons

Ok, so it's only function names that matter, isn't it?

donderom avatar Aug 03 '23 09:08 donderom

Yes. Function names are used for symbol lookup. There are ways to do platform specific overrides of symbol lookup though.

markehammons avatar Aug 09 '23 12:08 markehammons