Skip to content

Commit 64c7582

Browse files
Merge pull request #36529 from nate-chandler/rdar75547146
Sema: Stop checking @main if no decl synthesized.
2 parents 126850e + 6c5d62c commit 64c7582

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/AST/Module.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ bool ModuleDecl::isBuiltinModule() const {
14191419
}
14201420

14211421
bool SourceFile::registerMainDecl(Decl *mainDecl, SourceLoc diagLoc) {
1422+
assert(mainDecl);
14221423
if (mainDecl == MainDecl)
14231424
return false;
14241425

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,9 @@ void AttributeChecker::visitMainTypeAttr(MainTypeAttr *attr) {
20122012
SynthesizeMainFunctionRequest{D},
20132013
nullptr);
20142014

2015+
if (!func)
2016+
return;
2017+
20152018
// Register the func as the main decl in the module. If there are multiples
20162019
// they will be diagnosed.
20172020
if (file->registerMainDecl(func, attr->getLocation()))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: not %target-swift-frontend %s -c -parse-as-library
2+
3+
@main struct M1 {
4+
static func main() {}
5+
}
6+
7+
@main struct M2<T> {
8+
static func main() {}
9+
}
10+

0 commit comments

Comments
 (0)