Type declarations should also be typed
This is necessary so that the static expressions appearing in those types are correctly typed.
This commit is contained in:
parent
6b86b86e9d
commit
401aaeeb89
|
@ -164,6 +164,8 @@ let add_const f v =
|
||||||
(** Same as add_value but without checking for redefinition *)
|
(** Same as add_value but without checking for redefinition *)
|
||||||
let replace_value f v =
|
let replace_value f v =
|
||||||
g_env.values <- QualEnv.add f v g_env.values
|
g_env.values <- QualEnv.add f v g_env.values
|
||||||
|
let replace_type f v =
|
||||||
|
g_env.types <- QualEnv.add f v g_env.types
|
||||||
|
|
||||||
(** { 3 Find functions look in the global environement, nothing more } *)
|
(** { 3 Find functions look in the global environement, nothing more } *)
|
||||||
|
|
||||||
|
|
|
@ -1096,10 +1096,28 @@ let typing_const_dec cd =
|
||||||
let se = expect_static_exp QualEnv.empty ty cd.c_value in
|
let se = expect_static_exp QualEnv.empty ty cd.c_value in
|
||||||
{ cd with c_value = se; c_type = ty }
|
{ cd with c_value = se; c_type = ty }
|
||||||
|
|
||||||
|
let typing_typedec td =
|
||||||
|
let tydesc = match td.t_desc with
|
||||||
|
| Type_abs -> Type_abs
|
||||||
|
| Type_enum(tag_list) -> Type_enum tag_list
|
||||||
|
| Type_alias t ->
|
||||||
|
let t = check_type QualEnv.empty t in
|
||||||
|
replace_type td.t_name (Talias t);
|
||||||
|
Type_alias t
|
||||||
|
| Type_struct(field_ty_list) ->
|
||||||
|
let typing_field { f_name = f; f_type = ty } =
|
||||||
|
{ f_name = f; f_type = check_type QualEnv.empty ty }
|
||||||
|
in
|
||||||
|
let field_ty_list = List.map typing_field field_ty_list in
|
||||||
|
replace_type td.t_name (Tstruct field_ty_list);
|
||||||
|
Type_struct field_ty_list
|
||||||
|
in
|
||||||
|
{ td with t_desc = tydesc }
|
||||||
|
|
||||||
let program p =
|
let program p =
|
||||||
let program_desc pd = match pd with
|
let program_desc pd = match pd with
|
||||||
| Pnode n -> Pnode (node n)
|
| Pnode n -> Pnode (node n)
|
||||||
| Pconst c -> Pconst (typing_const_dec c)
|
| Pconst c -> Pconst (typing_const_dec c)
|
||||||
| _ -> pd
|
| Ptype t -> Ptype (typing_typedec t)
|
||||||
in
|
in
|
||||||
{ p with p_desc = List.map program_desc p.p_desc }
|
{ p with p_desc = List.map program_desc p.p_desc }
|
||||||
|
|
Loading…
Reference in a new issue