Attempt to infer a closure type based on its parameters and body
and put it aside until contextual type becomes available or it
has been determined that there is no context.
Once all appropriate conditions are met, generate constraints for
the body of the closure and bind it the previously inferred type.
Doing so makes it possible to pass single-statement closures as
an argument to a function builder parameter.
Resolves: SR-11628
Resolves: rdar://problem/56340587
Separate closure from top-level constraint generation because
its body shouldn't be considered when it comes to parent/weight
computation, otherwise top expression in body is going to get
disconnected from the closure.
Rather than mutating the parameter pattern in place and separately
return whether an error occurred, return the new pattern or NULL if an
error occurred. While here, switch over to ContextualPattern for the
input.
And get rid of that infernal "goto".
Contextual pattern describes a particular pattern with enough
contextual information to determine its type. Use this to simplify
TypeChecker::typeCheckPattern()'s interface in a manner that will
admit request'ification.
Make TypeChecker::typeCheckPattern() return the computed type, rather
than returning an "error" flag. More importantly, make it functional,
so that it doesn't set the type it computes on the pattern.
Use UnresolvedType as a placeholder for types that need to be
inferred, rather than a null type. This allows us to produce
structural types involving types that need to be inferred.
Note that with this change as-is, we get a number of duplicated
diagnostics, because typeCheckPattern() will be called multiple times
for the same pattern and will emit some diagnostics each time. This
will be addressed in a subsequent commit.
Curry thunks create AutoClosureExprs with parameters, and we can't just
fold those away.
Also, remove an older AutoClosureExpr cleanup that seems to be
redundant.
It might be either impossible to infer the base because there is
no contextual information e.g. `_ = .foo` or there is something
else wrong in the expression which disconnects member reference
from its context.
Rather than setting up the constraint solver with a single expression
(that gets recorded for parents/depths), record each expression that
goes through constraint generation.
This commit moves the getNSObjectType and
getObjCSelectorType methods from TypeChecker
onto ASTContext. In addition, it moves the
FOR_KNOWN_FOUNDATION_TYPES macro into a separate
file to define each of the Obj-C type decls
we want to have access to.
ProtocolConformanceRef already has an invalid state. Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it. Mechanically
translate all of the callers and callsites to use this new
representation.