mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-09 22:16:10 +03:00
Allow literal scope output structures
This commit is contained in:
parent
6972de06ad
commit
1c2c41b2ff
@ -498,7 +498,9 @@ let rec translate_expr
|
|||||||
let ctxt = Name_resolution.module_ctx ctxt path in
|
let ctxt = Name_resolution.module_ctx ctxt path in
|
||||||
let s_uid =
|
let s_uid =
|
||||||
match Ident.Map.find_opt (Mark.remove s_name) ctxt.local.typedefs with
|
match Ident.Map.find_opt (Mark.remove s_name) ctxt.local.typedefs with
|
||||||
| Some (Name_resolution.TStruct s_uid) -> s_uid
|
| Some (Name_resolution.TStruct s_uid)
|
||||||
|
| Some (Name_resolution.TScope (_, { out_struct_name = s_uid; _ })) ->
|
||||||
|
s_uid
|
||||||
| _ ->
|
| _ ->
|
||||||
Message.raise_spanned_error (Mark.get s_name)
|
Message.raise_spanned_error (Mark.get s_name)
|
||||||
"This identifier should refer to a struct name"
|
"This identifier should refer to a struct name"
|
||||||
|
41
tests/test_scope/good/scope_struct.catala_en
Normal file
41
tests/test_scope/good/scope_struct.catala_en
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
```catala
|
||||||
|
declaration scope SubFoo:
|
||||||
|
input x content integer
|
||||||
|
input y content integer
|
||||||
|
output z1 content integer
|
||||||
|
output z2 content integer
|
||||||
|
|
||||||
|
declaration scope Foo:
|
||||||
|
output example content SubFoo
|
||||||
|
|
||||||
|
scope SubFoo:
|
||||||
|
definition z1 equals x + y
|
||||||
|
definition z2 equals x - y
|
||||||
|
|
||||||
|
scope Foo:
|
||||||
|
definition example equals
|
||||||
|
let results_foo equals output of SubFoo with { -- x: 1 -- y: 2 } in
|
||||||
|
SubFoo {
|
||||||
|
-- z1: results_foo.z1 + 1
|
||||||
|
-- z2: results_foo.z2 + 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```catala-test-inline
|
||||||
|
$ catala Typecheck --check-invariants
|
||||||
|
[RESULT] Invariant typing_defaults checked. result: [65/65]
|
||||||
|
[RESULT] Invariant match_inversion checked. result: [0/0]
|
||||||
|
[RESULT] Invariant app_inversion checked. result: [4/4]
|
||||||
|
[RESULT] Invariant no_return_a_function checked. result: [3/3]
|
||||||
|
[RESULT] Invariant no_partial_evaluation checked. result: [4/4]
|
||||||
|
[RESULT] Invariant default_no_arrow checked. result: [6/6]
|
||||||
|
[RESULT] Typechecking successful!
|
||||||
|
```
|
||||||
|
|
||||||
|
```catala-test-inline
|
||||||
|
$ catala interpret -s Foo
|
||||||
|
[RESULT] Computation successful! Results:
|
||||||
|
[RESULT] example = SubFoo { -- z1: 4 -- z2: 0 }
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user