Clojure

clojure.repl/source chokes when reading code with ::auto/resolved keys

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Reproduction

foo.clj
(ns foo
  (:require [clojure.java.io :as io]))

(defn f [] ::io/key)
repl
Clojure 1.10.0-alpha4
user=> (require 'foo)
nil
user=> (source foo/f)
RuntimeException Invalid token: ::io/key  clojure.lang.Util.runtimeException (Util.java:221)

Problem analysis
source calls read, without any underlying binding or notion of Compiler.currentNS(), which causes aliased keywords to fail to resolve.

Possible solution
Bind *reader-resolver* to the following before reading:

(reify LispReader$Resolver
  (currentNS [_] 'ignored)
  (resolveClass [_ sym] 'ignored)
  (resolveAlias [_ sym] 'ignored)
  (resolveVar [_ sym] 'ignored))

Aside, the logic inside source-fn can be simplified with read+string, modulo CLJ-2358

Activity

Ghadi Shayban made changes -
Field Original Value New Value
Description *Reproduction*
{code:title=foo.clj|borderStyle=solid}
(ns foo
  (:require [clojure.java.io :as io]))

(defn f [] ::io/key)
{code}
{code:title=repl|borderStyle=solid}
Clojure 1.10.0-alpha4
user=> (require 'foo)
nil
user=> (source foo/f)
RuntimeException Invalid token: ::io/key clojure.lang.Util.runtimeException (Util.java:221)
{code}

*Problem analysis*
{{source}} repeatedly calls {{read}}, without any underlying binding or notion of {{Compiler.currentNS()}}, which causes aliased keywords to fail to resolve.

*Possible solution*
Bind \*reader-resolver\* to the following before reading:
{code}
(reify LispReader$Resolver
  (currentNS [_] 'ignored)
  (resolveClass [_ sym] 'ignored)
  (resolveAlias [_ sym] 'ignored)
  (resolveVar [_ sym] 'ignored))
{code}

Aside, the logic inside {{source-fn}} can be simplified with {{read+string}}, modulo CLJ-2358
*Reproduction*
{code:title=foo.clj|borderStyle=solid}
(ns foo
  (:require [clojure.java.io :as io]))

(defn f [] ::io/key)
{code}
{code:title=repl|borderStyle=solid}
Clojure 1.10.0-alpha4
user=> (require 'foo)
nil
user=> (source foo/f)
RuntimeException Invalid token: ::io/key clojure.lang.Util.runtimeException (Util.java:221)
{code}

*Problem analysis*
{{source}} calls {{read}}, without any underlying binding or notion of {{Compiler.currentNS()}}, which causes aliased keywords to fail to resolve.

*Possible solution*
Bind \*reader-resolver\* to the following before reading:
{code}
(reify LispReader$Resolver
  (currentNS [_] 'ignored)
  (resolveClass [_ sym] 'ignored)
  (resolveAlias [_ sym] 'ignored)
  (resolveVar [_ sym] 'ignored))
{code}

Aside, the logic inside {{source-fn}} can be simplified with {{read+string}}, modulo CLJ-2358

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: