Printing symbol sometimes prints package prefix when it shouldn't
In the below example, a symbol is imported into package 'a and then exported. package b uses a. When in package b, printing the symbol includes the package prefix when it shouldn't.
;; Setup
cl-user> (defpackage a (:use))
#<PACKAGE A>
cl-user> (import 'cl-user::sym 'a)
t
cl-user> (export 'cl-user::sym 'a)
t
cl-user> (defpackage b (:use a))
#<PACKAGE B>
;; You can see sym is inherited
cl-user> (find-symbol "SYM" 'b)
common-lisp-user::sym
:inherited
;; sym can be correctly read without the package prefix.
cl-user> (let ((*package* (find-package 'b))) (read-from-string "sym"))
common-lisp-user::sym
;; But printing the symbol prints the package too, unecessarily
cl-user> (let ((*package* (find-package 'b)))
(prin1-to-string (find-symbol "SYM" 'b)))
"common-lisp-user::sym"
The relevant bit is in Symbol.java. Search for "Package prefixes are printed if necessary" , then below:
// Has this symbol been imported into the current package?
if (currentPackage.findExternalSymbol(name) == this)
return symbolName;
That code doesn't see if the symbol has been imported into the current package, rather it checks whether the symbol is exported from the current package. The fix is to use the logic in of findSymbol in Package.java which iterates through used packages to see if the symbol it is external in any of them.
I gave a shot at fixing it by calling findSymbol, but must have got something wrong as there was a build error.
@alanruttenberg I think I managed to fix this with https://github.com/easye/abcl/commit/7e53c91ded636878681ddd79dd9a4c498c9527cf.
Waiting for CI test coverage to see if I broke anything…
@alanruttenberg I think I managed to fix this with easye@7e53c91.
Waiting for CI test coverage to see if I broke anything…
Unfortunately this breaks ~50 SYMBOL-* ANSI-TESTS, so I have withdrawn the pull request.
Is there a list of the tests that failed?
Is there a list of the tests that failed?
@alanruttenberg See https://travis-ci.org/github/easye/abcl/jobs/681328414#L14569
One has to disable the use of ql:quickload under the CI tests ala https://github.com/easye/abcl/commit/11dfbb0a17e3cf9abad7ff4edd0b0e07fb7c5540 otherwise Travis will timeout.