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
Return type inference should use type of overridden method (rather than infer locally from overridden's rhs) #8159
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8159?orig=1 |
@som-snytt said (edited on Jan 18, 2014 4:51:05 AM UTC): I thought I saw a ticket after that. (#7212) |
@som-snytt said: http://stackoverflow.com/a/21198284/1296806 The distinction is between "Scala is buggy" and "Scala is greatly improved." |
Giovanni Botta (giodude) said: |
@adriaanm said: |
@adriaanm said: |
Giovanni Botta (giodude) said: class A{
def x: Option[String] = None
}
class B extends A{
override def x: None = None
}
// should NOT compile
class C extends B{
override def x = Some("123")
}
class D extends A{
override def x = None
}
// should compile
class E extends D{
override def x = Some("123")
} Am I right? |
@som-snytt said: But does the inference guide kick in only on explicit override, or also for impl of abstract member? |
Giovanni Botta (giodude) said: |
@adriaanm said: Regarding to your first question, neither C nor E should compile (even after you correct B to use None.type for x's return type) |
@som-snytt said: But the Scala way is to have intuitive rules with unintuitive edge cases, not the other way around! Otherwise, there would be no puzzlers. |
@som-snytt said: |
Given the following code:
The compiler seems to infer the type of C.x as None.type so D doesn't compile.
The text was updated successfully, but these errors were encountered: