Error struct for type mismatch errors in Predicator evaluation.
This error occurs when an operation receives values of incorrect types, such as trying to perform arithmetic on strings or logical operations on integers.
Fields
message- Human-readable error descriptionexpected- The type that was expected (e.g.,:integer,:boolean)got- The actual type(s) received (single type or tuple for binary operations)values- The actual value(s) that caused the error (optional, for debugging)operation- The operation that failed (e.g.,:add,:logical_and)position-{line, column}of the source token that produced the failing instruction, when a position table was available (optional)span- the source text the failing instruction's AST node covers, when the program was compiled with spans (optional).positionnames the token to blame;spanis what to underline.
Examples
%Predicator.Errors.TypeMismatchError{
message: "Arithmetic add requires integers, got "hello" (string) and 5 (integer)",
expected: :integer,
got: {:string, :integer},
values: {"hello", 5},
operation: :add
}
%Predicator.Errors.TypeMismatchError{
message: "Unary minus requires an integer, got "text" (string)",
expected: :integer,
got: :string,
values: "text",
operation: :unary_minus
}
Summary
Functions
Creates a type mismatch error for binary operations.
Creates a type mismatch error for unary operations.
Creates a type mismatch error for a unary operation that accepts more than one
type, spelling the accepted set out in the message while expected stays the
single normative atom a consumer matches on.
Types
@type t() :: %Predicator.Errors.TypeMismatchError{ expected: atom(), got: atom() | {atom(), atom()}, message: binary(), operation: atom(), position: Predicator.Types.position() | nil, span: Predicator.Types.span() | nil, values: term() }
Functions
Creates a type mismatch error for binary operations.
Creates a type mismatch error for unary operations.
Creates a type mismatch error for a unary operation that accepts more than one
type, spelling the accepted set out in the message while expected stays the
single normative atom a consumer matches on.
store accepts a string or an integer segment but reports expected: :string,
the mirror of bracket_access's key rule (docs/isa.md section 5); a message
built from the atom alone would tell a user something false about what the
opcode accepts.
Examples
iex> error = Predicator.Errors.TypeMismatchError.unary(:store, :string, :boolean, true, "a string or an integer")
iex> {error.expected, error.message}
{:string, "Assignment requires a string or an integer, got true (boolean)"}