summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-10-12 00:42:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-10-12 00:42:16 -0700
commitf2ba3dfc996bfcd67a723b23754e808276ab3b9f (patch)
tree8f9e81e66511ec5fe8d54eb59e66b1add696c25f /lib.c
parent2034e70be87fa1635b7e5a445450c1777c16d2ba (diff)
downloadtxr-f2ba3dfc996bfcd67a723b23754e808276ab3b9f.tar.gz
txr-f2ba3dfc996bfcd67a723b23754e808276ab3b9f.tar.bz2
txr-f2ba3dfc996bfcd67a723b23754e808276ab3b9f.zip
printer: bug: fallback syms printed without prefix.
This is a basic read/print consistency problem. When a symbol is printed that is anywhere in the fallback list of the current package, we are dumping it unqualified, even if it is hidden by a same-named symbol in the current package itself or such a symbol occurring earlier in the fallback list. * lib.c (symbol_needs_prefix): When the to-be-printed symbol is found in the fallback list, re-scan the current package for a symbol having the same name, as well as the preceding nodes in the fallback list. If such a symbol is found, then the to-be printed symbol must be package-qualified. * tests/012/syms.expected: New file. * tests/012/syms.tl: Likewise. * tests/012/compile.tl: Pull syms into compile job. * txr.1: Clarify text about this. The existing text's only reasonable interpretation supports the behavior which this patch ensures (which is needed on grounds of read/print consistency) but the text lacks precision.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index cf2d6cf8..6b13be82 100644
--- a/lib.c
+++ b/lib.c
@@ -7015,6 +7015,7 @@ val symbol_needs_prefix(val self, val package, val sym)
{
val fallback = get_hash_userdata(package->pk.symhash);
+ val rescanfb = fallback;
for (; fallback; fallback = cdr(fallback)) {
val fb_pkg = car(fallback);
@@ -7024,11 +7025,17 @@ val symbol_needs_prefix(val self, val package, val sym)
val cell = gethash_e(self, fb_pkg->pk.symhash, name);
if (cell) {
int found_in_fallback = (eq(cdr(cell), sym) != nil);
- if (found_in_fallback)
- return nil;
- break;
+ if (!found_in_fallback)
+ break;
}
}
+ if (gethash_e(self, package->pk.symhash, name))
+ return sym_pkg->pk.name;
+ for (; rescanfb != fallback && rescanfb; rescanfb = cdr(rescanfb)) {
+ val fb_pkg = car(rescanfb);
+ if (gethash_e(self, fb_pkg->pk.symhash, name))
+ return sym_pkg->pk.name;
+ }
return nil;
} else {
if (gethash_e(self, fb_pkg->pk.symhash, name))