Files
Nim/tests/ic/mexportprivate.nim
araq bff0bc45fd IC: export s makes s importable even without a * on its declaration
`nim c --ic:on` could not compile anything that reached `std/tempfiles`:

    lib/std/tempfiles.nim(115, 38) Error: type mismatch
    Expression: initRand()
    Expected one of: [1] proc initRand(seed: int64)

That is `std/random`. It declares `proc initRand(): Rand` WITHOUT a `*`
and then, forty lines later, `since (1, 5, 1): export initRand`.

Two mechanisms make a symbol importable and the writer only knew one.
`sfExported` is the `*` on the declaration; `semExport` instead calls
`reexportSym`, which adds the symbol to the module's interface table and
sets no flag. `writeSymDef` decided the NIF `x` marker — "importable as a
bare identifier" — from `sfExported` alone, so a symbol exported the
second way shipped as private and its importer reported an undeclared
identifier. Nothing about this is IC-specific in the source; it is
ordinary stdlib code that classic compilation accepts.

So ask the interface too: `reexportedLocalSyms` collects the symbols a
module defines that reached its interface without the flag, and they get
the marker. Symbols that are genuinely private still do not — the
regression test's sibling case (`proc g()`, never exported) is still
rejected under both `--ic:on` and `--ic:off`.

This was found by pointing `--ic:on` at Atlas, which is now the first
sizeable third-party program it builds. `nim c --ic:off` and `--ic:on`
produce the same working binary from the same 209-module closure.

ic 41/41 (the new test is the 41st), `koch boot -d:release` equal
executables.
2026-08-31 14:51:25 +02:00

5 lines
130 B
Nim

proc pub*(x: int): int = x + 1
proc hidden(): int = 42 # no `*` ...
export hidden # ... but explicitly re-exported