fix(lang): a function named like an engine namespace method's target is refused

Random.range is rng_range, so a package's own rng_range(a, b, c) took
every Random.range call silently. Where the program calls such a method
and the target resolves to a function of its own, the function is
refused, naming the namespace method and the call. Reseed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 05:14:45 +03:00
parent 31d842fca4
commit 73129b59d5
8 changed files with 13668 additions and 13100 deletions

View file

@ -148,6 +148,21 @@ function ck_builtin(e: Node, name: pointer) -> pointer {
}
return null
}
# a program's function named like the target of one of the engine's own namespace methods takes
# that method's calls - a package's rng_range(a, b, c) made every Random.range a call to it, and
# the checker then asked for its third argument. Refused where the method is called.
var ck_shadow_seen: []pointer = new []pointer
function ck_alias_shadow(e: Node, al: int, tf: Node) -> void {
if not has_sub(g_al_file[al], "runtime/native/") { return }
if tf.file == null or has_sub(tf.file, "runtime/native/") { return }
var i = 0
while i < len(ck_shadow_seen) {
if (ck_shadow_seen[i] == tf.s) { return }
i += 1
}
push(ck_shadow_seen, tf.s)
ck_err("shadow", tf, `{tf.s} is the engine's {g_al_ns[al]}.{g_al_meth[al]}, which this program calls ({e.file}:{itoa(e.line)}), and every such call would reach this function instead; choose another name`)
}
function ck_call(e: Node) -> pointer {
let c = e.a
if c.kind == E_ID { return ck_call_named(e, c.s) }
@ -159,6 +174,7 @@ function ck_call(e: Node) -> pointer {
let al = ns_alias_find(b.s, c.s)
if al >= 0 {
var tf = ck_fn(g_al_target[al])
if tf != null { ck_alias_shadow(e, al, tf) }
if tf == null {
tf = ck_extern(g_al_target[al])
if tf != null { ck_raw(e, `{b.s}.{c.s}, a C function`) }

View file

@ -9,6 +9,7 @@ var g_al_ns: []pointer = new []pointer
var g_al_meth: []pointer = new []pointer
var g_al_target: []pointer = new []pointer
var g_al_labels: []pointer = new []pointer # "a|b|c"; "" for none; null for the target's own
var g_al_file: []pointer = new []pointer # where the alias is declared (the engine's: runtime/native)
function ns_parse_alias(nsname: pointer, is_exp: int) -> void {
pi += 1
@ -33,6 +34,7 @@ function ns_parse_alias(nsname: pointer, is_exp: int) -> void {
push(g_al_meth, meth)
push(g_al_target, target)
push(g_al_labels, labels)
push(g_al_file, g_parse_file)
}
function ns_alias_find(ns: pointer, meth: pointer) -> int {
var i = 0

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff