fix(lang): 0.R4 - ludic.ui's UiAct is its own, and a name that meets a package's export says whose it is

A game's exported UiAct collided with ludic.ui's, which nothing outside ludic.ui uses: it is private
to ludic.ui now, and a private record of one spelling in two modules never clashed. A real clash - a
type named like one a package exports - is still refused, and the message names the package and the
way out (`ludic_ui exports it, and exported names are one namespace - rename this one, or declare it
without export inside a module of your own`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-26 06:57:35 +03:00
parent eb1e780733
commit d46f0adb5e
10 changed files with 1095 additions and 879 deletions

View file

@ -119,7 +119,10 @@ show.
The same holds for a `property` and an `event`: `fishing` and `hunting` may each have a private
`Catch` record and a private `Landed` event with different fields, and each module's types, `new`,
`emit` and `@On` reach its own (compiled as `Catch__fishing`). Two exported ones of one spelling are
refused (`'Catch' is defined twice`, `event 'Landed' is defined twice`). Three kinds of record stay
refused (`'Catch' is defined twice`, `event 'Landed' is defined twice`). When one of the two is a package's export the message
says so (`'UiNode' is defined twice (...): ludic_ui exports it, and exported names are one namespace -
rename this one, or declare it without export inside a module of your own`); a package exports only
what a program uses, so ludic.ui's `UiAct` is its own and a game's may take the name. Three kinds of record stay
one namespace, because other code names them by spelling: a generic record, a property that is an
entity's component (a `model` names it), and the record a component or a view generates.

View file

@ -0,0 +1,8 @@
bump: patch
type: fix
**A name that meets a package's export says whose it is; ludic.ui's `UiAct` is its own.** A game's
`UiAct` collided with ludic.ui's, which no program uses - it is private to ludic.ui now, so the game
may have one. A real clash - a type named like one a package exports - is still refused, and the
message names the package and the way out: `'UiNode' is defined twice (...): ludic_ui exports it, and
exported names are one namespace - rename this one, or declare it without export inside a module of
your own`.

View file

@ -0,0 +1,7 @@
# own_uiact.ludic - a game module may export a record named like one of ludic.ui's own private ones
import "ludic.ui"
import "own_uiact/acts"
program OwnUiAct {
numbers float
entry { print(`{act_kind()}`) }
}

View file

@ -0,0 +1,6 @@
module acts
export property UiAct { kind: int = 3 }
export function act_kind() -> int {
let a = new UiAct
return a.kind
}

View file

@ -0,0 +1,7 @@
# a program's type named like a package's export is a real clash, and the message says whose
import "ludic.ui"
program PkgClash {
numbers float
property UiNode { kind: int = 3 }
entry { print("x") }
}

View file

@ -4,7 +4,7 @@
const A_CALL: int = 0
const A_SET: int = 1
const A_EMIT: int = 2
export property UiAct {
property UiAct {
kinds: []int = null
names: []string = null
exprs: []UiExpr = null

View file

@ -239,6 +239,15 @@ function decl_group(k: int) -> int {
if k == N_STRUCT or k == N_COMP or k == N_EVENT { return 2 }
return 0
}
# when one of the two is a package's export: say so, and what to do - exported names are one
# namespace, and a module's private one of the same spelling would not clash
function dup_whose(first: Node, d: Node) -> pointer {
var pk = pkg_of_file(first.file)
if pk == "" { pk = pkg_of_file(d.file) }
if pk == "" { return "" }
if not (pkg_of_file(first.file) == "") and not (pkg_of_file(d.file) == "") { return "" }
return `: {pk} exports it, and exported names are one namespace - rename this one, or declare it without export inside a module of your own`
}
function check_duplicate_decls() -> void {
let k = new []pointer
let v = new []Node
@ -254,7 +263,7 @@ function check_duplicate_decls() -> void {
if first != null {
g_err_file = d.file
g_err_line = d.line
perr(`'{d.s}' is defined twice (first in {first.file}:{itoa(first.line)})`)
perr(`'{d.s}' is defined twice (first in {first.file}:{itoa(first.line)}){dup_whose(first, d)}`)
}
ck_tab_put(k, v, key, d)
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1005,6 +1005,8 @@ function cmd_dev_test() -> int {
reject_case("rejected/exported_kinds", "'Catch' is defined twice", "two modules that export one record still clash")
reject_case("rejected/exported_events", "event 'Landed' is defined twice", "two modules that export one event clash")
feat_case("modules/tangle", "", "4", "tangle.ludic (the program ludic deps is tested on)")
feat_case("modules/own_uiact", "", "3", "own_uiact.ludic (0.R4: a game's exported UiAct does not meet ludic.ui's, which is its own module's)")
reject_case("rejected/pkg_export_clash", "ludic_ui exports it, and exported names are one namespace", "a type named like a package's export says whose it is")
reject_case("rejected/exported_twins", "function 'seed' is defined twice", "two modules that export one name still clash")
feat_case("modules/layers", "", "5", "layers.ludic (L3: `module menu in layer app uses items` - one layer's modules use each other and may go round)")
reject_case("rejected/layer_reach", "hud uses items.item_count", "a layered module is still held to its uses outside the layer")