~/temp $ swift ./testmain.swift 1 ↵
./testmain.swift:1:1: error: 'main' attribute cannot be used in a module that contains top-level code
@main
^
./testmain.swift:1:1: note: top-level code defined in this source file
@main
^
~/temp $
This happens 100% of the time, regardless if @main is on the first line or not (I first noticed it when it complained about having import Foundation as "top level code"
This is as of the 2020-06-05-SNAPSHOT build. I did some searching to see if there were any bug reports or yet-unresolved issues, but my searches didn't lead me to anything useful.
Yes, the workaround in the bug report does work. The interesting thing is that it works if compiling (i.e. swiftc) but not just running; I'd think that, with this attribute, I should be able to throw a bunch of .swift files at swift and let it figure out what to run based on @main without needing an actual main.swift.