2024Clojure 状态调查!中分享您的想法。

欢迎!请参阅关于页面以获取更多关于如何使用本站的信息。

+1
ClojureScript

我无法将 #inst 值添加到 var 元数据中。编译失败并出现 Not supported: class java.time.Instant 错误

重新生成步骤

$ mkdir src
$ echo '(ns core) (def ^{:time #inst "2023-10-07"} foo :foo)' > src/core.cljs
$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}' -M --main cljs.main --compile core

预期:编译成功

实际

Unexpected error compiling at (REPL:1).
Not supported: class java.time.Instant

Full report at:
/var/folders/0p/vtdv4p053pd6gkx8d5p98h000000gn/T/clojure-15941611179751768055.edn

分析

CLJS-3291 将 #inst 读取器改为生成 java.time.Instant 而非 java.util.Date。由于分析缓存转储器不知道如何序列化 java.util.Date,因此它无法写入 java.time.Instant

解决方法

(def foo :foo)
(alter-meta #'foo assoc :time #inst "2023-10-07")

完整报告

{:clojure.main/message
 "Unexpected error compiling at (REPL:1).\nNot supported: class java.time.Instant\n",
 :clojure.main/triage
 {:file
  #object[java.io.File 0x608f79a8 "/Users/mikko/Documents/Projects/sharetribe/instant-cljs2/src/core.cljs"],
  :clojure.error/phase :compilation,
  :clojure.error/class java.lang.Exception,
  :clojure.error/cause "Not supported: class java.time.Instant"},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message
    "failed compiling file:/Users/mikko/Documents/Projects/sharetribe/instant-cljs2/src/core.cljs",
    :data
    {:file
     #object[java.io.File 0x608f79a8 "/Users/mikko/Documents/Projects/sharetribe/instant-cljs2/src/core.cljs"],
     :clojure.error/phase :compilation},
    :at
    [cljs.compiler$compile_file$fn__4809 invoke "compiler.cljc" 1768]}
   {:type java.lang.RuntimeException,
    :message
    "java.lang.Exception: Not supported: class java.time.Instant",
    :at
    [com.cognitect.transit.impl.WriterFactory$1
     write
     "WriterFactory.java"
     65]}
   {:type java.lang.Exception,
    :message "Not supported: class java.time.Instant",
    :at
    [com.cognitect.transit.impl.AbstractEmitter
     marshal
     "AbstractEmitter.java"
     195]}],
  :trace
  [[com.cognitect.transit.impl.AbstractEmitter
    marshal
    "AbstractEmitter.java"
    195]
   [com.cognitect.transit.impl.JsonEmitter
    emitMap
    "JsonEmitter.java"
    171]
   [com.cognitect.transit.impl.AbstractEmitter
    emitMap
    "AbstractEmitter.java"
    86]
   [com.cognitect.transit.impl.AbstractEmitter
    marshal
    "AbstractEmitter.java"
    185]
   [com.cognitect.transit.impl.JsonEmitter
    emitMap
    "JsonEmitter.java"
    171]
   [com.cognitect.transit.impl.AbstractEmitter
    emitMap
    "AbstractEmitter.java"
    86]
   [com.cognitect.transit.impl.AbstractEmitter
    marshal
    "AbstractEmitter.java"
    185]
   [com.cognitect.transit.impl.JsonEmitter
    emitMap
    "JsonEmitter.java"
    171]
   [com.cognitect.transit.impl.AbstractEmitter
    emitMap
    "AbstractEmitter.java"
    86]
   [com.cognitect.transit.impl.AbstractEmitter
    marshal
    "AbstractEmitter.java"
    185]
   [com.cognitect.transit.impl.JsonEmitter
    emitMap
    "JsonEmitter.java"
    171]
   [com.cognitect.transit.impl.AbstractEmitter
    emitMap
    "AbstractEmitter.java"
    86]
   [com.cognitect.transit.impl.AbstractEmitter
    marshal
    "AbstractEmitter.java"
    185]
   [com.cognitect.transit.impl.AbstractEmitter
    marshalTop
    "AbstractEmitter.java"
    212]
   [com.cognitect.transit.impl.JsonEmitter emit "JsonEmitter.java" 41]
   [com.cognitect.transit.impl.WriterFactory$1
    write
    "WriterFactory.java"
    62]
   [cljs.vendor.cognitect.transit$write invokeStatic "transit.clj" 171]
   [cljs.vendor.cognitect.transit$write invoke "transit.clj" 168]
   [cljs.analyzer$write_analysis_cache$fn__3960
    invoke
    "analyzer.cljc"
    4771]
   [cljs.analyzer$write_analysis_cache
    invokeStatic
    "analyzer.cljc"
    4770]
   [cljs.analyzer$write_analysis_cache invoke "analyzer.cljc" 4757]
   [cljs.compiler$emit_source invokeStatic "compiler.cljc" 1642]
   [cljs.compiler$emit_source invoke "compiler.cljc" 1557]
   [cljs.compiler$compile_file_STAR_$fn__4778
    invoke
    "compiler.cljc"
    1671]
   [cljs.compiler$with_core_cljs invokeStatic "compiler.cljc" 1477]
   [cljs.compiler$with_core_cljs invoke "compiler.cljc" 1466]
   [cljs.compiler$compile_file_STAR_ invokeStatic "compiler.cljc" 1655]
   [cljs.compiler$compile_file_STAR_ invoke "compiler.cljc" 1648]
   [cljs.compiler$compile_file$fn__4809 invoke "compiler.cljc" 1753]
   [cljs.compiler$compile_file invokeStatic "compiler.cljc" 1728]
   [cljs.compiler$compile_file invoke "compiler.cljc" 1704]
   [cljs.closure$compile_file invokeStatic "closure.clj" 657]
   [cljs.closure$compile_file invoke "closure.clj" 635]
   [cljs.closure$fn__6472 invokeStatic "closure.clj" 731]
   [cljs.closure$fn__6472 invoke "closure.clj" 725]
   [cljs.closure$fn__6381$G__6374__6388 invoke "closure.clj" 553]
   [cljs.closure$compile_sources$iter__6598__6602$fn__6603
    invoke
    "closure.clj"
    1102]
   [clojure.lang.LazySeq sval "LazySeq.java" 42]
   [clojure.lang.LazySeq seq "LazySeq.java" 51]
   [clojure.lang.Cons next "Cons.java" 39]
   [clojure.lang.RT next "RT.java" 713]
   [clojure.core$next__5451 invokeStatic "core.clj" 64]
   [clojure.core$dorun invokeStatic "core.clj" 3143]
   [clojure.core$doall invokeStatic "core.clj" 3149]
   [clojure.core$doall invoke "core.clj" 3149]
   [cljs.closure$compile_sources invokeStatic "closure.clj" 1098]
   [cljs.closure$compile_sources invoke "closure.clj" 1087]
   [cljs.closure$build invokeStatic "closure.clj" 3200]
   [cljs.closure$build invoke "closure.clj" 3104]
   [cljs.build.api$build invokeStatic "api.clj" 231]
   [cljs.build.api$build invoke "api.clj" 212]
   [cljs.cli$default_compile invokeStatic "cli.clj" 530]
   [cljs.cli$default_compile invoke "cli.clj" 486]
   [cljs.cli$compile_opt invokeStatic "cli.clj" 542]
   [cljs.cli$compile_opt invoke "cli.clj" 540]
   [cljs.cli$main invokeStatic "cli.clj" 703]
   [cljs.cli$main doInvoke "cli.clj" 692]
   [clojure.lang.RestFn applyTo "RestFn.java" 139]
   [clojure.core$apply invokeStatic "core.clj" 669]
   [clojure.core$apply invoke "core.clj" 662]
   [cljs.main$_main invokeStatic "main.clj" 65]
   [cljs.main$_main doInvoke "main.clj" 56]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [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 "Not supported: class java.time.Instant",
  :phase :compilation}}
我认为在源代码中放入 #inst 是一个错误https://widdindustries.com/blog/what-is-inst.html

1 答案

0
by

java --version ?

by
➜  java --version
openjdk 11.0.19 2023-04-18
OpenJDK 运行环境 Homebrew (构建 11.0.19+0)
OpenJDK 64 位服务器 VM Homebrew (构建 11.0.19+0, 混合模式)
...