Skip to content

Default leq method for Reals seems inconsistent with docstring #46327

@jishnub

Description

@jishnub
julia> struct A <: Real end

julia> Base.:(==)(::A, ::A) = false

julia> Base.:(<)(::A, ::A) = false

julia> x = A(); y = x;

julia> (x < y) | (x == y)
false

julia> x <= y
ERROR: <= not defined for A
Stacktrace:
 [1] error(::String, ::String, ::Type)
   @ Base ./error.jl:44
 [2] no_op_err(name::String, T::Type)
   @ Base ./promotion.jl:484
 [3] <=(x::A, y::A)
   @ Base ./promotion.jl:501
 [4] top-level scope
   @ REPL[11]:1

help?> <=
search: <=

  <=(x, y)
  (x,y)

  Less-than-or-equals comparison operator. Falls back to (x < y) | (x == y).
[...]

julia> versioninfo()
Julia Version 1.9.0-DEV.1120
Commit 95cbb9f6184 (2022-08-12 00:44 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.5 (ORCJIT, tigerlake)
  Threads: 1 on 8 virtual cores
Environment:
  LD_LIBRARY_PATH = :/usr/lib/x86_64-linux-gnu/gtk-3.0/modules
  JULIA_EDITOR = subl

As per the docstring, <= should fall back to using < and ==.

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions