aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChimrod <>2023-10-03 10:50:46 +0200
committerChimrod <>2023-10-03 18:39:11 +0200
commit2602e444277cdf215b34c10ab4f872dbce8348d0 (patch)
tree949c68e63f801ccf1da7d12b3a3fa64cd7b7b73e
parente8b746742fdeb44ea976d867001c7b0815df1543 (diff)
Variable shallowing made me lost somes errors. Should be better now
-rw-r--r--syntax/type_of.ml25
1 files changed, 19 insertions, 6 deletions
diff --git a/syntax/type_of.ml b/syntax/type_of.ml
index 6faea62..d578700 100644
--- a/syntax/type_of.ml
+++ b/syntax/type_of.ml
@@ -113,7 +113,7 @@ module Expression = struct
type t = {
result : Helper.t;
- report : Report.t list;
+ report : Report.t list; (* See the comment below *)
pos : pos;
empty : bool;
}
@@ -121,7 +121,13 @@ module Expression = struct
type repr = Report.t list -> t
(** The type repr is a function accepting the report as a first argement.
When the report is given, it will be reported into the tree and collected
- in bottom-top *)
+ in bottom-top.
+
+ It’s easy to forget that the report is updated when the type is created.
+ The function takes the report in argument, and store the report in the
+ returned type. Maybe should I make a tupple instead in order to make it
+ explicit ?
+ *)
type variable = { pos : pos; name : string; index : repr option }
@@ -159,8 +165,9 @@ module Expression = struct
parameters. *)
let types, report =
List.fold_left params ~init:([], _acc) ~f:(fun (types, report) param ->
- let arg = arg_of_repr (param report) in
- (arg :: types, report))
+ let t = param report in
+ let arg = arg_of_repr t in
+ (arg :: types, t.report))
in
let types = List.rev types
and default = { result = Any; report; pos; empty = false } in
@@ -244,6 +251,7 @@ module Expression = struct
let uoperator : pos -> T.uoperator -> repr -> repr =
fun pos operator t1 report ->
let t = t1 report in
+ let report = t.report in
match operator with
| Add -> t
| Neg | No ->
@@ -254,7 +262,9 @@ module Expression = struct
let boperator : pos -> T.boperator -> repr -> repr -> repr =
fun pos operator t1 t2 report ->
- let t1 = t1 report and t2 = t2 report in
+ let t1 = t1 report in
+ let t2 = t2 t1.report in
+ let report = t2.report in
let types = [ arg_of_repr t1; arg_of_repr t2 ] in
match operator with
| T.Plus ->
@@ -301,7 +311,10 @@ module Instruction = struct
(** Call for an instruction like [GT] or [*CLR] *)
let call : pos -> string -> expression list -> repr =
- fun _pos _ _ report -> report
+ fun _pos _ expressions report ->
+ List.fold_left expressions ~init:report ~f:(fun report expression ->
+ let result = expression report in
+ result.Expression.report)
let location : pos -> string -> repr = fun _pos _ report -> report