// expected: init() is not allowed in main package // // A main package's setup belongs in main(), which is the program entry; an // init() there would run before it with no defined place in the entry // sequence. Legacy says so, and stage4 now rejects it too: it used to print // "init() is not allowed" and skip the function, so the program built and the // init never ran - a silent difference, not a rejection. // // A library package may have exactly one init(), which runs after its // package-level variable initializers and before any importer's. // // Note on legacy: its package-declaration checks are gated on the shape of the // package path, so legacy rejects this file when the build root resolves to a // module path but accepts the same source copied to a bare out-of-tree // directory (whose path has no dot). stage4 applies the rule by package kind, // which is what the rule says; the restriction harness copies test sources to // an out-of-tree directory, so this one is intentionally stage4-only. package main func init() { println("setup") } func main() { println("body") }