mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-09 22:16:10 +03:00
Merge pull request #239 from CatalaLang/fix_237
Nice error messages for empty structs and enums
This commit is contained in:
commit
e28587c3ed
@ -377,6 +377,12 @@ let process_struct_decl (ctxt : context) (sdecl : Ast.struct_decl) : context =
|
|||||||
let s_uid =
|
let s_uid =
|
||||||
Desugared.Ast.IdentMap.find (fst sdecl.struct_decl_name) ctxt.struct_idmap
|
Desugared.Ast.IdentMap.find (fst sdecl.struct_decl_name) ctxt.struct_idmap
|
||||||
in
|
in
|
||||||
|
if List.length sdecl.struct_decl_fields = 0 then
|
||||||
|
Errors.raise_spanned_error
|
||||||
|
(Pos.get_position sdecl.struct_decl_name)
|
||||||
|
"The struct %s does not have any fields; give it some for Catala to be \
|
||||||
|
able to accept it."
|
||||||
|
(Pos.unmark sdecl.struct_decl_name);
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun ctxt (fdecl, _) ->
|
(fun ctxt (fdecl, _) ->
|
||||||
let f_uid =
|
let f_uid =
|
||||||
@ -420,6 +426,12 @@ let process_enum_decl (ctxt : context) (edecl : Ast.enum_decl) : context =
|
|||||||
let e_uid =
|
let e_uid =
|
||||||
Desugared.Ast.IdentMap.find (fst edecl.enum_decl_name) ctxt.enum_idmap
|
Desugared.Ast.IdentMap.find (fst edecl.enum_decl_name) ctxt.enum_idmap
|
||||||
in
|
in
|
||||||
|
if List.length edecl.enum_decl_cases = 0 then
|
||||||
|
Errors.raise_spanned_error
|
||||||
|
(Pos.get_position edecl.enum_decl_name)
|
||||||
|
"The enum %s does not have any cases; give it some for Catala to be able \
|
||||||
|
to accept it."
|
||||||
|
(Pos.unmark edecl.enum_decl_name);
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun ctxt (cdecl, cdecl_pos) ->
|
(fun ctxt (cdecl, cdecl_pos) ->
|
||||||
let c_uid =
|
let c_uid =
|
||||||
|
@ -2,8 +2,7 @@ source_file: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR CONTE
|
|||||||
##
|
##
|
||||||
## Ends in an error in state: 358.
|
## Ends in an error in state: 358.
|
||||||
##
|
##
|
||||||
## nonempty_list(enum_decl_line) -> enum_decl_line . [ SCOPE END_CODE DECLARATION ]
|
## list(enum_decl_line) -> enum_decl_line . list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
||||||
## nonempty_list(enum_decl_line) -> enum_decl_line . nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
|
||||||
##
|
##
|
||||||
## The known suffix of the stack is as follows:
|
## The known suffix of the stack is as follows:
|
||||||
## enum_decl_line
|
## enum_decl_line
|
||||||
@ -51,7 +50,7 @@ source_file: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON YEAR
|
|||||||
##
|
##
|
||||||
## Ends in an error in state: 350.
|
## Ends in an error in state: 350.
|
||||||
##
|
##
|
||||||
## code_item -> DECLARATION ENUM constructor COLON . nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
## code_item -> DECLARATION ENUM constructor COLON . list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
||||||
##
|
##
|
||||||
## The known suffix of the stack is as follows:
|
## The known suffix of the stack is as follows:
|
||||||
## DECLARATION ENUM constructor COLON
|
## DECLARATION ENUM constructor COLON
|
||||||
@ -63,7 +62,7 @@ source_file: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR YEAR
|
|||||||
##
|
##
|
||||||
## Ends in an error in state: 349.
|
## Ends in an error in state: 349.
|
||||||
##
|
##
|
||||||
## code_item -> DECLARATION ENUM constructor . COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
## code_item -> DECLARATION ENUM constructor . COLON list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
||||||
##
|
##
|
||||||
## The known suffix of the stack is as follows:
|
## The known suffix of the stack is as follows:
|
||||||
## DECLARATION ENUM constructor
|
## DECLARATION ENUM constructor
|
||||||
@ -75,7 +74,7 @@ source_file: BEGIN_CODE DECLARATION ENUM YEAR
|
|||||||
##
|
##
|
||||||
## Ends in an error in state: 348.
|
## Ends in an error in state: 348.
|
||||||
##
|
##
|
||||||
## code_item -> DECLARATION ENUM . constructor COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
## code_item -> DECLARATION ENUM . constructor COLON list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
||||||
##
|
##
|
||||||
## The known suffix of the stack is as follows:
|
## The known suffix of the stack is as follows:
|
||||||
## DECLARATION ENUM
|
## DECLARATION ENUM
|
||||||
@ -264,7 +263,7 @@ source_file: BEGIN_CODE DECLARATION YEAR
|
|||||||
##
|
##
|
||||||
## code_item -> DECLARATION . STRUCT constructor COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ]
|
## code_item -> DECLARATION . STRUCT constructor COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ]
|
||||||
## code_item -> DECLARATION . SCOPE constructor COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ]
|
## code_item -> DECLARATION . SCOPE constructor COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ]
|
||||||
## code_item -> DECLARATION . ENUM constructor COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
## code_item -> DECLARATION . ENUM constructor COLON list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
|
||||||
##
|
##
|
||||||
## The known suffix of the stack is as follows:
|
## The known suffix of the stack is as follows:
|
||||||
## DECLARATION
|
## DECLARATION
|
||||||
|
@ -617,7 +617,7 @@ code_item:
|
|||||||
scope_decl_context = context;
|
scope_decl_context = context;
|
||||||
}, Pos.from_lpos $sloc)
|
}, Pos.from_lpos $sloc)
|
||||||
}
|
}
|
||||||
| DECLARATION ENUM c = constructor COLON cases = nonempty_list(enum_decl_line) {
|
| DECLARATION ENUM c = constructor COLON cases = list(enum_decl_line) {
|
||||||
(EnumDecl {
|
(EnumDecl {
|
||||||
enum_decl_name = c;
|
enum_decl_name = c;
|
||||||
enum_decl_cases = cases;
|
enum_decl_cases = cases;
|
||||||
|
8
tests/test_enum/bad/empty.catala_en
Normal file
8
tests/test_enum/bad/empty.catala_en
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
## Test
|
||||||
|
|
||||||
|
```catala
|
||||||
|
declaration enumeration Foo:
|
||||||
|
|
||||||
|
declaration scope Bar:
|
||||||
|
internal foo content Foo
|
||||||
|
```
|
7
tests/test_enum/bad/output/empty.catala_en.Typecheck
Normal file
7
tests/test_enum/bad/output/empty.catala_en.Typecheck
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[ERROR] The enum Foo does not have any cases; give it some for Catala to be able to accept it.
|
||||||
|
|
||||||
|
--> tests/test_enum/bad/empty.catala_en
|
||||||
|
|
|
||||||
|
4 | declaration enumeration Foo:
|
||||||
|
| ^^^
|
||||||
|
+ Test
|
8
tests/test_struct/bad/empty_struct.catala_en
Normal file
8
tests/test_struct/bad/empty_struct.catala_en
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
## Test
|
||||||
|
|
||||||
|
```catala
|
||||||
|
declaration structure Foo:
|
||||||
|
|
||||||
|
declaration scope Bar:
|
||||||
|
internal foo content Foo
|
||||||
|
```
|
@ -0,0 +1,7 @@
|
|||||||
|
[ERROR] The struct Foo does not have any fields; give it some for Catala to be able to accept it.
|
||||||
|
|
||||||
|
--> tests/test_struct/bad/empty_struct.catala_en
|
||||||
|
|
|
||||||
|
4 | declaration structure Foo:
|
||||||
|
| ^^^
|
||||||
|
+ Test
|
Loading…
Reference in New Issue
Block a user