Skip to content

Commit

Permalink
Show expected and received type on directive error
Browse files Browse the repository at this point in the history
  • Loading branch information
wikku committed Jul 19, 2021
1 parent fb1af2e commit 3c97584
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -32,6 +32,9 @@ Working version
(`#use "missing_file";;`) use stderr and exit with an error.
(Florian Angeletti, review by Gabriel Scherer)

- #10524: Directive argument type error now shows expected and received type.
(Wiktor Kuchta, review by Gabriel Scherer)

### Manual and documentation:

- #7812, #10475: reworded the description of the behaviors of
Expand Down
18 changes: 16 additions & 2 deletions toplevel/topcommon.ml
Expand Up @@ -338,7 +338,21 @@ let try_run_directive ppf dir_name pdir_arg =
| Directive_ident f, Some {pdira_desc = Pdir_ident lid} -> f lid; true
| Directive_bool f, Some {pdira_desc = Pdir_bool b} -> f b; true
| _ ->
fprintf ppf "Wrong type of argument for directive `%s'.@."
dir_name;
let dir_type = match d with
| Directive_none _ -> "no argument"
| Directive_string _ -> "a `string' literal"
| Directive_int _ -> "an `int' literal"
| Directive_ident _ -> "an identifier"
| Directive_bool _ -> "a `bool' literal"
in
let arg_type = match pdir_arg with
| None -> "no argument"
| Some {pdira_desc = Pdir_string _} -> "a `string' literal"
| Some {pdira_desc = Pdir_int _} -> "an `int' literal"
| Some {pdira_desc = Pdir_ident _} -> "an identifier"
| Some {pdira_desc = Pdir_bool _} -> "a `bool' literal"
in
fprintf ppf "Directive `%s' expects %s, got %s.@."
dir_name dir_type arg_type;
false
end

0 comments on commit 3c97584

Please sign in to comment.