Skip to content
← Back

src/syntax/process/compile-expressions/if_missing_else_decider.ghul

1
namespace Syntax.Process is
2
use Semantic.Types.Type
3
4
// The outcome for a value-consuming if written without an
5
// unconditional else.
6
enum IfMissingElseDecision is
7
YIELD_ABSENCE,
8
REQUIRE_ELSE,
9
si
10
11
// Decides whether a value-consuming if without an unconditional
12
// else can yield an optional of its branches' type - present when
13
// an arm runs, absent when control falls through - or must keep
14
// demanding an else. Absence needs somewhere to go: an expected
15
// type that cannot hold absence rejects it, and so does a body
16
// whose every arm diverges, since nothing completes to be absent
17
// from.
18
class IF_MISSING_ELSE_DECIDER is
19
init() is
20
super.init()
21
si
22
23
decide(expected_type: Type?, seen_any_values: bool) -> IfMissingElseDecision is
24
if
25
!seen_any_values \/
26
(expected_type? /\ !expected_type.is_optional)
27
then
28
return IfMissingElseDecision.REQUIRE_ELSE
29
fi
30
31
return IfMissingElseDecision.YIELD_ABSENCE
32
si
33
si
34
si