Skip to content
← Back

src/semantic/types/generic_argument.ghul

1
namespace Semantic.Types is
2
use System.Text.StringBuilder
3
4
use Source
5
6
class GenericArgument: NAMED abstract is
7
is_wild: bool => true
8
is_function_generic_argument: bool => false
9
is_classy_generic_argument: bool => false
10
11
init(symbol: Symbols.Symbol) is
12
super.init(symbol)
13
si
14
15
get_type_arguments_into(results: Collections.LIST[GenericArgument]) is
16
results.add(self)
17
si
18
19
freeze() -> Type? is
20
let frozen = symbol.freeze()
21
22
if !frozen? then
23
return null
24
fi
25
26
return frozen.type
27
si
28
29
specialize(type_map: Collections.Map[Symbols.Symbol,Type]) -> Type is
30
let result: Type mut
31
32
if type_map.try_get_value(symbol, result ref) then
33
// A `T?` keeps its nullability across substitution.
34
if is_optional then
35
return result.as_optional()
36
else
37
return result
38
fi
39
fi
40
41
return self
42
si
43
44
bind_type_variables(other: Type, results: GENERIC_ARGUMENT_BIND_RESULTS) -> bool =>
45
results.bind(self, other)
46
47
to_string() -> string =>
48
if is_optional then
49
"{symbol.name}?"
50
else
51
symbol.name
52
fi
53
si
54
55
// TODO can get is classy vs is function from underlying symbol,
56
// delete these sub-classes and go back to having just
57
// one class representing a generic argument type
58
class CLASSY_GENERIC_ARGUMENT: GenericArgument is
59
is_classy_generic_argument: bool => true
60
61
init(symbol: Symbols.Symbol) is
62
super.init(symbol)
63
si
64
si
65
66
class FUNCTION_GENERIC_ARGUMENT: GenericArgument is
67
is_function_generic_argument: bool => true
68
69
init(symbol: Symbols.Symbol) is
70
super.init(symbol)
71
si
72
si
73
si