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:

  1. #[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).
  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's type_check_match additionally rejects a match on an opaque SCRUTINEE type, which catches a wildcard pattern.
  3. A native's result type must be inhabited. The constructed type (the IO/RawIO payload) may not be an inductive with zero constructors. Void is the deliberate empty type and is rejected when returned; a type variable or a function type is undecidable here and is left alone (Eq.rec returns P b e).

All three are ERRORS in every [affine] mode (logical consistency is not a migration warning), on the CLI, buffer and LSP paths.

defopaque_ctor_names#
pub def opaque_ctor_names (s : Scope) : HashMap String Bool

The witness constructor's names (bare and Ind.ctor), for every #[opaque] inductive in scope.

defcheck_module_opaque_diags#
pub def check_module_opaque_diags (path : Option String) (scope : Scope) (decl_list : List Decl) : List String
defnative_return_errors#
pub def native_return_errors (scope : Scope) (d : Def) : List TypeError

A 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.