Skip to content

Conversation

chenglou
Copy link
Member

@chenglou chenglou commented Feb 7, 2021

Fixes #4939

The previous message was also wrong (?). The types were flipped; if the
function expected 1 and got 2, it'd say "this function has arity2 but
was expected arity1".

@chenglou
Copy link
Member Author

chenglou commented Feb 7, 2021

Before:
Screen Shot 2021-02-07 at 8 12 04 AM

After:
image

(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),_,_)}) ::
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),b,_),_,_)}) :: _
) when a <> b ->
let extractArity s =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this too weird? Should I just pattern match all the way from arity0 to arity22?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pattern match all the way from arity0 to arity22 that would be an explosion of pattern match

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is still sound ? since we own the Js.Fn module which only contains type definitions for arity*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can you extract this into a toplevel function parameterized by a and b so that it can be reused later (for other syntaxes as well)?
  • this looks like the same pattern match in loc 185-188, so you should merge it there
  • I also think that a <> b seems to be not necessary since when a = b, there should be no such error message

This function expected 2 arguments, but got 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rephrase of such error message looks great

@chenglou chenglou force-pushed the arity-se branch 3 times, most recently from 458fb64 to 9b92bb7 Compare February 10, 2021 11:27
Fixes rescript-lang#4939

The previous message was also wrong (?). The types were flipped; if the function expected 1 and got 2, it'd say "this function has arity2 but was expected arity1".
(* assumption: the module Js.Fn only contains types from arity0 to arity22 *)
String.sub s 5 ((String.length s) - 5)
else
raise (Invalid_argument "Unrecognized arity type name.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicks: this should be assert false

@bobzhang bobzhang merged commit def3a2a into rescript-lang:master Feb 18, 2021
@chenglou chenglou deleted the arity-se branch February 18, 2021 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message for arity mismatch errors
2 participants