Improve some messages on structure disambiguation

This commit is contained in:
Louis Gesbert 2022-12-07 12:28:24 +01:00
parent 5cbab517db
commit 5bcc0a65eb
5 changed files with 4558 additions and 4542 deletions

View File

@ -275,7 +275,7 @@ let rec translate_expr
try Name_resolution.get_struct ctxt c
with Not_found ->
Errors.raise_spanned_error (Marked.get_mark c)
"Struct %s has not been defined before" (Marked.unmark c))
"Structure %s was not declared" (Marked.unmark c))
c
in
Expr.edstructaccess e (Marked.unmark x) str emark)

View File

@ -225,20 +225,20 @@ and ('a, 't) naked_gexpr =
args : ('a, 't) gexpr ScopeVar.Map.t;
}
-> (([< desugared | scopelang ] as 'a), 't) naked_gexpr
(* [desugared] has ambiguous struct fields *)
| EDStructAccess : {
name_opt : StructName.t option;
e : ('a, 't) gexpr;
field : IdentName.t;
}
-> ((desugared as 'a), 't) naked_gexpr
(* Resolved struct/enums, after [desugared] *)
(** [desugared] has ambiguous struct fields *)
| EStructAccess : {
name : StructName.t;
e : ('a, 't) gexpr;
field : StructField.t;
}
-> (([< scopelang | dcalc | lcalc ] as 'a), 't) naked_gexpr
(** Resolved struct/enums, after [desugared] *)
(* Lambda-like *)
| EAssert : ('a, 't) gexpr -> (([< dcalc | lcalc ] as 'a), 't) naked_gexpr
(* Default terms *)

View File

@ -464,13 +464,23 @@ and typecheck_expr_top_down :
A.StructName.format_t name
in
let field =
try
A.StructName.Map.find name
(A.IdentName.Map.find field ctx.ctx_struct_fields)
let candidate_structs =
try A.IdentName.Map.find field ctx.ctx_struct_fields
with Not_found ->
Errors.raise_spanned_error context_mark.pos
"Field %s does not belong to structure %a (no structure defines \
it)"
field A.StructName.format_t name
in
try A.StructName.Map.find name candidate_structs
with Not_found ->
Errors.raise_spanned_error context_mark.pos
"Field %s does not belong to structure %a" field
"Field %s does not belong to structure %a, but to %a" field
A.StructName.format_t name
(Format.pp_print_list
~pp_sep:(fun ppf () -> Format.fprintf ppf "@ or@ ")
A.StructName.format_t)
(List.map fst (A.StructName.Map.bindings candidate_structs))
in
A.StructField.Map.find field str
in

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@ scope A:
```catala-test-inline
$ catala Interpret -s A
[ERROR] Field g does not belong to structure Foo
[ERROR] Field g does not belong to structure Foo, but to Bar
┌─⯈ tests/test_struct/bad/wrong_qualified_field.catala_en:17.22-29:
└──┐