Skip to content

Can ToString[.] type be made applicable to arbitrary type by converting its symbol name as singleton? #182

@tribbloid

Description

@tribbloid

I have posted a stackoverflow question on this:

https://stackoverflow.com/questions/66837880/how-to-get-the-name-of-a-class-as-a-string-literal-at-compile-time-using-shapele

According to Prof. @DmytroMitin, it appears that a whitebox macro is the only option, fortunately it is not too complex, in dotty it may be introduced as a compiletime ops later

This feature, combining with RequireMsg[.] type, can be used to throw a customised ops error at compile-time, using a string interpolated with custom user type (https://twitter.com/soronpo/status/1275014596034809856). Similar to how @implicitNotFound error message is interpolated in native scala:

@implicitNotFound(msg = "Cannot prove that ${From} =:= ${To}.")
sealed abstract class =:=[From, To] extends (From <:< To) with Serializable {
...
}

Do you think this will be useful? I can submit a PR shortly but I may need some guidance to circumvent the NonLiteral constraint

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions