Clojure

defprotocol: invalid method overload syntax getting accepted

Details

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

Description

The compiler accepts this erroneous form:

user=> (defprotocol Bar (m [this]) (m [this arg]))
Bar

Analysis: defprotocol silently assoc's the last list of signatures found for any particular method name, without checking whether the method name was given earlier.

Patch: clj-1056-2.diff

Approach: Modify defprotocol to check whether each method name has already been encountered earlier, and throw an exception if so. The patch also updates the error message for the case of a protocol function with no args specified.

Behavior with patch clj-1056-2.txt:

user=> (defprotocol Bar (m [this]) (m [this arg]))
IllegalArgumentException Function m in protocol Bar was redefined. Specify all arities in single definition.
user=> (defprotocol Foo (m []))
IllegalArgumentException Definition of function m in protocol Foo must take at least one arg.

Screened by: Stuart Halloway

  1. clj-1056-1.txt
    10/Sep/13 11:24 PM
    3 kB
    Andy Fingerhut
  2. clj-1056-2.diff
    22/Oct/13 9:14 AM
    3 kB
    Alex Miller
  3. clj-1056-2.txt
    18/Oct/13 11:08 AM
    3 kB
    Alex Miller

Activity

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: