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
objectIssue11341 {
classClsA(i: Int) extendsOrdered[ClsA] {
defcompare(that: ClsA):Int=???// Members declared in java.lang.ComparableoverridedefcompareTo(that: ClsA|UncheckedNull):Int=???
}
classClsB(i: Int) extendsOrdered[ClsB] {
defcompare(that: ClsB):Int=???// Members declared in java.lang.ComparableoverridedefcompareTo(that: ClsB):Int=???
}
classClsC(i: Int) extendsOrdered[ClsC] {
defcompare(that: ClsC):Int=???
}
}
Output
defcompareTo(that: asuivre.Issue11341.ClsA|UncheckedNull):Int
error overriding method compareTo in traitOrdered of type (that: asuivre.Issue11341.ClsA):Int;
method compareTo of type (that: asuivre.Issue11341.ClsA|UncheckedNull):Int has incompatible typeclassClsB: asuivre.Issue11341.ClsBclassClsB needs to be abstract, since defcompareTo(x$0: T|UncheckedNull):Int is not defined
(Note that T|UncheckedNull does not match asuivre.Issue11341.ClsB)
defcompareTo(that: asuivre.Issue11341.ClsB):Int
error overriding method compareTo in traitComparable of type (x$0: asuivre.Issue11341.ClsB|UncheckedNull):Int;
method compareTo of type (that: asuivre.Issue11341.ClsB):Int has incompatible typeclassClsC: asuivre.Issue11341.ClsCclassClsC needs to be abstract, since defcompareTo(x$0: T|UncheckedNull):Int is not defined
(Note that T|UncheckedNull does not match asuivre.Issue11341.ClsC)
Expectation
I suppose that the case "ClsC" is the right one, as it is the case without the "-Yexplicit-nulls" flag.
The text was updated successfully, but these errors were encountered:
I tested this example using the new explicit nulls PR #9884 (We no longer have UncheckedNull, so it need to be repleced by Null).
The output is:
| override def compareTo(that: ClsA | Null): Int = ???
| ^
|error overriding method compareTo in trait Ordered of type (that: ClsA): Int;
| method compareTo of type (that: ClsA | Null): Int has incompatible type
I think this is expected in the current design. In the PR, we have a relaxed overriding rule when the overrided member is defined in Java.
However in this case, Ordered is a scala trait, and it overrides the compareTo function. Therefore, compareTo becomes a scala function and the special rule doesn't apply. The only way to override compareTo here is override def compareTo(that: ClsA): Int.
In theory, we may compare an object to a null pointer, but the current standard lib is not compiled using explicit nulls, we are unable to add | Null to the param type.
A workaround is to cast that: ClsA to ClsA | Null and then compare it to null.
Compiler version
scala version 3.0.0-M3
Minimized code
Output
Expectation
I suppose that the case "ClsC" is the right one, as it is the case without the "-Yexplicit-nulls" flag.
The text was updated successfully, but these errors were encountered: