<< Back to previous view

[CLJS-610] Duplicate protocols in defrecord are silently ignored Created: 06/Oct/13  Updated: 02/Dec/14  Resolved: 02/Dec/14

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Russell Mull Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None

Clojurescript 1913

Attachments: File duplicate-protocols-20131015.diff    


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]
  (-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.

Comment by Travis Thieman [ 15/Oct/13 3:51 PM ]

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.

Comment by David Nolen [ 28/Oct/13 8:51 AM ]

CLJS-636 needs to be addressed first.

Comment by David Nolen [ 02/Dec/14 6:13 AM ]

fixed in master

Generated at Thu Sep 21 02:07:53 CDT 2017 using JIRA 4.4#649-r158309.