Skip to content

Commit 8f6d22c

Browse files
authored
Merge pull request #59919 from etcwilde/ewilde/improve-main-error
Adding actionable note to @main error
2 parents 69c06f9 + aba6b92 commit 8f6d22c

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,10 @@ ERROR(attr_ApplicationMain_with_script,none,
32553255
"%" SELECT_APPLICATION_MAIN "0 attribute cannot be used in a module that contains "
32563256
"top-level code",
32573257
(unsigned))
3258+
3259+
NOTE(attr_ApplicationMain_parse_as_library,none,
3260+
"pass '-parse-as-library' to compiler invocation if this is intentional",
3261+
())
32583262
NOTE(attr_ApplicationMain_script_here,none,
32593263
"top-level code defined in this source file",
32603264
())

lib/AST/Module.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,8 @@ bool ModuleDecl::registerEntryPointFile(FileUnit *file, SourceLoc diagLoc,
18411841
if (existingDiagLoc.isValid()) {
18421842
getASTContext().Diags.diagnose(existingDiagLoc,
18431843
diag::attr_ApplicationMain_script_here);
1844+
getASTContext().Diags.diagnose(existingDiagLoc,
1845+
diag::attr_ApplicationMain_parse_as_library);
18441846
}
18451847
}
18461848
}

test/attr/ApplicationMain/attr_NSApplicationMain_with_main/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// expected-note{{top-level code defined in this source file}}
2+
// expected-note@-1{{pass '-parse-as-library' to compiler invocation if this is intentional}}
23
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s %S/delegate.swift
34

45
// Serialized partial AST support:

test/attr/ApplicationMain/attr_UIApplicationMain_with_main/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// expected-note{{top-level code defined in this source file}}
2+
// expected-note@-1{{pass '-parse-as-library' to compiler invocation if this is intentional}}
23
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s %S/delegate.swift
34

45
// REQUIRES: objc_interop
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// expected-note{{top-level code defined in this source file}}
2+
// expected-note@-1{{pass '-parse-as-library' to compiler invocation if this is intentional}}
23
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s %S/file.swift
34

45
hi()

0 commit comments

Comments
 (0)