Commit Graph

8 Commits

Author SHA1 Message Date
Tony Allevato
f249db3f85 Use cached evaluator results when looking up function types.
Also improve the output for thrown error destinations in
parsable modes.
2025-01-22 14:26:14 -05:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Doug Gregor
e1be9c312b Eliminate the DeclContext from ExplicitCaughtTypeRequest
Correctly determining the DeclContext needed for an
ExplicitCaughtTypeRequest is tricky for a number of callers, and
mistakes here can easily lead to redundant computation of the caught
type, redundant diagnostics, etc.

Instead, put a `DeclContext` into `DoCatchStmt`, because that's the
only catch node that needs a `DeclContext` but does not have one.
2023-12-13 11:42:56 -08:00
Doug Gregor
05a4a822ba Tighten CatchNode from an AbstractClosureExpr to a ClosureExpr.
Only real closures can have thrown error types, so we can use the
tighter bound for closures and simplify various CatchNode operations.
2023-12-12 22:30:18 -08:00
Doug Gregor
91df336a4d [Typed throws] Unify ThrownTypeRequest and DoCatchExplicitThrownTypeRequest
These two requests are effectively doing the same thing to two
different cases within CatchNode. Unify the requests into a single
request, ExplicitCaughtTypeRequest, which operates on a CatchNode.

This also moves the logic for closures with explicitly-specified throws
clauses into the same request, taking it out of the constraint system.
2023-12-12 00:06:17 -08:00
Doug Gregor
49b05cec84 [Typed throws] Make try? and try! into catch nodes
Both `try?` and `try!` are catch nodes, because they catch an error
thrown in their subexpression and handle it. Introduce an ASTScope for
all `try/try?/try1` expressions so we can find them, and model them as
catch nodes.

Fixes rdar://119216455.
2023-12-06 15:00:58 -08:00
Doug Gregor
cfe2b3c87d [Typed throws] Implement support for do throws(...) syntax
During the review of SE-0413, typed throws, the notion of a `do throws`
syntax for `do..catch` blocks came up. Implement that syntax and
semantics, as a way to explicitly specify the type of error that is
thrown from the `do` body in `do..catch` statement.
2023-12-02 07:37:47 -08:00
Doug Gregor
3dd4df2351 [Typed throws] Location based lookup for the thrown error type
Introduce a new API to find the AST node that catches or rethrows an
error thrown from the given source location. Use it to determine the
thrown error type to use for type checking a `throw` statement, which
begins as `any Error` within a `do..catch` and is later refined.
2023-10-15 22:59:48 -07:00