Skip to content
← Back

src/syntax/process/diverging_value_position.ghul

1
namespace Syntax.Process is
2
use Semantic.Types.Type;
3
4
// Rules for a statement used where a value is wanted whose only exits
5
// diverge — `throw`, or an `if`/`case`/`val` whose every arm diverges.
6
// Such a statement produces no value, but the continuation after it is
7
// unreachable and needs none, so a value-requiring context must not
8
// treat the absent value as an error.
9
class DIVERGING_VALUE_POSITION is
10
// True when a value-wanting position should report its statement
11
// having produced no value: it wants one, none was produced, and
12
// control actually reaches the continuation. A diverging statement
13
// makes that continuation unreachable, so the value is legitimately
14
// absent and nothing should be reported.
15
is_missing_value_reportable(want_value: bool, has_value: bool, is_unreachable: bool) -> bool static =>
16
want_value /\ !has_value /\ !is_unreachable;
17
18
// True when a diverging expression body (`=> throw E`, or an
19
// `=> if/case` whose arms all diverge) should adopt void as its
20
// return type. A return type the user declared — any settled type —
21
// is kept; only an unsettled one (absent, a wildcard, or still being
22
// inferred) is replaced, since the body yields nothing to infer from.
23
settles_inferred_return_to_void(return_type: Type?) -> bool static =>
24
!return_type? \/ return_type.is_wild \/ return_type.is_inferred;
25
si
26
si