Skip to content
← Back

src/syntax/trees/expressions/member.ghul

1
namespace Syntax.Trees.Expressions is
2
3
use Source;
4
5
class MEMBER(
6
location: LOCATION,
7
left: Expression,
8
identifier: Identifiers.Identifier,
9
completion_target: LOCATION
10
): Expression is
11
right_location: LOCATION => identifier.right_location;
12
13
is_member: bool => true;
14
could_be_type_expression: bool => left.could_be_type_expression;
15
16
// Set by the parser when the access was written `a?.b`: the
17
// load short-circuits on a null receiver and yields a result
18
// widened to the optional shape of the member type. Plain
19
// `a.b` leaves this false.
20
is_coalesce: bool public;
21
22
// Pushed in by the parent context. Lets a bare unit-variant
23
// member access (`let n: Option[int] = Option.NONE`) specialise
24
// the union from the declared type; other member shapes ignore
25
// the field.
26
27
try_copy_as_identifer() -> Identifiers.Identifier? =>
28
let maybe_left_as_identifier = left.try_copy_as_identifer() in
29
if maybe_left_as_identifier? then
30
Trees.Identifiers.QUALIFIED(
31
location,
32
maybe_left_as_identifier,
33
identifier.name,
34
completion_target,
35
right_location
36
)
37
else
38
return null;
39
fi;
40
41
super(location);
42
43
set_expected_type(expected_type: Semantic.Types.Type?, error_message: string?) is
44
compile_expressions_state.set_expected_type(expected_type, error_message);
45
si
46
47
accept(visitor: Visitor) is
48
visitor.visit(self);
49
si
50
51
walk(visitor: Visitor) is
52
if !visitor.pre(self) then
53
left.walk(visitor);
54
identifier.walk(visitor);
55
fi
56
accept(visitor);
57
si
58
59
replace_child(old: Expression, replacement: Expression) is
60
if left == old then
61
left = replacement;
62
fi
63
si
64
si
65
si