mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Disambiguate constructors and fields across modules
This commit is contained in:
parent
8194abaf93
commit
2c6e6bf0b5
@ -998,4 +998,26 @@ let form_context (prgm : Surface.Ast.program) : context =
|
||||
(process_law_structure process_use_item)
|
||||
ctxt prgm.program_items
|
||||
in
|
||||
ctxt
|
||||
let rec gather_all_constrs ctxt =
|
||||
(* Gather struct fields and enum constrs from modules: this helps with disambiguation *)
|
||||
let modules, constructor_idmap, field_idmap =
|
||||
ModuleName.Map.fold
|
||||
(fun m ctx (mmap, constrs, fields) ->
|
||||
let ctx = gather_all_constrs ctx in
|
||||
ModuleName.Map.add m ctx mmap,
|
||||
Ident.Map.union
|
||||
(fun _ enu1 enu2 ->
|
||||
Some (EnumName.Map.union (fun _ _ -> assert false)
|
||||
enu1 enu2))
|
||||
constrs ctx.constructor_idmap,
|
||||
Ident.Map.union
|
||||
(fun _ str1 str2 ->
|
||||
Some (StructName.Map.union (fun _ _ -> assert false)
|
||||
str1 str2))
|
||||
fields ctx.field_idmap
|
||||
)
|
||||
ctxt.modules (ModuleName.Map.empty, ctxt.constructor_idmap, ctxt.field_idmap)
|
||||
in
|
||||
{ ctxt with modules; constructor_idmap; field_idmap }
|
||||
in
|
||||
gather_all_constrs ctxt
|
||||
|
@ -12,13 +12,13 @@ declaration scope T2:
|
||||
output o4 content decimal
|
||||
|
||||
scope T2:
|
||||
definition o1 equals Mod_def.Enum1.No
|
||||
definition o1 equals No
|
||||
definition o2 equals t1.e1
|
||||
definition o3 equals t1.sr
|
||||
definition o4 equals Mod_def.half of 10
|
||||
assertion (Mod_def.Str1 { -- fld1: No -- fld2: 1 }).Mod_def.Str1.fld1 = No
|
||||
assertion (Mod_def.Str1 { -- fld1: No -- fld2: 1 }).fld1 = No
|
||||
assertion o1 = Mod_def.Enum1.No
|
||||
assertion o2 = Mod_def.Enum1.Maybe
|
||||
assertion o2 = Maybe
|
||||
assertion o3 = $1000
|
||||
assertion o4 = 5.0
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user