Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata fn on defn f fails if calling defn f #363

Closed
lread opened this issue Jul 2, 2020 · 0 comments
Closed

metadata fn on defn f fails if calling defn f #363

lread opened this issue Jul 2, 2020 · 0 comments

Comments

@lread
Copy link
Contributor

lread commented Jul 2, 2020

version
0.1.1-alpha.2

platform
macOS 10.15.5
Clojure 1.10.536 on JDK 11

symptom
When metadata :test on (defn x) is a function and that function calls x, x cannot be resolved.

This use case occurs in test.check's defspec.

repro
Here's my attempt at distilling the issue to a file we'll call metaeval.clj:

(defn ^{:test (fn []
                (println "hey there from af meta fn")
                (af))}
  af []
   (println "hi from af"))

(println "call af:")
(af)

(println "\ncall af :test fn:")
((:test (meta #'af)))

expected behavior
If we run the above code through Clojure, all works as expected:

> clojure metaeval.clj
call af:
hi from af

call af :test fn:
hey there from af meta fn
hi from af

actual behaviour
Running the same code through sci gives us:

> clojure -Sdeps '{:deps {borkdude/sci {:mvn/version "0.1.1-alpha.2"}}}' \
               --report stderr \
               -e "(require '[sci.core :as sci]) (sci/binding [sci/out *out*] (sci/eval-string (slurp \"metaeval.clj\")))"
{:clojure.main/message
 "Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:54).\nCould not resolve symbol: af [at line 3, column 18]\n",
 :clojure.main/triage
 {:clojure.error/class clojure.lang.ExceptionInfo,
  :clojure.error/line 54,
  :clojure.error/cause
  "Could not resolve symbol: af [at line 3, column 18]",
  :clojure.error/symbol sci.impl.utils/throw-error-with-location,
  :clojure.error/source "utils.cljc",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message "Could not resolve symbol: af [at line 3, column 18]",
    :data {:type :sci/error, :line 3, :column 18},
    :at
    [sci.impl.utils$throw_error_with_location
     invokeStatic
     "utils.cljc"
     54]}],
  :trace
  [[sci.impl.utils$throw_error_with_location
    invokeStatic
    "utils.cljc"
    54]
   [sci.impl.utils$throw_error_with_location invoke "utils.cljc" 44]
   [sci.impl.utils$throw_error_with_location
    invokeStatic
    "utils.cljc"
    45]
   [sci.impl.utils$throw_error_with_location invoke "utils.cljc" 44]
   [sci.impl.analyzer$resolve_symbol invokeStatic "analyzer.cljc" 137]
   [sci.impl.analyzer$resolve_symbol invoke "analyzer.cljc" 115]
   [sci.impl.analyzer$analyze_call invokeStatic "analyzer.cljc" 645]
   [sci.impl.analyzer$analyze_call invoke "analyzer.cljc" 637]
   [sci.impl.analyzer$analyze invokeStatic "analyzer.cljc" 748]
   [sci.impl.analyzer$analyze invoke "analyzer.cljc" 727]
   [sci.impl.analyzer$analyze_children$fn__905
    invoke
    "analyzer.cljc"
    146]
   [clojure.core$mapv$fn__8445 invoke "core.clj" 6912]
   [clojure.lang.PersistentList reduce "PersistentList.java" 144]
   [clojure.core$reduce invokeStatic "core.clj" 6827]
   [clojure.core$mapv invokeStatic "core.clj" 6903]
   [clojure.core$mapv invoke "core.clj" 6903]
   [sci.impl.analyzer$analyze_children
    invokeStatic
    "analyzer.cljc"
    146]
   [sci.impl.analyzer$analyze_children invoke "analyzer.cljc" 145]
   [sci.impl.analyzer$expand_fn_args_PLUS_body
    invokeStatic
    "analyzer.cljc"
    198]
   [sci.impl.analyzer$expand_fn_args_PLUS_body
    invoke
    "analyzer.cljc"
    166]
   [sci.impl.analyzer$expand_fn$fn__933 invoke "analyzer.cljc" 222]
   [clojure.lang.PersistentVector reduce "PersistentVector.java" 343]
   [clojure.core$reduce invokeStatic "core.clj" 6827]
   [clojure.core$reduce invoke "core.clj" 6810]
   [sci.impl.analyzer$expand_fn invokeStatic "analyzer.cljc" 219]
   [sci.impl.analyzer$expand_fn invoke "analyzer.cljc" 205]
   [sci.impl.analyzer$analyze_call invokeStatic "analyzer.cljc" 670]
   [sci.impl.analyzer$analyze_call invoke "analyzer.cljc" 637]
   [sci.impl.analyzer$analyze invokeStatic "analyzer.cljc" 748]
   [sci.impl.analyzer$analyze invoke "analyzer.cljc" 727]
   [sci.impl.analyzer$analyze_children$fn__905
    invoke
    "analyzer.cljc"
    146]
   [clojure.core$mapv$fn__8445 invoke "core.clj" 6912]
   [clojure.core.protocols$iter_reduce invokeStatic "protocols.clj" 49]
   [clojure.core.protocols$fn__8148 invokeStatic "protocols.clj" 75]
   [clojure.core.protocols$fn__8148 invoke "protocols.clj" 75]
   [clojure.core.protocols$fn__8088$G__8083__8101
    invoke
    "protocols.clj"
    13]
   [clojure.core$reduce invokeStatic "core.clj" 6828]
   [clojure.core$mapv invokeStatic "core.clj" 6903]
   [clojure.core$mapv invoke "core.clj" 6903]
   [sci.impl.analyzer$analyze_children
    invokeStatic
    "analyzer.cljc"
    146]
   [sci.impl.analyzer$analyze_children invoke "analyzer.cljc" 145]
   [sci.impl.analyzer$analyze invokeStatic "analyzer.cljc" 742]
   [sci.impl.analyzer$analyze invoke "analyzer.cljc" 727]
   [sci.impl.analyzer$expand_declare$fn__1037$fn__1038$fn__1039
    invoke
    "analyzer.cljc"
    477]
   [clojure.lang.ArrayChunk reduce "ArrayChunk.java" 58]
   [clojure.core.protocols$fn__8154 invokeStatic "protocols.clj" 136]
   [clojure.core.protocols$fn__8154 invoke "protocols.clj" 124]
   [clojure.core.protocols$fn__8114$G__8109__8123
    invoke
    "protocols.clj"
    19]
   [clojure.core.protocols$seq_reduce invokeStatic "protocols.clj" 31]
   [clojure.core.protocols$fn__8144 invokeStatic "protocols.clj" 75]
   [clojure.core.protocols$fn__8144 invoke "protocols.clj" 75]
   [clojure.core.protocols$fn__8088$G__8083__8101
    invoke
    "protocols.clj"
    13]
   [clojure.core$reduce invokeStatic "core.clj" 6828]
   [clojure.core$reduce invoke "core.clj" 6810]
   [sci.impl.analyzer$expand_declare$fn__1037$fn__1038
    invoke
    "analyzer.cljc"
    469]
   [clojure.lang.AFn applyToHelper "AFn.java" 154]
   [clojure.lang.AFn applyTo "AFn.java" 144]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$update_in$up__6853 invoke "core.clj" 6185]
   [clojure.core$update_in$up__6853 invoke "core.clj" 6184]
   [clojure.core$update_in invokeStatic "core.clj" 6186]
   [clojure.core$update_in doInvoke "core.clj" 6172]
   [clojure.lang.RestFn invoke "RestFn.java" 445]
   [sci.impl.analyzer$expand_declare$fn__1037
    invoke
    "analyzer.cljc"
    467]
   [clojure.lang.Atom swap "Atom.java" 37]
   [clojure.core$swap_BANG_ invokeStatic "core.clj" 2352]
   [clojure.core$swap_BANG_ invoke "core.clj" 2345]
   [sci.impl.analyzer$expand_declare invokeStatic "analyzer.cljc" 464]
   [sci.impl.analyzer$expand_declare invoke "analyzer.cljc" 463]
   [sci.impl.analyzer$expand_defn invokeStatic "analyzer.cljc" 324]
   [sci.impl.analyzer$expand_defn invoke "analyzer.cljc" 321]
   [sci.impl.analyzer$analyze_call invokeStatic "analyzer.cljc" 673]
   [sci.impl.analyzer$analyze_call invoke "analyzer.cljc" 637]
   [sci.impl.analyzer$analyze invokeStatic "analyzer.cljc" 748]
   [sci.impl.analyzer$analyze invoke "analyzer.cljc" 727]
   [sci.impl.interpreter$eval_form invokeStatic "interpreter.cljc" 647]
   [sci.impl.interpreter$eval_form invoke "interpreter.cljc" 639]
   [sci.impl.interpreter$eval_string_STAR_
    invokeStatic
    "interpreter.cljc"
    659]
   [sci.impl.interpreter$eval_string_STAR_
    invoke
    "interpreter.cljc"
    653]
   [sci.impl.interpreter$eval_string
    invokeStatic
    "interpreter.cljc"
    668]
   [sci.impl.interpreter$eval_string invoke "interpreter.cljc" 664]
   [sci.core$eval_string invokeStatic "core.cljc" 179]
   [sci.core$eval_string invoke "core.cljc" 142]
   [sci.core$eval_string invokeStatic "core.cljc" 177]
   [sci.core$eval_string invoke "core.cljc" 142]
   [user$eval5158 invokeStatic "NO_SOURCE_FILE" 1]
   [user$eval5158 invoke "NO_SOURCE_FILE" 1]
   [clojure.lang.Compiler eval "Compiler.java" 7177]
   [clojure.lang.Compiler eval "Compiler.java" 7132]
   [clojure.core$eval invokeStatic "core.clj" 3214]
   [clojure.main$eval_opt invokeStatic "main.clj" 488]
   [clojure.main$eval_opt invoke "main.clj" 482]
   [clojure.main$initialize invokeStatic "main.clj" 508]
   [clojure.main$null_opt invokeStatic "main.clj" 542]
   [clojure.main$null_opt invoke "main.clj" 539]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause "Could not resolve symbol: af [at line 3, column 18]",
  :data {:type :sci/error, :line 3, :column 18}}}

Execution error (ExceptionInfo) at sci.impl.utils/throw-error-with-location (utils.cljc:54).
Could not resolve symbol: af [at line 3, column 18]

Notice that af could not be resolved within the meta :test function.

borkdude added a commit to babashka/babashka that referenced this issue Jul 3, 2020
@borkdude borkdude closed this as completed Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants