Clojure

defprotocol should throw error when signatures include variable number of parameters

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.3
  • Fix Version/s: None
  • Component/s: None
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

I tried to use & in the signature for a method in defprotocol. Apparently (see below), this is compiled so that & becomes a simple parameter name, and there is no special handling for variable number of parameters. I think the use of & in a protocol signature ought to be detected and immediately cause an exception (I also think this restriction on the signatures ought to be documented; I couldn't find it specified in the current documentation, though of course it is implied (as I later realized) by the fact that defprotocol creates a Java interface).

user=> (defprotocol Applier (app [this f & args]))
Applier
user=> (deftype A [] Applier (app [_ f & args] (prn f & args) (apply f args)))
user.A
user=> (app (A.) + 1 2)
#<core$PLUS clojure.core$PLUS@5d9d0d20> 1 2
IllegalArgumentException Don't know how to create ISeq from: java.lang.Long
clojure.lang.RT.seqFrom (RT.java:487)

Activity

Alex Miller made changes -
Field Original Value New Value
Labels protocols
Alex Miller made changes -
Approval Triaged [ 10120 ]
Issue Type Enhancement [ 4 ] Defect [ 1 ]
Alex Miller made changes -
Labels protocols errormsgs protocols
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Coventry made changes -
Attachment 0002-Error-msg-for-variadic-syntax-in-defprotocol-sigs.patch [ 12352 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12355 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12356 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12355 ]
Tassilo Horn made changes -
Patch Code and Test [ 10002 ]
Alex Coventry made changes -
Attachment 0002-Error-msg-for-variadic-syntax-in-defprotocol-sigs.patch [ 12352 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12385 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12356 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12386 ]
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12385 ]
Tassilo Horn made changes -
Tassilo Horn made changes -
Attachment 0001-Forbid-vararg-declaration-in-defprotocol-definterfac.patch [ 12386 ]
Tassilo Horn made changes -
Assignee Tassilo Horn [ tsdh ]
Tassilo Horn made changes -
Assignee Tassilo Horn [ tsdh ] Stuart Halloway [ stu ]
Alex Miller made changes -
Issue Type Defect [ 1 ] Enhancement [ 4 ]

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated: