Show conflicting date rounding mode declarations when they happen

This commit is contained in:
Raphaël Monat 2023-03-16 18:51:01 +01:00
parent 8981b21edb
commit d5cd5b206a
7 changed files with 24 additions and 13 deletions

View File

@ -919,11 +919,11 @@ let translate_scope_decl
let date_rounding : date_rounding =
match
List.find_opt
(function Desugared.Ast.DateRounding _ -> true)
(function Desugared.Ast.DateRounding _, _ -> true)
sigma.scope_options
with
| Some (Desugared.Ast.DateRounding Desugared.Ast.Increasing) -> RoundUp
| Some (DateRounding Decreasing) -> RoundDown
| Some (Desugared.Ast.DateRounding Desugared.Ast.Increasing, _) -> RoundUp
| Some (DateRounding Decreasing, _) -> RoundDown
| None -> AbortOnRound
in
let ctx = { ctx with date_rounding } in

View File

@ -197,7 +197,7 @@ type scope = {
scope_uid : ScopeName.t;
scope_defs : scope_def ScopeDefMap.t;
scope_assertions : assertion list;
scope_options : catala_option list;
scope_options : catala_option Marked.pos list;
scope_meta_assertions : meta_assertion list;
}

View File

@ -120,7 +120,7 @@ type scope = {
scope_uid : ScopeName.t;
scope_defs : scope_def ScopeDefMap.t;
scope_assertions : assertion list;
scope_options : catala_option list;
scope_options : catala_option Marked.pos list;
scope_meta_assertions : meta_assertion list;
}

View File

@ -1153,16 +1153,21 @@ let process_scope_use_item
let new_scope =
match
List.find_opt
(fun scope_opt ->
(fun (scope_opt, _) ->
scope_opt = Ast.DateRounding Ast.Increasing
|| scope_opt = Ast.DateRounding Ast.Decreasing)
scope.scope_options
with
| Some _ ->
Errors.raise_spanned_error (Marked.get_mark item)
"A date rounding mode has already been specified"
| Some (_, old_pos) ->
Errors.raise_multispanned_error
[None, old_pos; None, Marked.get_mark item]
"You cannot set multiple date rounding modes"
| None ->
{ scope with scope_options = Ast.DateRounding r :: scope.scope_options }
{
scope with
scope_options =
Marked.same_mark_as (Ast.DateRounding r) item :: scope.scope_options;
}
in
{
prgm with

View File

@ -49,7 +49,7 @@ type 'm scope_decl = {
scope_sig : (typ * Desugared.Ast.io) ScopeVar.Map.t;
scope_decl_rules : 'm rule list;
scope_mark : 'm mark;
scope_options : Desugared.Ast.catala_option list;
scope_options : Desugared.Ast.catala_option Marked.pos list;
}
type 'm program = {

View File

@ -41,7 +41,7 @@ type 'm scope_decl = {
scope_sig : (typ * Desugared.Ast.io) ScopeVar.Map.t;
scope_decl_rules : 'm rule list;
scope_mark : 'm mark;
scope_options : Desugared.Ast.catala_option list;
scope_options : Desugared.Ast.catala_option Marked.pos list;
}
type 'm program = {

View File

@ -25,7 +25,13 @@ scope Test:
```catala-test-inline
$ catala Interpret -s Test
[ERROR] A date rounding mode has already been specified
[ERROR] You cannot set multiple date rounding modes
┌─⯈ tests/test_date/bad/rounding_option_conflict.catala_en:10.13-23:
└──┐
10 │ date round decreasing
│ ‾‾‾‾‾‾‾‾‾‾
┌─⯈ tests/test_date/bad/rounding_option_conflict.catala_en:12.13-23:
└──┐