Skip to content

Commit 698a0a3

Browse files
authored
Merge pull request swiftlang#35193 from etcwilde/ewilde/there-is-no-try-on-main-only-do
Adding implicit try-expr to throwing main
2 parents 7ad3455 + efb50e1 commit 698a0a3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,14 +1952,14 @@ synthesizeMainBody(AbstractFunctionDecl *fn, void *arg) {
19521952

19531953
if (mainFunction->hasThrows()) {
19541954
auto *tryExpr = new (context) TryExpr(
1955-
SourceLoc(), callExpr, context.TheEmptyTupleType, /*implicit=*/true);
1955+
callExpr->getLoc(), callExpr, context.TheEmptyTupleType, /*implicit=*/true);
19561956
returnedExpr = tryExpr;
19571957
} else {
19581958
returnedExpr = callExpr;
19591959
}
19601960

19611961
auto *returnStmt =
1962-
new (context) ReturnStmt(SourceLoc(), callExpr, /*Implicit=*/true);
1962+
new (context) ReturnStmt(SourceLoc(), returnedExpr, /*Implicit=*/true);
19631963

19641964
SmallVector<ASTNode, 1> stmts;
19651965
stmts.push_back(returnStmt);
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend -dump-ast -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-AST
23

34
@main
45
struct MyBase {
5-
static func main() throws {
6+
static func main() throws {
67
}
78
}
89

10+
// CHECK-AST: (func_decl implicit "$main()" interface type='(MyBase.Type) -> () throws -> ()' access=internal type
11+
// CHECK-AST-NEXT: (parameter "self")
12+
// CHECK-AST-NEXT: (parameter_list)
13+
// CHECK-AST-NEXT: (brace_stmt implicit
14+
// CHECK-AST-NEXT: (return_stmt implicit
15+
// CHECK-AST-NEXT: (try_expr implicit
16+
// CHECK-AST-NEXT: (call_expr implicit type='()'

0 commit comments

Comments
 (0)