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 type has wrong bounds. #1273

Closed
scabug opened this Issue Aug 22, 2008 · 6 comments

Comments

Projects
None yet
5 participants
@scabug

scabug commented Aug 22, 2008

A singleton type is always inhabited by an object reference, and null. Hence the type Singleton should have bounds >: Null <: AnyRef. However, this is not currently the case:

scala> trait T { type X >: Null <: AnyRef }
defined trait T

scala> new T { type X = Singleton }
<console>:6: error: error overriding type X in trait T with bounds >: Null <: AnyRef;
 type X has incompatible type Singleton
       new T { type X = Singleton }

In particular it seems obviously erroneous that Null <: Singleton doesn't hold, since Null <: a.type and a.type <: Singleton for any reference a. So the transitivity of type conformance seems to be broken.

@scabug

This comment has been minimized.

Show comment
Hide comment
@scabug

scabug Aug 22, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1273?orig=1
Reporter: Lauri Alanko (lealanko)

scabug commented Aug 22, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1273?orig=1
Reporter: Lauri Alanko (lealanko)

@scabug

This comment has been minimized.

Show comment
Hide comment
@scabug

scabug Aug 28, 2008

@odersky said:
The status of singleton types and null is most likely to be reviewed soon. Postponed until then.

scabug commented Aug 28, 2008

@odersky said:
The status of singleton types and null is most likely to be reviewed soon. Postponed until then.

@scabug

This comment has been minimized.

Show comment
Hide comment
@scabug

scabug Jan 14, 2009

@odersky said:
Milestone postponed deleted

scabug commented Jan 14, 2009

@odersky said:
Milestone postponed deleted

@scabug

This comment has been minimized.

Show comment
Hide comment
@scabug

scabug Jun 7, 2010

@paulp said:
Can I rescue this from postponement? I think the ticket as reported unintentionally misrepresents the issue, possibly making it appear deeper than it is. It's actually broken worse than is shown, but at the same time, is easier to fix. The problem is that SingletonClass is assigned Any as a parent, not AnyRef. So forget the lower bound, even <: AnyRef is enough to exclude it.

The good news though is that that's the same reason the lower bound is wrong, and assigning AnyRef as the parent fixes that too. Making this change doesn't seem to bother the compiler in the least. All builds, all passes.

Specwise, from my reading of it all singleton types must descend from AnyRef, but the same is not explicitly said of scala.Singleton. Someone reading it would be rather likely to think Singleton <: AnyRef. Perhaps it should be worded more clearly regardless of outcome.

A singleton type is of the form p.type, where p is a path pointing to a value expected to conform (�6.1) to scala.AnyRef. The type denotes the set of values consisting of null and the value denoted by p.
A stable type is either a singleton type or a type which is declared to be a subtype of trait scala.Singleton.

scabug commented Jun 7, 2010

@paulp said:
Can I rescue this from postponement? I think the ticket as reported unintentionally misrepresents the issue, possibly making it appear deeper than it is. It's actually broken worse than is shown, but at the same time, is easier to fix. The problem is that SingletonClass is assigned Any as a parent, not AnyRef. So forget the lower bound, even <: AnyRef is enough to exclude it.

The good news though is that that's the same reason the lower bound is wrong, and assigning AnyRef as the parent fixes that too. Making this change doesn't seem to bother the compiler in the least. All builds, all passes.

Specwise, from my reading of it all singleton types must descend from AnyRef, but the same is not explicitly said of scala.Singleton. Someone reading it would be rather likely to think Singleton <: AnyRef. Perhaps it should be worded more clearly regardless of outcome.

A singleton type is of the form p.type, where p is a path pointing to a value expected to conform (�6.1) to scala.AnyRef. The type denotes the set of values consisting of null and the value denoted by p.
A stable type is either a singleton type or a type which is declared to be a subtype of trait scala.Singleton.
@scabug

This comment has been minimized.

Show comment
Hide comment
@scabug

scabug Jun 23, 2016

@milessabin said:
As of the work on SIP-23 we want Singleton <: Any so I think the current behaviour becomes correct once that branch is merged.

scabug commented Jun 23, 2016

@milessabin said:
As of the work on SIP-23 we want Singleton <: Any so I think the current behaviour becomes correct once that branch is merged.

@scabug

This comment has been minimized.

Show comment
Hide comment
@scabug

scabug commented Aug 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment