<< Back to previous view

[CTYP-91] polymorphic ann-protocol doesn't work Created: 30/Oct/13  Updated: 05/Nov/13  Resolved: 05/Nov/13

Status: Resolved
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Russell Mull Assignee: Ambrose Bonnaire-Sergeant
Resolution: Completed Votes: 0
Labels: None
Environment:

Clojure 1.5.1, Core.typed 0.2.14 and 0.2.15



 Description   

The example of a polymorphic defprotocol annotation from the documentation is:

(ann-protocol [[x :variance :covariant]]
  IFoo
  bar
  [IFoo -> Any]
  baz
  [IFoo -> Number])

It's implied that there exists a corresponding protocol like this:

(defprotocol> IFoo
  (bar [this])
  (baz [this]))

Type checking this code with check-ns gives an error:

AssertionError Assert failed: ((u/hash-c? (every-pred symbol? (complement namespace)) Type?) methods)
	clojure.core.typed.type-rep/Protocol-maker (type_rep.clj:289)
	clojure.core.typed.type-ctors/Protocol* (type_ctors.clj:448)
	clojure.core.typed.collect-phase/gen-protocol* (collect_phase.clj:443)
	clojure.core.typed.collect-phase/fn--14235 (collect_phase.clj:458)
	clojure.lang.MultiFn.invoke (MultiFn.java:227)
	clojure.core.typed.collect-phase/collect -COLON-invoke14011 (collect_phase.clj:189)
	clojure.lang.MultiFn.invoke (MultiFn.java:227)
	clojure.core.typed.collect-phase/collect-asts (collect_phase.clj:119)
	clojure.core.typed.collect-phase/collect-ns (collect_phase.clj:107)
	clojure.core.typed/check-ns (typed.clj:1459)
	clojure.core.typed/check-ns (typed.clj:1429)

Incidentally, it would be nice if the example in the documentation actually used the declared type parameter in some way.



 Comments   
Comment by Russell Mull [ 30/Oct/13 10:01 PM ]

The above stack trace is from 0.2.14. This is the trace for 0.2.15:

AssertionError Assert failed: ((u/hash-c? (every-pred symbol? (complement namespace)) Type?) methods)
	clojure.core.typed.type-rep/Protocol-maker (type_rep.clj:289)
	clojure.core.typed.type-ctors/Protocol* (type_ctors.clj:448)
	clojure.core.typed.collect-phase/gen-protocol* (collect_phase.clj:443)
	clojure.core.typed.collect-phase/fn--14237 (collect_phase.clj:458)
	clojure.lang.MultiFn.invoke (MultiFn.java:227)
	clojure.core.typed.collect-phase/collect -COLON-invoke14013 (collect_phase.clj:189)
	clojure.lang.MultiFn.invoke (MultiFn.java:227)
	clojure.core.typed.collect-phase/collect-asts (collect_phase.clj:119)
	clojure.core.typed.collect-phase/collect-ns (collect_phase.clj:107)
	clojure.core.typed/check-ns (typed.clj:1459)
	clojure.core.typed/check-ns (typed.clj:1429)
Comment by Ambrose Bonnaire-Sergeant [ 05/Nov/13 9:52 AM ]

This exposes that polymorphic protocols are completely untested :/

This issue is fixed in 0.2.16: https://github.com/clojure/core.typed/commit/4474f76eea1e966523914c5455761f1e7b8542c8

Also updated the doc: https://github.com/clojure/core.typed/commit/216454c8c292d68dfa1ac1cd5ce36e00f43cc1c8

This doesn't mean polymorphic protocols/datatypes are usable yet, but it's progress. Working on it.

Generated at Fri Oct 24 04:58:57 CDT 2014 using JIRA 4.4#649-r158309.