Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created June 13, 2010 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swannodette/437046 to your computer and use it in GitHub Desktop.
Save swannodette/437046 to your computer and use it in GitHub Desktop.
(ns prim-this-bug)
(set! *warn-on-reflection* true)
(defprotocol VecMath
(add [this other])
(sub [this other]))
(defrecord Point [^double x ^double y]
VecMath
(add [this other] (let [^Point other other]
(Point. (+ x (.x other)) (+ y (.y other)))))
(sub [this other] (let [^Point other other]
(Point. (- x (.x other)) (- y (.y other))))))
(defn ^:static bugfn ^double [p1 p2]
(let [v (sub p1 p2)]
(+ (:x v) (:y v))))
;; error: java.lang.RuntimeException: java.lang.IllegalStateException: no 'this' pointer within static method (prim_this_bug.clj:16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment