Skip to content
← Back

src/semantic/lambda_return_constraint.ghul

1
namespace Semantic is
2
use Types.Type
3
4
// Decides whether a call slot's Func/Action return-type argument is a
5
// real enough type to push down onto a lambda-literal body as its
6
// expected type.
7
class LAMBDA_RETURN_CONSTRAINT is
8
// False for a sentinel (INFERRED_RETURN_TYPE, INFERRED_VARIABLE_TYPE,
9
// ERROR), a provisional composite still carrying one of those, void,
10
// and a slot that still mentions a not-yet-bound method-level type
11
// argument belonging to some other function (`U` in
12
// `map[U](f: T -> U)`, or a composite like `Tasks.TASK[U]`) -
13
// pushing that down would have the body's type-check against the
14
// raw, unresolved type argument instead of letting the body's own
15
// type drive inference. A type parameter `scope` can see is a
16
// different matter: a class-level one already bound in its own
17
// context, and the type parameters of the function whose body is
18
// being compiled, both name a fixed type there and push down like
19
// any other.
20
should_push(candidate: Type?, scope: Scope?) -> bool static =>
21
candidate? /\
22
!candidate.is_inferred /\
23
!candidate.is_error /\
24
!candidate.is_void /\
25
!candidate.is_sentinel /\
26
!candidate.has_function_generic_argument_foreign_to(scope)
27
si
28
si