Skip to content

Every Js.Date is equal to every other Js.Date #3455

Closed

Description

@mlms13

Using == in Reason (or = in OCaml), all Js.Date.t values are equal:

let a = Js.Date.fromFloat 1553816680458.0
let b = Js.Date.fromFloat 0.0
let _ = Js.log (a = b) (* true *)

I tried looking through the caml_equal function, but I got a bit lost. :)

Activity

  1. bobzhang commented on Mar 29, 2019

    @bobzhang
    Member

    hi, = is unsafe unless you know what you do. We have a warning flag (102) to warn unsafe usage of =, we accept patches to make the default behavior less surprising

  2. yawaramin commented on Mar 29, 2019

    @yawaramin
    Contributor
  3. cristianoc commented on Mar 29, 2019

    @cristianoc
    Collaborator

    For reference: this is the point where dates would be handled:
    https://github.com/BuckleScript/bucklescript/blob/fafc9fd350a29275bb523c17564aed27879efc96/jscomp/runtime/caml_obj.ml#L328

    After O.isArray one would check O.isDate which presumably would use instanceof Date.
    Date equality does not work with == in JS so one would need to use <= and >=.

  4. bobzhang commented on Apr 3, 2019

    @bobzhang
    Member

    It makes sense to make the default less surprising, we are going to have this fixed in next release

  5. yawaramin commented on Apr 3, 2019

    @yawaramin
    Contributor

    One option to kind of cover this and other surprises with polymorphic compares is to by default enable 102 as a warning. Actually, now that I think about it, I want to propose some stricter warnings and errors by default anyway. I'll open a separate issue.

  6. bobzhang commented on Apr 4, 2019

    @bobzhang
    Member

    @yawaramin it used to be default, but people don't like it ..

  7. yawaramin commented on Apr 5, 2019

    @yawaramin
    Contributor

    @bobzhang that makes sense actually–I had it turned on for a bit and realized it's not great because the warning doesn't go away–it keeps appearing even if the file isn't touched afterwards 😅

  8. added a commit that references this issue on Apr 7, 2019
    133b110
  9. added a commit that references this issue on Apr 7, 2019
    ab732ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions