Allow literal scope output structures

This commit is contained in:
Louis Gesbert 2024-01-19 15:41:48 +01:00
parent 6972de06ad
commit 1c2c41b2ff
2 changed files with 44 additions and 1 deletions

View File

@ -498,7 +498,9 @@ let rec translate_expr
let ctxt = Name_resolution.module_ctx ctxt path in
let s_uid =
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)
"This identifier should refer to a struct name"

View 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 }
```