ww package: reject non-function main declarations

This commit is contained in:
2026-08-21 15:13:09 +09:00
parent 2b7fafde0c
commit 2387d3e2d2
6 changed files with 520 additions and 3 deletions

View File

@@ -307,9 +307,17 @@ ImportPath = ident { "." ident } .
ownership, symbols, artifacts, storage, or diagnostics. Repeated occurrences
of the same exact identity remain valid and deduplicate normally.
- An executable package is one declared `package main` and containing a
`fn main`; path and directory spelling do not classify commands. An ordinary
import of a package declared `main` is rejected, except for the toolchain's
colocated external-test wiring.
`fn main`; path and directory spelling do not classify commands. Within a
package declared `main`, a package-scope declaration named `main` must be a
function: `let`, `const`, `def`, and `type` forms reject as
`cannot declare main - must be func` and do not enter package scope. The
restriction depends only on the declared package name. A package with any
other declared name may use or export `main` regardless of its dotted import
path, path leaf, physical directory, or selection role. WW retains its
established program-entry ABI, so a function `main` may carry WW's supported
arguments and result; this rule does not adopt Go's source signature. An
ordinary import of a package declared `main` is rejected, except for the
toolchain's colocated external-test wiring.
- For `ww build`, an explicit `-o` names an output directory when ordinary
`stat` reports an existing directory (following symlinks) or its spelling
ends in `/`. This classification is independent of whether one or many
@@ -414,6 +422,13 @@ called as `init()`, selected as `pkg.init`, exported, or used by another kind
of declaration. Package-variable initialization completes before these
functions run.
In a package whose declared name is `main`, only a function declaration may
claim the package-scope name `main`. A rejected non-function declaration is not
installed and cannot satisfy the executable entry. This is independent of
canonical import identity and physical location. The accepted function shape
continues to use WW's entry ABI, including its supported argument and result
forms.
### 5.2 `let`
```
@@ -697,6 +712,12 @@ under test binds to the augmented white-box action when it exists; affected
transitive importers are copied and rewired so ordinary and augmented package
state do not coexist in the linked closure.
A non-function package-scope `main` in production or same-package test source
of a package declared `main` is a package-checker failure. Generated test-main
ownership does not hide or replace it: the product is not linked or executed,
no test accounting or package `ok` result is emitted, and ordinary build/test
failure presentation and rollback apply.
Those variants are action distinctions over exact package representatives, not
new ordinary package identities for case-fold comparison. Production,
same-package test, external test, and recompiled copies of one exact canonical