You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is this difference in behavior in Scala 2 vs dotty intentional or a bug?
// Scala 2.12.8
scala>traitX { overridedeftoString=super.toString +" X" }
defined traitX
scala>traitY { overridedeftoString=super.toString +" Y" }
defined traitY
scala>classZextendsXwithY { overridedeftoString=super.toString +" Z" }
defined classZ
scala>newZ
res1:Z=Z@20a24edf XYZ
In dotty
// dotty 0.14.0-bin-20190312-3c9935f-NIGHTLY
scala>traitX { overridedeftoString=super.toString +" X" }
|traitY { overridedeftoString=super.toString +" Y" }
|classZextendsXwithY { overridedeftoString=super.toString +" Z" }
|3|classZextendsXwithY { overridedeftoString=super.toString +" Z" }
|^|classZ cannot be defined due to a conflict between its parents when
| implementing a super-accessor for toString in traitY:||1. One of its parent (Y) contains a call super.toString in its body,
| and when a super-call in a traitis written without an explicit parent
| listed in brackets, it is implemented by a generated super-accessor in
| the classthatextendsthistraitbased on the linearization order of
| the class.
|2. BecauseX comes before Y in the linearization
| order of Z, and because X overrides toString,
| the super-accessor in Z is implemented asa call to
|super[X].toString.
|3. However,
|String (the typeofsuper[X].toString in Z)
| is not a subtype of
| ():String (the typeof toString in traitY).
|Hence, the super-accessor that needs to be generated in Z| is illegal.
||Here are two possible ways to resolve this:||1. Change the linearization order of Z such that
|Y comes before X.
|2. Alternatively, replace super.toString in the body of traitY by a
|super-call to a specific parent, e.g. super[Object].toString
I wonder why 3 talks about the subtype of (): String.
And if I follow proposal 1 from this error message it is still an error and proposal 2 gives this:
scala>traitX { overridedeftoString=super[Object].toString +" X" }
|traitY { overridedeftoString=super[Object].toString +" Y" }
|classZextendsXwithY { overridedeftoString=super.toString +" Z" }
|// defined trait X// defined trait Y// defined class Z
scala>newZvalres0:Z=Z@30a3e9b YZ
Compared to Scala 2 which also prints X ...
Shouldn't the behavior in Scala 2 and dotty be the same when not specifying parent super[Object] ?
The text was updated successfully, but these errors were encountered:
Is this difference in behavior in Scala 2 vs dotty intentional or a bug?
In dotty
I wonder why 3 talks about the subtype of
(): String
.And if I follow proposal 1 from this error message it is still an error and proposal 2 gives this:
Compared to Scala 2 which also prints
X
...Shouldn't the behavior in Scala 2 and dotty be the same when not specifying parent super[Object] ?
The text was updated successfully, but these errors were encountered: