Skip to content

Commit 596a2fc

Browse files
committed
Don't forward @main into SIL
We've already generated the parts necessary to handle `@main` during SILGen. Keeping the attribute on the struct means that re-ingesting the SIL will fail because it tries to re-create the implicit `$main` function resulting in the following error message: error: invalid redeclaration of synthesized static method '$main()' static func $main()
1 parent 7727a96 commit 596a2fc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/AST/Attr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,13 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
895895
}
896896
return true;
897897

898-
case DAK_MainType:
898+
case DAK_MainType: {
899+
// Don't print into SIL. Necessary bits have already been generated.
900+
if (Options.PrintForSIL)
901+
return false;
899902
Printer.printSimpleAttr(getAttrName(), /*needAt=*/true);
900903
return true;
904+
}
901905

902906
case DAK_SetterAccess:
903907
Printer.printKeyword(getAttrName(), Options, "(set)");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %s
2+
// RUN: %target-swift-frontend -emit-silgen -parse-as-library %s | %FileCheck %s
23

34
@main
45
struct EntryPoint {
56
static func main() {
67
}
78
}
9+
10+
// CHECK-NOT: @main struct EntryPoint {
11+
// CHECK: struct EntryPoint {

0 commit comments

Comments
 (0)