mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Adding actionable note to @main error
The compiler enters "script" mode if there is a file called `main.swift`, or if there is only one file. Parsing files as a script means that anything in the file is interpreted as top-level code, which is incompatible with a valid @main-annotated struct, so an error is emitted. Unfortunately, it is intentional in many cases, and the diagnostic didn't provide anything actionable to indicate that the explicit main function is intentional and that the file being passed in is not actually a top-level context. The new note indicates that passing `-parse-as-library` to the compiler invocation will fix it if the explicit main function is intentional.
This commit is contained in:
@@ -1841,6 +1841,8 @@ bool ModuleDecl::registerEntryPointFile(FileUnit *file, SourceLoc diagLoc,
|
||||
if (existingDiagLoc.isValid()) {
|
||||
getASTContext().Diags.diagnose(existingDiagLoc,
|
||||
diag::attr_ApplicationMain_script_here);
|
||||
getASTContext().Diags.diagnose(existingDiagLoc,
|
||||
diag::attr_ApplicationMain_parse_as_library);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user