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
Singleton Types for Value Classes #379
Comments
Would you mind taking a look to see if this is still an issue for shapeless-2.2.2? |
On master (2.2.3) it's still odd that the following compiles: object PathDependentSingleton3 {
val x = new ValueTest(5)
val wX = Witness(x)
} Since it's invalid Scala to reference the singleton type of a Value class: object PathDependentSingleton3 {
val x = new ValueTest(5)
val wX = Witness(x)
implicitly[wX.T =:= x.type]
}
[error] found : shapeless.SingletonTypesTests.PathDependentSingleton3.x.type (with underlying type shapeless.ValueTest)
[error] required: AnyRef
[error] Note that ValueTest extends Any, not AnyRef.
[error] Such types can participate in value classes, but instances
[error] cannot appear in singleton types or in reference comparisons.
[error] implicitly[wX.T =:= x.type] I think it's best not to allow Value classes in Witness at all, right? That's what I meant in the original post, this behavior might confuse people unless it's explicitly stated somewhere. |
Agreed. It's just that there were some changes in the Thanks for the update :-) |
This decision has been reversed in e70f01e. As of SIP-23 value types do admit singleton types of this form, and the exclusion no longer seems well motivated. |
This compiles just fine but I have no idea what
XT
is supposed to be here.x.type
is an invalid expression sincex
is not subclassingAnyRef
so I'm not sure if this behavior is intended?If it is then Shapeless Witness macros add support for singleton types on value classes by treating them as reference types which may lead to un{expected, documented} behavior? An example that could possibly confuse people:
The text was updated successfully, but these errors were encountered: