tools.analyzer

analyzing extend expression with non-constant type/class throws exception

Details

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

Description

Here is an example that is slightly cut down from code in namespace seesaw.widgets.log-window, where I first saw the issue. It could be cut down a little more. The main point is that the first arg to extend-type is not a constant, but a fn call that returns a class:

(defn- log-window-proxy [state]
  (proxy [javax.swing.JTextArea clojure.lang.IDeref] []
    ; Implement IDeref
    (deref [] state) 

    ; this is how you disable auto-scrolling :(
    (scrollRectToVisible [rect]
                         (if @(:auto-scroll? state)
                           (proxy-super scrollRectToVisible rect)))))

(defprotocol LogWindow
  (log   [this message])
  (clear [this]))

(extend-type (class (log-window-proxy nil))
  LogWindow
  (log [this message]
    (println "message" message))
  (clear [this] 
    nil))

Activity

Hide
Nicola Mometto added a comment -

Yet another #TANAL-24 related bug.

(extend-type (class 1) proto (protof [this]))

extends to

(extend (class 1) proto {:protof (fn [^{:tag '(class 1)} this])})

And clojure swallows that silently.
It's not clear to me whether extend-type is supposed to work that way, but since the docstring says explicitely "Propagates the class as a type hint on the first argument of all fns." and this is clearly not true, I will consider this as a Clojure bug and fill a ticket.

I'll keep this ticket open too until #TANAL-24 gets resolved.

Show
Nicola Mometto added a comment - Yet another #TANAL-24 related bug.
(extend-type (class 1) proto (protof [this]))
extends to
(extend (class 1) proto {:protof (fn [^{:tag '(class 1)} this])})
And clojure swallows that silently. It's not clear to me whether extend-type is supposed to work that way, but since the docstring says explicitely "Propagates the class as a type hint on the first argument of all fns." and this is clearly not true, I will consider this as a Clojure bug and fill a ticket. I'll keep this ticket open too until #TANAL-24 gets resolved.
Hide
Nicola Mometto added a comment -
Show
Nicola Mometto added a comment - Clojure ticket: http://dev.clojure.org/jira/browse/CLJ-1308

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: