-
Notifications
You must be signed in to change notification settings - Fork 21
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
Concrete classes can have abstract type members #1753
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1753?orig=1 |
Geoffrey Alan Washburn (washburn) said: |
@DRMacIver said: I find it rather surprising (I found it during a presentation while explaining abstract type members, and both Miles and I were baffled), but will assume there's a good reason for it. :-) |
@milessabin said: Welcome to Scala version 2.7.3.final (Java HotSpot(TM) Server VM, Java 1.6.0_10).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class C { type T }
defined class C
scala> object O extends C
defined module O
scala> var v1 : O.T = _
v1: O.T = null
scala> val v2 : Any = v1
v2: Any = null
scala> val v3 : AnyVal = v1
<console>:7: error: type mismatch;
found : O.T
required: AnyVal
val v3 : AnyVal = v
^
scala> val v4 : AnyRef = v1
<console>:7: error: type mismatch;
found : O.T
required: AnyRef
Note that implicit conversions are not applicable because they are ambiguous:
both method any2stringadd in object Predef of type (Any)scala.runtime.StringAdd
and method any2ArrowAssoc in object Predef of type [A](A)ArrowAssoc[A]
are possible conversion functions from O.T to AnyRef
val v4 : AnyRef = v
^ So T is <: of Any, but not of AnyVal or AnyRef, even though null inhabits T? |
@odersky said: yes.
Null inhabits T only because you sneakily forgot to initialize the |
@ingoem said: |
@odersky said: |
@Blaisorblade said: However, this does not describe why it is forbidden to have: object Baz { type T } See #8217 for that. |
The following compiles:
I'm not 100% sure I'm not missing something in the SLS about default of type members, but I can't find anything.
The text was updated successfully, but these errors were encountered: