Skip to content

Instantly share code, notes, and snippets.

@txus
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save txus/c1e7df080f51224ab52b to your computer and use it in GitHub Desktop.
Save txus/c1e7df080f51224ab52b to your computer and use it in GitHub Desktop.
Core Typed interop
(ns typed.core
(:require [clojure.core.typed :as t]))
(t/ann-datatype Foo [fooName :- t/Str])
(deftype Foo [fooName])
(t/ann-datatype Bar [barName :- t/Str])
(deftype Bar [barName])
(t/ann theName [(t/U Foo Bar) -> t/Str])
(defmulti theName class)
(defmethod theName Foo [f] (.fooName f))
(defmethod theName Bar [f] (.barName f))
(t/check-ns)
@txus
Copy link
Author

txus commented Apr 26, 2015

   Type Checker: Found 2 errors
   {:type-error :top-level-error,
    :errors
    (#<ExceptionInfo clojure.lang.ExceptionInfo: Unresolved host interop: fooName

   Hint: use *warn-on-reflection* to identify reflective calls

   in: (.fooName f) {:env {:file "typed/core.clj", :column 28, :line 12}, :form (.fooName f), :type-error :clojure.core.typed.errors/tc-error-parent}>
     #<ExceptionInfo clojure.lang.ExceptionInfo: Unresolved host interop: barName

   Hint: use *warn-on-reflection* to identify reflective calls

   in: (.barName f) {:env {:file "typed/core.clj", :column 28, :line 13}, :form (.barName f), :type-error :clojure.core.typed.errors/tc-error-parent}>)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment