Appearance
| 1 | namespace Syntax.Trees is | |
| 2 | // Trait carried by AST nodes that hold a type expected_type propagated | |
| 3 | // down from the surrounding context — i.e. "the type my parent / | |
| 4 | // declaring environment expects this expression to produce". | |
| 5 | // | |
| 6 | // Storage and most overrides live on the concrete Expression | |
| 7 | // subclasses; making this an explicit trait gives later | |
| 8 | // bidirectional-inference passes a uniform handle on | |
| 9 | // "anything-that-carries-a-expected_type" and lets new expected_type | |
| 10 | // producers (left-side-of-assignment, list-literal element types) | |
| 11 | // be added as small, targeted edits rather than spread across the | |
| 12 | // class hierarchy. | |
| 13 | // | |
| 14 | // The stored expected_type is the upper-bound type the value must | |
| 15 | // conform to (LHS of an assignment, formal arg type of a call, | |
| 16 | // return type of the enclosing function). | |
| 17 | trait TypeConstrained is | |
| 18 | expected_type: Semantic.Types.Type?; | |
| 19 | ||
| 20 | set_expected_type(expected_type: Semantic.Types.Type, expected_type_error_message: string); | |
| 21 | upgrade_expected_type(new_expected_type: Semantic.Types.Type, new_error_message: string); | |
| 22 | clear_expected_type(); | |
| 23 | si | |
| 24 | si |