diff --git a/flap/src/hopix/hopixTypechecker.ml b/flap/src/hopix/hopixTypechecker.ml index d4e2d71..74b98c8 100644 --- a/flap/src/hopix/hopixTypechecker.ml +++ b/flap/src/hopix/hopixTypechecker.ml @@ -30,32 +30,36 @@ let check_equal_types pos ~expected ~given = let rec check_pattern_linearity : identifier list -> pattern Position.located -> identifier list = - fun vars Position.{ value; position } -> match value with + fun vars Position.{ value; position = _ } -> + match value with | PWildcard -> vars | PLiteral _ -> vars | PVariable v -> linearity_variable v vars - | PTypeAnnotation(p,_) -> check_pattern_linearity vars p + | PTypeAnnotation (p, _) -> + (* Pour les deux matchs qui suivent, on fait la même chose : + On regarde récursivement chaque pattern de chaque liste, et on effectue le + check de linéarité pour chaque pattern. - (* Pour les deux matchs qui suivent, on fait la même chose : On regarde récursivement chaque pattern - de chaque liste, et on effectue le check de linéarité pour chaque pattern. Seulement, pour PRecord qui est - un (label located * pattern located), on doit séparer en deux matchs distinct pour "ouvrir" la paire de PRecord *) - | PTaggedValue(_,_,plist) | PTuple(plist) | POr (plist) | PAnd (plist) - -> linearity_pattern_list plist vars - | PRecord(plist,_) - -> linearity_precord_list plist vars + Seulement, pour PRecord qui est un (label located * pattern located), + on doit séparer en deux matchs distinct pour "ouvrir" la paire de PRecord *) + check_pattern_linearity vars p + | PTaggedValue (_, _, plist) | PTuple plist | POr plist | PAnd plist -> + linearity_pattern_list plist vars + | PRecord (plist, _) -> linearity_precord_list plist vars -and linearity_variable v vars = - if List.mem v.value vars then - failwith "Il y a déjà une occurence de la variable dans le pattern" - else v.value::vars +and linearity_variable v vars = + if List.mem v.value vars + then + HopixTypes.type_error + v.position + "Il y a déjà une occurence de la variable dans le pattern" + else v.value :: vars and linearity_pattern_list plist vars = List.fold_left (fun vars pat -> check_pattern_linearity vars pat) vars plist and linearity_precord_list plist vars = - List.fold_left (fun vars (label,pat) -> check_pattern_linearity vars pat) vars plist - - + List.fold_left (fun vars (_, pat) -> check_pattern_linearity vars pat) vars plist ;; (** Type-checking code *)