Appearance
| 1 | namespace Semantic is | |
| 2 | use Types.Type | |
| 3 | ||
| 4 | // Settles the inferred return type of a function literal whose slot | |
| 5 | // asked for `U?` over an unconstrained U. The slot's return is | |
| 6 | // `MAYBE[U]`, a distinct CLR type from the `string?` or bare `int` | |
| 7 | // the body produces, and the literal's delegate has to carry the | |
| 8 | // slot's shape for the call to bind: the body's type is pinned as | |
| 9 | // `MAYBE[T]` over what it produced, and the return boundary makes | |
| 10 | // the coercion into it. | |
| 11 | class MAYBE_RETURN_PIN is | |
| 12 | of( | |
| 13 | function: Symbols.Function, | |
| 14 | value_type: Type, | |
| 15 | innate_symbol_lookup: Lookups.InnateSymbolLookup | |
| 16 | ) -> Type static is | |
| 17 | if | |
| 18 | !function.wrap_inferred_return_as_maybe \/ | |
| 19 | !value_type.is_settled \/ | |
| 20 | value_type.is_maybe \/ | |
| 21 | value_type.is_null | |
| 22 | then | |
| 23 | return value_type | |
| 24 | fi | |
| 25 | ||
| 26 | let inner = value_type.optional_inner_type ?? value_type | |
| 27 | ||
| 28 | if let maybe: Types.GENERIC = innate_symbol_lookup.get_maybe_type(inner) then | |
| 29 | // A `MAYBE` the body wrote out by name is a plain | |
| 30 | // construction over the same symbol: already the carrier. | |
| 31 | if maybe.is_construction_of_same_symbol_as(value_type) then | |
| 32 | return value_type | |
| 33 | fi | |
| 34 | ||
| 35 | return maybe | |
| 36 | fi | |
| 37 | ||
| 38 | return value_type | |
| 39 | si | |
| 40 | si | |
| 41 | si |