From 2602e444277cdf215b34c10ab4f872dbce8348d0 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Tue, 3 Oct 2023 10:50:46 +0200 Subject: Variable shallowing made me lost somes errors. Should be better now --- syntax/type_of.ml | 25 +++++++++++++++++++------ 1 file 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 -- cgit v1.2.3