Skip to content

Commit

Permalink
support type inference for module val definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
wies committed Dec 6, 2024
1 parent 4c42b7d commit 7302c4c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1975,9 +1975,15 @@ module ProcessModule = struct
Rewriter.Option.map var.var_init ~f:(fun expr ->
process_expr expr var_decl.var_type)
in

let (var : Stmt.var_def) = { var_decl; var_init } in

let var_type =
var_init |> Option.map ~f:Expr.to_type |> Option.value ~default:var_decl.var_type
in
let _ = if Type.equal var_type Type.any then
Error.error var_decl.var_loc
@@ Printf.sprintf "Type annotation missing for variable %s"
(Ident.to_string var_decl.var_name)
in
let (var : Stmt.var_def) = { var_decl = { var_decl with var_type }; var_init } in
Module.(VarDef var)

let check_implements_symbol interface_ident (symbol : Symbol.t)
Expand Down

0 comments on commit 7302c4c

Please sign in to comment.