lang::typecheck::opaque_rules
lang/src/typecheck/opaque_rules.mo
Opaque native types, and the rule that natives may not construct empty types.
A type with no constructors is the empty type (False). A #[native]
or #[extern "c"] declaration returning one would assert an inhabitant
of False, so:
#[opaque]types declare exactly one NULLARY witness constructor. The witness is the inhabitation proof (At/Cell,I64…F64,Ptr). The type stays abstract because the witness is unreferenceable (rule 2).- The witness cannot be constructed or matched. A source reference
to an
#[opaque]constructor is an error, in expression position (Term.con/Term.var) and in a match pattern (MatchCase.name).infer.mo'stype_check_matchadditionally rejects a match on an opaque SCRUTINEE type, which catches a wildcard pattern. - A native's result type must be inhabited. The constructed type
(the
IO/RawIOpayload) may not be an inductive with zero constructors.Voidis the deliberate empty type and is rejected when returned; a type variable or a function type is undecidable here and is left alone (Eq.recreturnsP b e).
All three are ERRORS in every [affine] mode (logical consistency is not
a migration warning), on the CLI, buffer and LSP paths.
pub def opaque_ctor_names (s : Scope) : HashMap String BoolThe witness constructor's names (bare and Ind.ctor), for every
#[opaque] inductive in scope.
pub def check_module_opaque_diags (path : Option String) (scope : Scope) (decl_list : List Decl) : List Stringpub def native_return_errors (scope : Scope) (d : Def) : List TypeErrorA body-less native/extern returning an empty inductive. Split into small
defs: a let ... in match cannot sit directly in an if's else arm in
this parser.