-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Type overriding does not result in type intersection #241
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
Comments
No, it should be
which is an unsatisfiable type. The test that flags these as errors is still missing. This needs to be part of the "new refchecks" which is yet to be done. |
Okay, related question: class A { type T = Int; val x: T = 1 }
type B = A { override type T = String } Should this fail for the same reason, or do we want to disallow refinement to all existing members? |
Good question. According to DOT this would be correct. We check for satisfiable bounds only when creating an object. Whether we want to enforce the same in the compiler or something stronger is currently open. |
Oh, so unsatisfiable types are allowed and are not a hole in the type system as long as you don't use something like |
@samuelgruetter : What's the significance of the lazy? Your example compiles without it too. |
Here's something to keep in mind when doing the "new refchecks": The remark
is somewhat incomplete: If we do not check that types have their bounds in an overriding relationship during refchecks, it's not sufficient to form their intersection when selecting, but we also have to do an additional test when creating new objects: When instantiating a class trait A {
type S <: T
type T <: U
type U
def s2u(s: S): U = (s: T)
}
trait Converter {
type S >: String
type U <: Int
def s2u(s: S): U
}
class B extends A with Converter
class C extends B {
override type S = R
override type T = R
override type U = R
}
// a completely unrelated realizable class:
class R {}
object test2 {
// Here it's not sufficient to check that the bounds given in C are satisfiable,
// but we also have to check that they are compatible with all overridden bounds
val c = new C
val co: Converter = c
val myStringAsInt: Int = co.s2u("hi")
} |
@samuelgruetter: It seems to me that in #50 o.X should have type bounds (String | Int)..(String & Int) and intToString is invalid because Int is not a subtype of this type, so everything would be fine if the type of o.X was correct |
@smarter whether |
Comment explains why following aliases in general is incomplete and potentially unsound. This makes Iter2 compile, but causes cyclic reference errors for pos/sets.scala.
Closes scala#241 -- that took a while!
The following:
Compiles without any error.
RefChecks.scala mentions:
Should b.x have the type "Int | String" ?
CC @odersky @DarkDimius @namin .
The text was updated successfully, but these errors were encountered: