Clojure

instance? fails on deftype instance, when used from multiple files

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

Description

When instance? is called from two separate namespaces to test an instance of a user defined type, one of them fails

In the attached project, the following (identical) tests run correctly:

lein test instance-test.test.core
lein test instance-test.test.core2

but this fails:

lein test

For ease of reference, the attached project contains the following:

(ns instance-test.core)
(deftype MyType [a])
(defn make-my-type
[]
(MyType. nil))

(ns instance-test.test.core
(:use [instance-test.core] :reload-all)
(:use [clojure.test])
(:import instance-test.core.MyType))

(deftest test1
(is (instance? instance-test.core.MyType (make-my-type))))

(ns instance-test.test.core2
(:use [instance-test.core] :reload-all)
(:use [clojure.test])
(:import instance-test.core.MyType))

(deftest test1
(is (instance? instance-test.core.MyType (make-my-type))))

Activity

Hide
Assembla Importer added a comment -

hugoduncan said: Removing :reload-all from the tests, causes the unexpected behaviour to disappear

Show
Assembla Importer added a comment - hugoduncan said: Removing :reload-all from the tests, causes the unexpected behaviour to disappear
Hide
Stuart Sierra added a comment -

I can confirm the described behavior with Clojure 1.2.0 and Leiningen 1.3.1.

But it shouldn't work at all, because "instance-test.core" is not a valid Java package name. This was fixed in CLJ-432.

With Clojure 1.3.0-alpha5, MyType's package name is correctly munged to "instance_test.core". Loading the test namespaces fails (as it should) with java.lang.ClassNotFoundException: instance-test.core.MyType.

Show
Stuart Sierra added a comment - I can confirm the described behavior with Clojure 1.2.0 and Leiningen 1.3.1. But it shouldn't work at all, because "instance-test.core" is not a valid Java package name. This was fixed in CLJ-432. With Clojure 1.3.0-alpha5, MyType's package name is correctly munged to "instance_test.core". Loading the test namespaces fails (as it should) with java.lang.ClassNotFoundException: instance-test.core.MyType.

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: