mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
6 lines
261 B
Swift
6 lines
261 B
Swift
// expected-note{{top-level code defined in this source file}}
|
|
// expected-note@-1{{pass '-parse-as-library' to compiler invocation if this is intentional}}
|
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s %S/file.swift
|
|
|
|
hi()
|