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

Null should be subtype of non-value classes #501

Open
hearnadam opened this issue Dec 18, 2024 · 5 comments
Open

Null should be subtype of non-value classes #501

hearnadam opened this issue Dec 18, 2024 · 5 comments

Comments

@hearnadam
Copy link

/** `Null` is - together with [[scala.Nothing]] - at the bottom of the Scala type hierarchy.
  *
  * `Null` is the type of the `null` literal. It is a subtype of every type
  * except those of value classes. Value classes are subclasses of [[AnyVal]], which includes
  * primitive types such as [[Int]], [[Boolean]], and user-defined value classes.
  *
  * Since `Null` is not a subtype of value types, `null` is not a member of any such type.
  * For instance, it is not possible to assign `null` to a variable of type [[scala.Int]].
  */
sealed trait Null
import izumi.reflect.Tag

Tag[Null] <:< Tag[String] // returns false
@pshirshov
Copy link
Member

Do you really have a practical usecase for this? I've intentionally made our rules simpler than they are in the compiler in order to save a couple pennies of the performance.

If you really need this, new special cases should be introduced around this place: https://github.com/zio/izumi-reflect/blob/develop/izumi-reflect/izumi-reflect/src/main/scala/izumi/reflect/macrortti/LightTypeTagInheritance.scala#L74

@hearnadam
Copy link
Author

I don't have a direct usecase, I was actually testing my own Tag encoding against izumi and hit this. I suspect it would be only useful in unions, if that enables you any optimization:

@pshirshov
Copy link
Member

my own Tag encoding against izumi

May I have a look please? I would be happy to add it into our list of relevant projects.

@hearnadam
Copy link
Author

I haven't worked on it in some time, but the idea builds on the existing kyo-tag system, but encoded unions and intersections in a single String: https://github.com/getkyo/kyo/pull/948/files

This has many benefits on the JVM, but does not lead to a simple implementation. There are some core bugs I need to solve.

@pshirshov
Copy link
Member

Interesting. Is it a scala3-only project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants