Module Melange_compiler_libs.Errortrace

type position =
  1. | First
  2. | Second
;
let swap_position: position => position;
let print_pos: Stdlib.Format.formatter => position => unit;
type expanded_type = {
  1. ty: Types.type_expr,
  2. expanded: Types.type_expr,
};
let trivial_expansion: Types.type_expr => expanded_type;

trivial_expansion ty creates an expanded_type whose expansion is also ty. Usually, you want Ctype.expand_type instead, since the expansion carries useful information; however, in certain circumstances, the error is about the expansion of the type, meaning that actually performing the expansion produces more confusing or inaccurate output.

type diff('a) = {
  1. got: 'a,
  2. expected: 'a,
};
let map_diff: ('a => 'b) => diff('a) => diff('b);

map_diff f {expected;got} is {expected=f expected; got=f got}

type escape_kind('a) =
  1. | Constructor(Path.t)
  2. | Univ(Types.type_expr)
  3. | Self
  4. | Module_type(Path.t)
  5. | Equation('a)
  6. | Constraint
;

Scope escape related errors

type escape('a) = {
  1. kind: escape_kind('a),
  2. context: option(Types.type_expr),
};
let map_escape: ('a => 'b) => escape('a) => escape('b);
let explain: list('a) => (prev:option('a) => 'a => option('b)) => option('b);
type unification = pri
  1. | Unification
;

Type indices

type comparison = pri
  1. | Comparison
;
type fixed_row_case =
  1. | Cannot_be_closed
  2. | Cannot_add_tags(list(string))
;
type variant('variety) =
  1. | Incompatible_types_for(string) : variant(_)
  2. | No_tags(position, list((Asttypes.label, Types.row_field))) : variant(_)
  3. | No_intersection : variant(unification)
  4. | Fixed_row(position, fixed_row_case, Types.fixed_explanation) : variant( unification)
  5. | Presence_not_guaranteed_for(position, string) : variant(comparison)
  6. | Openness(position) : variant(comparison)
;
type obj('variety) =
  1. | Missing_field(position, string) : obj(_)
  2. | Abstract_row(position) : obj(_)
  3. | Self_cannot_be_closed : obj(unification)
;
type elt('a, 'variety) =
  1. | Diff(diff('a)) : elt('a, _)
  2. | Variant(variant('variety)) : elt('a, 'variety)
  3. | Obj(obj('variety)) : elt('a, 'variety)
  4. | Escape(escape('a)) : elt('a, _)
  5. | Incompatible_fields: {
    1. name: string,
    2. diff: diff(Types.type_expr),
    } : elt('a, _)
  6. | Rec_occur(Types.type_expr, Types.type_expr) : elt('a, _)
;
type t('a, 'variety) = list(elt('a, 'variety));
type trace('variety) = t(Types.type_expr, 'variety);
type error('variety) = t(expanded_type, 'variety);
let map: ('a => 'b) => t('a, 'variety) => t('b, 'variety);
let incompatible_fields: name:string => got:Types.type_expr => expected:Types.type_expr => elt(Types.type_expr, _);
let swap_trace: t('a, 'variety) => t('a, 'variety);

The traces ('variety t) are the core error types. However, we bundle them up into three "top-level" error types, which are used elsewhere: unification_error, equality_error, and moregen_error. In the case of equality_error, this has to bundle in extra information; in general, it distinguishes the three types of errors and allows us to distinguish traces that are being built (or processed) from those that are complete and have become the final error. These error types have the invariants that their traces are nonempty; we ensure that through three smart constructors with matching names.

type unification_error = pri {
  1. trace: error(unification),
};
type equality_error = pri {
  1. trace: error(comparison),
  2. subst: list((Types.type_expr, Types.type_expr)),
};
type moregen_error = pri {
  1. trace: error(comparison),
};
let unification_error: trace:error(unification) => unification_error;
let equality_error: trace:error(comparison) => subst:list((Types.type_expr, Types.type_expr)) => equality_error;
let moregen_error: trace:error(comparison) => moregen_error;
type comparison_error =
  1. | Equality_error(equality_error)
  2. | Moregen_error(moregen_error)
;

Wraps up the two different kinds of comparison errors in one type

let swap_unification_error: unification_error => unification_error;

Lift swap_trace to unification_error

module Subtype: { ... };