From 4492c9b3ea164f844174142e5a65cfd6c9b9af35 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 5 Dec 2023 11:47:52 +0100 Subject: [PATCH] better errors --- flap/src/hopix/hopixTypechecker.ml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/flap/src/hopix/hopixTypechecker.ml b/flap/src/hopix/hopixTypechecker.ml index d4cd9d9..debc113 100644 --- a/flap/src/hopix/hopixTypechecker.ml +++ b/flap/src/hopix/hopixTypechecker.ml @@ -126,7 +126,7 @@ and synth_apply let given = synth_expression tenv x in check_equal_types x.position ~expected ~given; droit - | _ -> failwith "Error: apply" + | _ -> HopixTypes.type_error f.position "Can't apply" and synth_record : HopixTypes.typing_environment @@ -167,7 +167,7 @@ and synth_sequence = fun tenv elist -> match elist with - | [] -> failwith "Error: sequence" + | [] -> HopixTypes.type_error Position.dummy "Invalid sequence" | [ x ] -> synth_expression tenv x | x :: l -> let given = synth_expression tenv x in @@ -261,12 +261,9 @@ and check_expression : HopixTypes.typing_environment -> HopixAST.expression Position.located -> HopixTypes.aty -> unit = - fun env (Position.{ value = e; position = pos } as exp) expected -> - match e with - | Fun df -> failwith "Students! This is your job! (check_expression | Fun)" - | _ -> - let given = synth_expression env exp in - check_equal_types pos ~expected ~given + fun env (Position.{ position = pos } as exp) expected -> + let given = synth_expression env exp in + check_equal_types pos ~expected ~given and check_value_definition : HopixTypes.typing_environment -> HopixAST.value_definition @@ -275,7 +272,7 @@ and check_value_definition fun env -> function | SimpleValue (id, ty, ex) -> (match ty with - | None -> failwith "A type is missing." + | None -> HopixTypes.type_error ex.position "Type is missing" | Some ty' -> let tys, tenv = Position.located_pos (check_type_scheme env) ty' in check_expression tenv ex (HopixTypes.instantiate_type_scheme tys []);