text
stringlengths
0
601k
let force_delayed_checks ( ) = let snap = Btype . snapshot ( ) in let w_old = Warnings . backup ( ) in List . iter ( fun ( f , w ) -> Warnings . restore w ; f ( ) ) ( List . rev ! delayed_checks ) ; Warnings . restore w_old ; reset_delayed_checks ( ) ; Btype . backtrack snap
let rec final_subexpression exp = match exp . exp_desc with Texp_let ( _ , _ , e ) | Texp_sequence ( _ , e ) | Texp_try ( e , _ ) | Texp_ifthenelse ( _ , e , _ ) | Texp_match ( _ , { c_rhs = e } :: _ , _ ) | Texp_letmodule ( _ , _ , _ , _ , e ) | Texp_letexception ( _ , e ) | Texp_open ( _ , e ) -> final_subexpression ...
let rec is_nonexpansive exp = match exp . exp_desc with | Texp_ident _ | Texp_constant _ | Texp_unreachable | Texp_function _ | Texp_array [ ] -> true | Texp_let ( _rec_flag , pat_exp_list , body ) -> List . for_all ( fun vb -> is_nonexpansive vb . vb_expr ) pat_exp_list && is_nonexpansive body | Texp_apply ( e , ( _ ,...
let maybe_expansive e = not ( is_nonexpansive e )
let check_recursive_bindings env valbinds = let ids = let_bound_idents valbinds in List . iter ( fun { vb_expr } -> if not ( Rec_check . is_valid_recursive_expression ids vb_expr ) then raise ( Error ( vb_expr . exp_loc , env , Illegal_letrec_expr ) ) ) valbinds
let check_recursive_class_bindings env ids exprs = List . iter ( fun expr -> if not ( Rec_check . is_valid_class_expr ids expr ) then raise ( Error ( expr . cl_loc , env , Illegal_class_expr ) ) ) exprs
let rec approx_type env sty = match sty . ptyp_desc with Ptyp_arrow ( p , _ , sty ) -> let ty1 = if is_optional p then type_option ( newvar ( ) ) else newvar ( ) in newty ( Tarrow ( p , ty1 , approx_type env sty , Cok ) ) | Ptyp_tuple args -> newty ( Ttuple ( List . map ( approx_type env ) args ) ) | Ptyp_constr ( lid ...
let rec type_approx env sexp = match sexp . pexp_desc with Pexp_let ( _ , _ , e ) -> type_approx env e | Pexp_fun ( p , _ , _ , e ) -> let ty = if is_optional p then type_option ( newvar ( ) ) else newvar ( ) in newty ( Tarrow ( p , ty , type_approx env e , Cok ) ) | Pexp_function ( { pc_rhs = e } :: _ ) -> newty ( Tar...
let rec list_labels_aux env visited ls ty_fun = let ty = expand_head env ty_fun in if List . memq ty visited then List . rev ls , false else match ty . desc with Tarrow ( l , _ , ty_res , _ ) -> list_labels_aux env ( ty :: visited ) ( l :: ls ) ty_res | _ -> List . rev ls , is_Tvar ty
let list_labels env ty = wrap_trace_gadt_instances env ( list_labels_aux env [ ] [ ] ) ty
let check_univars env expans kind exp ty_expected vars = if expans && maybe_expansive exp then lower_contravariant env exp . exp_type ; let vars = List . map ( expand_head env ) vars in let vars = List . map ( expand_head env ) vars in let vars ' = List . filter ( fun t -> let t = repr t in generalize t ; match t . des...
let check_partial_application statement exp = let rec f delay = let ty = ( expand_head exp . exp_env exp . exp_type ) . desc in let check_statement ( ) = match ty with | Tconstr ( p , _ , _ ) when Path . same p Predef . path_unit -> ( ) | _ -> if statement then let rec loop { exp_loc ; exp_desc ; exp_extra ; _ } = matc...
let generalizable level ty = let rec check ty = let ty = repr ty in if ty . level < lowest_level then ( ) else if ty . level <= level then raise Exit else ( mark_type_node ty ; iter_type_expr check ty ) in try check ty ; unmark_type ty ; true with Exit -> unmark_type ty ; false
let self_coercion = ref ( [ ] : ( Path . t * Location . t list ref ) list )
let create_package_type loc env ( p , l ) = let s = ! Typetexp . transl_modtype_longident loc env p in let fields = List . map ( fun ( name , ct ) -> name , Typetexp . transl_simple_type env false ct ) l in let ty = newty ( Tpackage ( s , List . map fst l , List . map ( fun ( _ , cty ) -> cty . ctyp_type ) fields ) ) i...
let contains_variant_either ty = let rec loop ty = let ty = repr ty in if ty . level >= lowest_level then begin mark_type_node ty ; match ty . desc with Tvariant row -> let row = row_repr row in if not ( is_fixed row ) then List . iter ( fun ( _ , f ) -> match row_field_repr f with Reither _ -> raise Exit | _ -> ( ) ) ...
let shallow_iter_ppat f p = match p . ppat_desc with | Ppat_any | Ppat_var _ | Ppat_constant _ | Ppat_interval _ | Ppat_extension _ | Ppat_type _ | Ppat_unpack _ -> ( ) | Ppat_array pats -> List . iter f pats | Ppat_or ( p1 , p2 ) -> f p1 ; f p2 | Ppat_variant ( _ , arg ) | Ppat_construct ( _ , arg ) -> Option . iter f...
let exists_ppat f p = let exception Found in let rec loop p = if f p then raise Found else ( ) ; shallow_iter_ppat loop p in match loop p with | exception Found -> true | ( ) -> false
let contains_polymorphic_variant p = exists_ppat ( function | { ppat_desc = ( Ppat_variant _ | Ppat_type _ ) } -> true | _ -> false ) p
let contains_gadt cp = exists_pattern ( function | { pat_desc = Tpat_construct ( _ , cd , _ ) } when cd . cstr_generalized -> true | _ -> false ) cp
let may_contain_gadts p = exists_ppat ( function | { ppat_desc = Ppat_construct ( _ , _ ) } -> true | _ -> false ) p
let check_absent_variant env = iter_pattern ( function { pat_desc = Tpat_variant ( s , arg , row ) } as pat -> let row = row_repr ! row in if List . exists ( fun ( s ' , fi ) -> s = s ' && row_field_repr fi <> Rabsent ) row . row_fields || not ( is_fixed row ) && not ( static_row row ) then ( ) else let ty_arg = match ...
let proper_exp_loc exp = let rec aux = function | [ ] -> exp . exp_loc | ( ( Texp_constraint _ | Texp_coerce _ ) , loc , _ ) :: _ -> loc | _ :: rest -> aux rest in aux exp . exp_extra
let rec name_pattern default = function [ ] -> Ident . create_local default | p :: rem -> match p . pat_desc with Tpat_var ( id , _ ) -> id | Tpat_alias ( _ , id , _ ) -> id | _ -> name_pattern default rem
let name_cases default lst = name_pattern default ( List . map ( fun c -> c . c_lhs ) lst )
let unify_exp env exp expected_ty = let loc = proper_exp_loc exp in try unify_exp_types loc env exp . exp_type expected_ty with Error ( loc , env , Expr_type_clash ( trace , tfc , None ) ) -> raise ( Error ( loc , env , Expr_type_clash ( trace , tfc , Some exp . exp_desc ) ) )
let rec type_exp ? recarg env sexp = type_expect ? recarg env sexp ( mk_expected ( newvar ( ) ) ) let previous_saved_types = Cmt_format . get_saved_types ( ) in let exp = Builtin_attributes . warning_scope sexp . pexp_attributes ( fun ( ) -> type_expect_ ? in_function ? recarg env sexp ty_expected_explained ) in Cmt_fo...
let type_binding env rec_flag spat_sexp_list scope = Typetexp . reset_type_variables ( ) ; let ( pat_exp_list , new_env , _unpacks ) = type_let ~ check ( : fun s -> Warnings . Unused_value_declaration s ) ~ check_strict ( : fun s -> Warnings . Unused_value_declaration s ) At_toplevel env rec_flag spat_sexp_list scope f...
let type_let existential_ctx env rec_flag spat_sexp_list scope = let ( pat_exp_list , new_env , _unpacks ) = type_let existential_ctx env rec_flag spat_sexp_list scope false in ( pat_exp_list , new_env )
let type_expression env sexp = Typetexp . reset_type_variables ( ) ; begin_def ( ) ; let exp = type_exp env sexp in end_def ( ) ; if maybe_expansive exp then lower_contravariant env exp . exp_type ; generalize exp . exp_type ; match sexp . pexp_desc with Pexp_ident lid -> let loc = sexp . pexp_loc in let ( _path , desc...
let spellcheck ppf unbound_name valid_names = Misc . did_you_mean ppf ( fun ( ) -> Misc . spellcheck valid_names unbound_name )
let spellcheck_idents ppf unbound valid_idents = spellcheck ppf ( Ident . name unbound ) ( List . map Ident . name valid_idents )
let type_clash_of_trace trace = Ctype . Unification_trace . ( explain trace ( fun ~ prev : _ -> function | Diff diff -> Some diff | _ -> None ) )
let report_literal_type_constraint expected_type const = let const_str = match const with | Const_int n -> Some ( Int . to_string n ) | Const_int32 n -> Some ( Int32 . to_string n ) | Const_int64 n -> Some ( Int64 . to_string n ) | Const_nativeint n -> Some ( Nativeint . to_string n ) | _ -> None in let suffix = if Pat...
let report_literal_type_constraint const = function | Some Unification_trace . { expected = { t = { desc = Tconstr ( typ , [ ] , _ ) } } } -> report_literal_type_constraint typ const | Some _ | None -> [ ]
let report_expr_type_clash_hints exp diff = match exp with | Some ( Texp_constant const ) -> report_literal_type_constraint const diff | _ -> [ ]
let report_pattern_type_clash_hints pat diff = match pat with | Some ( Tpat_constant const ) -> report_literal_type_constraint const diff | _ -> [ ]
let report_type_expected_explanation expl ppf = let because expl_str = fprintf ppf " @ because it is in % s " expl_str in match expl with | If_conditional -> because " the condition of an if - statement " | If_no_else_branch -> because " the result of a conditional with no else branch " | While_loop_conditional -> beca...
let report_type_expected_explanation_opt expl ppf = match expl with | None -> ( ) | Some expl -> report_type_expected_explanation expl ppf
let report_unification_error ~ loc ? sub env trace ? type_expected_explanation txt1 txt2 = Location . error_of_printer ~ loc ? sub ( fun ppf ( ) -> Printtyp . report_unification_error ppf env trace ? type_expected_explanation txt1 txt2 ) ( )
let report_error ~ loc env = function | Constructor_arity_mismatch ( lid , expected , provided ) -> Location . errorf ~ loc " [ @ The constructor % a @ expects % i argument ( s ) , @ \ but is applied here to % i argument ( s ) ] " @ longident lid expected provided | Label_mismatch ( lid , trace ) -> report_unification_...
let report_error ~ loc env err = wrap_printing_env ~ error : true env ( fun ( ) -> report_error ~ loc env err )
let ( ) = Location . register_error_of_exn ( function | Error ( loc , env , err ) -> Some ( report_error ~ loc env err ) | Error_forward err -> Some err | _ -> None )
let ( ) = Persistent_env . add_delayed_check_forward := add_delayed_check ; Env . add_delayed_check_forward := add_delayed_check ; ( )
let type_expect ? in_function env e ty = type_expect ? in_function env e ty
let type_exp env e = type_exp env e
let type_argument env e t1 t2 = type_argument env e t1 t2
let x = function 0 . . . 1 . -> ( ) ^^^^^^^^ } ] |
let f = function None None -> 0 [ %% expect { | ^^^^^^^^^ but is applied here to 1 argument ( s ) } ] |
let x = None None [ %% expect { | ^^^^^^^^^ but is applied here to 1 argument ( s ) } ] |
type t = A of { x : int }
let f = function ( A ( x : _ ) ) -> 0 [ %% expect { |
type t = A of { x : int ; } ^^^^^ } ] |
let f = function Some ( exception Not_found ) -> 0 [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^ } ] |
let f = function [ % ext ] -> 0 [ %% expect { | ^^^ } ] |
let rec f x = ( ( ) , ( ) : _ -> _ -> _ ) [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^ but an expression was expected of type ' c -> ' d -> ' e } ] |
let rec g x = ( ( ( ) , ( ) ) : _ -> _ :> _ ) [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ but an expression was expected of type ' c -> ' d } ] |
let f x = match x with exception Not_found -> ( ) ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } ] |
type r = { x : int }
let r = { x = 1 ; x = 1 } [ %% expect { |
type r = { x : int ; } ^^^^^^^^^^^^^ } ] |
let ( ) = { x = 1 } . x <- 2 [ %% expect { | ^^^^^^^^^^^^^^^^ } ] |
let ( ) = for Some i = 3 to 4 do ( ) done ; [ %% expect { | ^^^^^^ } ] | inherit v as super method m = 0 method x : int = super # m end ; ; [ %% expect { | ^^^^^ } ] |
let x = new v [ %% expect { | ^^^^^ } ] |
let x = object val x = 1 method m = x <- 0 end [ %% expect { | ^^^^ } ] |
let x = object ( self ) method m = self <- 0 end [ %% expect { | ^^^^^^^^ } ] | [ %% expect { | ^^^^^^^^^^^^^^ } ] |
let f x = { < y = x } > [ %% expect { | ^^^^^^^^^^^ } ] | [ %% expect { | ^^^^^^^^^ } ] |
module type empty = sig end
let f ( x : int ) = ( )
let x = f ( module struct end )
module type empty = sig end ^^^^^^^^^^^^^^^^^^^ } ] |
let x = [ % extension_constructor A ]
type t = A ^ } ] |
let x = [ % extension_constructor ] ^^^^^^^^^^^^^^^^^^^^^^^^ } ] |
let x = format_of_string " % z " ^^^^ } ] |
let f ~ x = x + 2
let y = f ~ y : 1 ^ } ] |
let g f = f ~ x : 0 ~ y : 0 ; f ~ y : 0 ~ x : 0 ^ in an order different from other calls . This is only allowed when the real type is known . } ] |
type t = A of { x : int }
let x = A 1
type t = A of { x : int ; } ^^^ } ] |
type ' a t = A of ' a
let rec A x = A ( A ( ) )
type ' a t = A of ' a ^^^ } ] |
let quadratic ( x , x ) = x * x ^ } ] |
type t = A of int | B of float | C
let f ( A x | B x ) = 0
type t = A of int | B of float | C ^^^^^^^^^ int but on the right - hand side it has type float } ] |
let f ( A x | C ) = 0 ^^^^^^^ } ] |
let f ( A x | B y ) = 0 ^^^^^^^^^ } ] |
let f = function # t -> ( )
type t = [ ] ^ } ] |
let f { x ; x = y ; x = z } = x ^^^^^^^^^^^ } ] |
let x = ( [ ` B ] [ ` :> A ] ) ^^^^ [ > ` B ] list but is here used with type [ < ` A ] } ] |
let o = object method m = instance <- 0 end [ %% expect { | ^^^^^^^^^^^^^ } ] |
let x = function | ` azdwbie -> ( ) | ` c7diagq -> ( ) [ %% expect { | ^^^^^^^^ Change one of them . } ] |
let x = ` azdwbie = ` c7diagq [ %% expect { | ^^^^^^^^ Change one of them . } ] |
type ' a x = | X : [ ` > azdwbie ] x | Y : [ ` > c7diagq ] x
let x = function | X -> ( ) | Y -> ( ) [ %% expect { |
type ' a x = X : [ > ` azdwbie ] x | Y : [ > ` c7diagq ] x ^ Change one of them . } ] |