Skip to content
← Back

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

1
namespace Syntax.Process is
2
// A generic alias named without type arguments, where a type is
3
// wanted as a value - most often to construct it. An alias that
4
// renames a generic class, passing its own type parameters through in
5
// order, stands for that class, so its type arguments are inferred as
6
// they would be for the class. Any other generic alias has no single
7
// class to infer them for.
8
class BARE_GENERIC_ALIAS is
9
// The class the alias renames, as its open type, or null when the
10
// alias does anything more than rename.
11
class_type(alias: Semantic.Symbols.TYPE_ALIAS) -> Semantic.Types.Type? static is
12
let target = cast Semantic.Types.GENERIC?(alias.target_type)
13
14
if !target? then
15
return null
16
fi
17
18
let arguments = target.arguments
19
let parameters = alias.type_parameters
20
21
if arguments.count != parameters.count then
22
return null
23
fi
24
25
for i in 0..arguments.count do
26
let argument = cast Semantic.Types.NAMED?(arguments[i])
27
28
if !argument? \/ argument.symbol != cast Semantic.Symbols.Symbol(parameters[i]) then
29
return null
30
fi
31
od
32
33
if let generic = cast Semantic.Symbols.GENERIC?(target.symbol) then
34
return generic.symbol.type
35
fi
36
37
return null
38
si
39
si
40
si