ClojureScript

Duplicate protocols in defrecord are silently ignored

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
  • Environment:
    Clojurescript 1913

Description

It is currently not an error to define a type with two implementations of the same protocol; which implementation is actually used appears to be arbitrary. This shouldn't be allowed, as it leads to mysterious misbehavior like the following:

(defrecord MyCountableThing [count]
  ICounted
  (-count [_] count))

Calling count on any instance of MyCountableThing will of course return 1, which is the the answer given by the default implementation of ICounted in the defrecord macro. I'm not arguing here that the above code should necessarily work; indeed the semantics of defrecord make it reasonable for it not to. But it should be an error rather than doing nothing.

Activity

David Nolen made changes -
Field Original Value New Value
Priority Major [ 3 ] Minor [ 4 ]
Hide
Travis Thieman added a comment - - edited

Patch: 20131015

Warns on duplicate protocols in defrecord and deftype invocations. This also found a few instances in cljs/cljs.core with duplicated code, which I removed.

Clojure allows this without an error and will allow one of the duplicated protocol definitions through to the record. It seemed more reasonable to throw a warning in this case so that valid code in Clojure will remain valid code in ClojureScript.

Show
Travis Thieman added a comment - - edited Patch: 20131015 Warns on duplicate protocols in defrecord and deftype invocations. This also found a few instances in cljs/cljs.core with duplicated code, which I removed. Clojure allows this without an error and will allow one of the duplicated protocol definitions through to the record. It seemed more reasonable to throw a warning in this case so that valid code in Clojure will remain valid code in ClojureScript.
Travis Thieman made changes -
Attachment duplicate-protocols-20131015.diff [ 12326 ]
Travis Thieman made changes -
Attachment duplicate-protocols-20131015.diff [ 12326 ]
Travis Thieman made changes -
Attachment duplicate-protocols-20131015.diff [ 12327 ]
Hide
David Nolen added a comment -

CLJS-636 needs to be addressed first.

Show
David Nolen added a comment - CLJS-636 needs to be addressed first.
Hide
David Nolen added a comment -

fixed in master

Show
David Nolen added a comment - fixed in master
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: