Appearance
| 1 | namespace Semantic is | |
| 2 | use Collections; | |
| 3 | use Semantic.Types.Type; | |
| 4 | use Semantic.Lookups.InnateSymbolLookup; | |
| 5 | ||
| 6 | use Ghul.Pipes; | |
| 7 | ||
| 8 | // Builds a tuple type whose element types are the per-position least | |
| 9 | // upper bounds of a set of tuple-literal value types — used when | |
| 10 | // inferring the type of a list literal or a set of if-branch values | |
| 11 | // whose elements are themselves tuple literals. | |
| 12 | class TUPLE_ELEMENT_LUB(_innate_symbol_lookup: InnateSymbolLookup) is | |
| 13 | ||
| 14 | combine(tuple_types: Iterable[Type], element_names: LIST[string?]?) -> Type is | |
| 15 | let lubs = LIST[LEAST_UPPER_BOUND_MAP](); | |
| 16 | ||
| 17 | for tuple_type in tuple_types do | |
| 18 | for (index, element_type) in tuple_type.arguments |> index() do | |
| 19 | if index >= lubs.count then | |
| 20 | lubs.add(LEAST_UPPER_BOUND_MAP()); | |
| 21 | fi | |
| 22 | ||
| 23 | lubs[index].add(element_type); | |
| 24 | od | |
| 25 | od | |
| 26 | ||
| 27 | return | |
| 28 | _innate_symbol_lookup.get_tuple_type( | |
| 29 | lubs |> | |
| 30 | map(l => l.get_result() ?? _innate_symbol_lookup.get_object_type()) |> | |
| 31 | collect(), | |
| 32 | element_names | |
| 33 | ); | |
| 34 | si | |
| 35 | si | |
| 36 | si |