温馨提示:本文翻译自stackoverflow.com,查看原文请点击:clojure.spec - How to read Clojure's spec :macro-syntax-check errors

clojure.spec - 如何阅读Clojure的规范:宏语法检查错误

发布于 2020-03-27 11:09:13

joy.gui.DynaFrame从“关闭之乐”的第12.2.1章中复制了以下定义

(ns joy.gui
  (:gen-class
   :name joy.gui.DynaFrame
   :extends javax.swing.JFrame
   :implements [clojure.lang.IMeta]
   :prefix df-
   :state state
   :init init
   :constructors {[String] [String]
                  [] [String]}
   :methods [[display [java.awt.Container] void]
   ^{:static true} [version [] String]]
   )
  (:import (javax.swing JFrame JPanel JComponent)
           (java.awt BorderLayout Container)))

不幸的是,:prefix自2014年以来,的语法已明显更改,因此第6行应显示为:prefix "df-"

评估上面的错误代码,我收到以下错误消息:

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling src/dipping_feet/gui.clj at (1:1)
   #:clojure.error{:phase :macro-syntax-check,
                   :line 1,
                   :column 1,
                   :source

1. Caused by clojure.lang.ExceptionInfo
   Call to clojure.core/ns did not conform to spec.
   #:clojure.spec.alpha{:problems
                        [{:path [],
                          :reason "Extra input",
                          :pred
                          (clojure.spec.alpha/cat
                           :docstring
                           (clojure.spec.alpha/? clojure.core/string?)
                           :attr-map
                           (clojure.spec.alpha/? clojure.core/map?)
                           :ns-clauses
                           :clojure.core.specs.alpha/ns-clauses),
                          :val
                          ((:gen-class
                            :name
                            joy.gui.DynaFrame
                            :extends
                            javax.swing.JFrame
                            :implements
                            [clojure.lang.IMeta]
                            :prefix
                            df-
                            :state
                            state
                            :init
                            init
                            :constructors
                            {[String] [String], [] [String]}
                            :methods
                            [[display [java.awt.Container] void]
                             [version [] String]])
                           (:import
                            (javax.swing JFrame JPanel JComponent)
                            (java.awt BorderLayout Container))),
                          :via [:clojure.core.specs.alpha/ns-form],
                          :in [1]}],
                        :spec
                        #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x3b982314 "clojure.spec.alpha$regex_spec_impl$reify__2509@3b982314"],
                        :value
                        (joy.gui
                         (:gen-class
                          :name
                          joy.gui.DynaFrame
                          :extends
                          javax.swing.JFrame
                          :implements
                          [clojure.lang.IMeta]
                          :prefix
                          df-
                          :state
                          state
                          :init
                          init
                          :constructors
                          {[String] [String], [] [String]}
                          :methods
                          [[display [java.awt.Container] void]
                           [version [] String]])
                         (:import
                          (javax.swing JFrame JPanel JComponent)
                          (java.awt BorderLayout Container))),
                        :args
                        (joy.gui
                         (:gen-class
                          :name
                          joy.gui.DynaFrame
                          :extends
                          javax.swing.JFrame
                          :implements
                          [clojure.lang.IMeta]
                          :prefix
                          df-
                          :state
                          state
                          :init
                          init
                          :constructors
                          {[String] [String], [] [String]}
                          :methods
                          [[display [java.awt.Container] void]
                           [version [] String]])
                         (:import
                          (javax.swing JFrame JPanel JComponent)
                          (java.awt BorderLayout Container)))}

我在这里省略了堆栈跟踪。

我的问题是:错误消息中是否存在引用,该引用会指向代码中错误的确切位置?我基本上必须猜测我定义的哪一部分是不正确的。

查看更多

查看更多

提问者
Dimitri Vorona
被浏览
20
bbrinck 2019-07-04 06:26

是的,我同意,这是一个令人困惑的错误消息。这似乎是规范中的错误,所以很遗憾,我不认为您现在可以采取任何措施来使错误变得更好。

https://clojure.atlassian.net/browse/CLJ-2013?oldIssueView=true

发布
问题

分享
好友

手机
浏览

扫码手机浏览