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

Singleton Types for Value Classes #379

Closed
tzbob opened this issue May 4, 2015 · 4 comments
Closed

Singleton Types for Value Classes #379

tzbob opened this issue May 4, 2015 · 4 comments
Assignees
Labels

Comments

@tzbob
Copy link

tzbob commented May 4, 2015

  class ValueTest(val x: Int) extends AnyVal

  object PathDependentSingleton2 {
    val x = new ValueTest(5)
    val wX = Witness(x)
    type XT = wX.T
  }

This compiles just fine but I have no idea what XT is supposed to be here. x.type is an invalid expression since x is not subclassing AnyRef 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:

    val x = new ValueTest(5)
    val y = new ValueTest(5)
    val wX = Witness(x)
    val wY = Witness(y)
    implicitly[wX.T =:= wY.T]
@milessabin
Copy link
Owner

Would you mind taking a look to see if this is still an issue for shapeless-2.2.2?

@tzbob
Copy link
Author

tzbob commented Jun 16, 2015

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.

@milessabin
Copy link
Owner

Agreed. It's just that there were some changes in the Witness materializer in 2.2.2 and it was at least conceivable that this might have come out in the wash.

Thanks for the update :-)

@milessabin
Copy link
Owner

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.

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

No branches or pull requests

2 participants