Skip to content
← Back

src/semantic/types/array.ghul

1
namespace Semantic.Types is
2
3
use Source.LOCATION
4
5
class ARRAY: GENERIC is
6
short_description: string => get_short_description(self)
7
8
get_short_description(reference: GENERIC) -> string static is
9
let element =
10
if reference.arguments[0].is_function then
11
"({reference.arguments[0]})"
12
else
13
"{reference.arguments[0]}"
14
fi
15
16
return if reference.is_optional then "{element}[]?" else "{element}[]" fi
17
si
18
19
init(
20
location: LOCATION,
21
symbol: Symbols.Classy,
22
arguments: Collections.List[Type]
23
) is
24
super.init(Symbols.ARRAY(location, symbol, arguments[0]))
25
si
26
27
// Arrays are declared covariant; effective_argument_variance
28
// downgrades this to invariant for a value-typed element, same
29
// as it does for any other type's declared variance.
30
get_argument_type_variance(index: int) -> TypeVariance => TypeVariance.COVARIANT
31
32
create(
33
location: LOCATION,
34
symbol: Symbols.Classy,
35
arguments: Collections.List[Type]
36
) -> GENERIC =>
37
Types.ARRAY(location, symbol, arguments)
38
39
to_string() -> string => get_short_description(self)
40
si
41
si