Clojure

Unexpected interaction between protocol extension and namespaced method keyword/symbols

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: Release 1.3
  • Fix Version/s: Release 1.4
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

If the keywords of a protocol's method map are namespaced, the map is accepted, but lookup fails since lookup uses non-namespaced keywords.

See TLOG-4 for an actual case of this being an issue.

Work-around for namespaced keywords with extend:
don't use namespaced keywords

Work-around for syntax-quoting with extend-type or extend-protocol:
use extend with non-namespaced keywords

Possible solutions:

  1. Inside extend, remove namespace of keywords
  2. or
    • Inside extend, error on namespaced keywords.
    • Inside emit-hinted-impl, only grab name portion of symbols before converting to keyword.

Activity

Hide
Alexander Taggart added a comment -

Simple test case to see the issue.

=> (defprotocol P
     (self [p]))
P
=> (extend String
     P
     {::self identity})
nil
=> (self "foo")
#<IllegalArgumentException java.lang.IllegalArgumentException: No implementation of method: :self of protocol: #'user/P found for class: java.lang.String>
=> (defmacro try-extend-type [c]
     `(extend-type String
        P
        (self [p#] p#)))
#'user/try-extend-type
=> (try-extend-type String)
nil
=> (self "foo")
#<IllegalArgumentException java.lang.IllegalArgumentException: No implementation of method: :self of protocol: #'user/P found for class: java.lang.String>
=> (keys (get-in P [:impls String]))
(:user/self)
Show
Alexander Taggart added a comment - Simple test case to see the issue.
=> (defprotocol P
     (self [p]))
P
=> (extend String
     P
     {::self identity})
nil
=> (self "foo")
#<IllegalArgumentException java.lang.IllegalArgumentException: No implementation of method: :self of protocol: #'user/P found for class: java.lang.String>
=> (defmacro try-extend-type [c]
     `(extend-type String
        P
        (self [p#] p#)))
#'user/try-extend-type
=> (try-extend-type String)
nil
=> (self "foo")
#<IllegalArgumentException java.lang.IllegalArgumentException: No implementation of method: :self of protocol: #'user/P found for class: java.lang.String>
=> (keys (get-in P [:impls String]))
(:user/self)
Fogus made changes -
Field Original Value New Value
Fix Version/s Release 1.4 [ 10040 ]
Hide
Rich Hickey added a comment -

Most of this is a non-issue. :self and :foo/self are not the same.

This:

"Inside emit-hinted-impl, only grab name portion of symbols before converting to keyword."

is the only needed change.

Show
Rich Hickey added a comment - Most of this is a non-issue. :self and :foo/self are not the same. This: "Inside emit-hinted-impl, only grab name portion of symbols before converting to keyword." is the only needed change.
Alexander Taggart made changes -
Assignee Alexander Taggart [ ataggart ]
Alexander Taggart made changes -
Status Open [ 1 ] In Progress [ 3 ]
Alexander Taggart made changes -
Attachment clj-845-1.patch [ 10377 ]
Patch Code and Test
Alexander Taggart made changes -
Approval Test
Alexander Taggart made changes -
Status In Progress [ 3 ] Open [ 1 ]
Hide
Stuart Sierra added a comment -

Screened.

Show
Stuart Sierra added a comment - Screened.
Stuart Sierra made changes -
Approval Test [ 10013 ] Screened [ 10004 ]
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Sierra made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Stuart Halloway made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: