ww package: reject non-function main declarations
This commit is contained in:
@@ -7696,6 +7696,36 @@ fn classifyinitdecls(c: *checker, file: *syntax.node) void = {
|
||||
};
|
||||
};
|
||||
|
||||
// Pinned Go 1.26.5 types2 rejects a non-function package-scope `main`
|
||||
// before declaring it, but only when the declared package name is `main`
|
||||
// (resolver.go:90-110 declarePkgObj). WW's function entry ABI deliberately
|
||||
// permits argument/result-bearing functions, so this is the independent
|
||||
// declaration-kind rule: canonical identity, physical directory, path leaf,
|
||||
// and root/action status are not inputs. Remove rejected declarations from
|
||||
// later name installation just as the pinned resolver returns without
|
||||
// declaring its object. Twin of cmd/wcc/check.c.
|
||||
fn rejectnonfunctionmaindecls(c: *checker, file: *syntax.node) void = {
|
||||
let prev: *syntax.node = nil;
|
||||
let d: *syntax.node = file.list;
|
||||
for (d != nil) {
|
||||
let next: *syntax.node = d.next;
|
||||
let invalid: bool = topdeclkind(d)
|
||||
&& d.kind != syntax.nkind.N_FNDECL
|
||||
&& syntax.streq(d.str, "main")
|
||||
&& syntax.streq(d.pkgname, "main");
|
||||
if (invalid) {
|
||||
importdiagprefix(d);
|
||||
cerr("cannot declare main - must be func\n");
|
||||
c.errs += 1;
|
||||
if (prev == nil) { file.list = next; }
|
||||
else { prev.next = next; };
|
||||
} else {
|
||||
prev = d;
|
||||
};
|
||||
d = next;
|
||||
};
|
||||
};
|
||||
|
||||
fn initstripcast(n: *syntax.node) *syntax.node = {
|
||||
for (n != nil && n.kind == syntax.nkind.N_CAST) { n = n.lhs; };
|
||||
return n;
|
||||
@@ -8578,6 +8608,7 @@ fn checkfile(c: *checker, file: *syntax.node) void = {
|
||||
file.list = usenode;
|
||||
};
|
||||
};
|
||||
rejectnonfunctionmaindecls(c, file);
|
||||
markimportuses(c, file);
|
||||
checkimportredeclarations(c, file);
|
||||
checkimportusageandcollisions(c, file);
|
||||
|
||||
Reference in New Issue
Block a user