public
Last active

  • Download Gist
bounds_bug.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(ns typed-example.core
(:import (clojure.lang Symbol Seqable))
(:require [clojure.core.typed :refer [ann check-ns defprotocol> ann-datatype ann-protocol inst]]))
 
(ann-protocol Similar
is-similar? [Similar Any -> Boolean])
(defprotocol> Similar
(is-similar? [this a]))
 
(ann-datatype MyInt [x :- Number])
(deftype MyInt [x]
Similar
(is-similar? [this m]
(= x m)))
 
(ann find-similar (All [[t :< Similar]]
[t (U nil (Seqable t)) -> Boolean]))
(defn find-similar [a as]
(cond
(empty? as) false
(is-similar? a (first as)) true
:else ((inst find-similar t) a (next as))))
;AssertionError Assert failed: 22: Manually instantiated type t is not between bounds Nothing and typed-example.core/Similar
;(and (sub/subtype? ty upper-bound) (sub/subtype? lower-bound ty)) clojure.core.typed.inst/manual-inst (inst.clj:54)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.