Skip to content

multiple errors on same range: report real errors first (4.14) #2143

Description

@edwintorok

The following snippet shows 2 errors on OCaml 4.14:

let oneof_array xs st = Array.get xs (Random.State.int st (Array.length xs))

let array_of_set (type t) (module S: Set.S with type t = t) set =
  set |> S.to_seq |> Array.of_seq |> oneof_array
Entering directory '/home/edwint/git/o/x'
File "bin/main.ml", line 4, characters 2-48:
4 |   set |> S.to_seq |> Array.of_seq |> oneof_array
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error (warning 5 [ignored-partial-application]): this function application is partial,
maybe some arguments are missing.
File "bin/main.ml", line 4, characters 2-48:
4 |   set |> S.to_seq |> Array.of_seq |> oneof_array
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type Random.State.t -> S.elt
       but an expression was expected of type 'a
       The type constructor S.elt would escape its scope
Leaving directory '/home/edwint/git/o/x'

However through the LSP server I can only see the 1st one, which happens to be a warning-as-an-error.
It'd be more useful to show the 2nd one, which is the real error.

This doesn't reproduce on OCaml 5.5, because the compiler can infer the missing annotations.
On OCaml 5.4 the message looks different (the 1st warning is folded into as a hint):

Entering directory '/home/edwint/git/o/x'
File "bin/main.ml", line 4, characters 2-48:
4 |   set |> S.to_seq |> Array.of_seq |> oneof_array
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type Random.State.t -> S.elt
       but an expression was expected of type 'a
       The type constructor S.elt would escape its scope
Hint: This function application is partial, maybe some arguments are missing.

(this can be fixed on 4.14 and 5.4 by adding a type constraint for elt too)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions