Appearance
| 1 | namespace Semantic.Types is | |
| 2 | // Whether a type holds the type of a bare `null` somewhere inside it, as | |
| 3 | // a tuple built with a `null` element does when nothing says what that | |
| 4 | // element holds. Such a type has no runtime representation, so it cannot | |
| 5 | // be the type of a variable or a type argument. | |
| 6 | class NULL_ELEMENT is | |
| 7 | within(type: Type) -> bool static is | |
| 8 | if let generic: GENERIC = type then | |
| 9 | for argument in generic.arguments do | |
| 10 | if isa NULL(argument) \/ within(argument) then | |
| 11 | return true | |
| 12 | fi | |
| 13 | od | |
| 14 | fi | |
| 15 | ||
| 16 | return false | |
| 17 | si | |
| 18 | ||
| 19 | // Whether an actual argument of type `actual` can be passed to a formal | |
| 20 | // of type `formal`, as far as a bare `null` inside it is concerned. A | |
| 21 | // tuple formal gives each element its own type; any other formal leaves | |
| 22 | // the `null` element with none, and the tuple with no runtime | |
| 23 | // representation to pass. | |
| 24 | fits(formal: Type, actual: Type) -> bool static is | |
| 25 | if !within(actual) then | |
| 26 | return true | |
| 27 | fi | |
| 28 | ||
| 29 | let unwrapped = formal.optional_inner_type ?? formal | |
| 30 | ||
| 31 | // A type parameter is bound element by element where the actual | |
| 32 | // is a tuple, and binding refuses a `null` element itself. | |
| 33 | if unwrapped.is_type_variable \/ unwrapped.is_function_generic_argument \/ unwrapped.is_classy_generic_argument then | |
| 34 | return true | |
| 35 | fi | |
| 36 | ||
| 37 | return unwrapped.is_value_tuple \/ isa TUPLE(unwrapped) | |
| 38 | si | |
| 39 | si | |
| 40 | si |