Skip to content

Impossible to extends "Ordered" when "-Yexplicit-nulls" flag used #11341

Closed
@flomebul

Description

@flomebul

Compiler version

scala version 3.0.0-M3

Minimized code

object Issue11341 {
  class ClsA(i: Int) extends Ordered[ClsA] {
    def compare(that: ClsA): Int = ???

    // Members declared in java.lang.Comparable
    override def compareTo(that: ClsA | UncheckedNull): Int = ???
  } 

  class ClsB(i: Int) extends Ordered[ClsB] {
    def compare(that: ClsB): Int = ???

    // Members declared in java.lang.Comparable
    override def compareTo(that: ClsB): Int = ???
  } 

  class ClsC(i: Int) extends Ordered[ClsC] {
    def compare(that: ClsC): Int = ???
  } 
}

Output

def compareTo(that: asuivre.Issue11341.ClsA | UncheckedNull): Int
error overriding method compareTo in trait Ordered of type (that: asuivre.Issue11341.ClsA): Int;
  method compareTo of type (that: asuivre.Issue11341.ClsA | UncheckedNull): Int has incompatible type

class ClsB: asuivre.Issue11341.ClsB
class ClsB needs to be abstract, since def compareTo(x$0: T | UncheckedNull): Int is not defined 
(Note that T | UncheckedNull does not match asuivre.Issue11341.ClsB)

def compareTo(that: asuivre.Issue11341.ClsB): Int
error overriding method compareTo in trait Comparable of type (x$0: asuivre.Issue11341.ClsB | UncheckedNull): Int;
  method compareTo of type (that: asuivre.Issue11341.ClsB): Int has incompatible type

class ClsC: asuivre.Issue11341.ClsC
class ClsC needs to be abstract, since def compareTo(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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions