Swift Executable with @main

Hi,

I was trying to use @main using a swift executable swift package init --type executable. The code below builds and runs in Xcode but when I try to run the code in terminal I get the error " 'main' attribute cannot be used in a module that contains top-level code". I was wondering why that might be and if this might be a bug? I am still fairly new with Swift, thanks for your help in advance.

@main
struct Test {
    static func main() {
        print("hello")
    }
}

This is a known bug. [SR-12683] `@main` is no longer usable due to misdetection of top level code · Issue #55127 · apple/swift · GitHub

3 Likes