Uploaded image for project: 'Clojure'
  1. CLJ-760

ClassNotFound when AOT compiling a self-referring deftype extended to a protocol

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not Reproducible
    • Affects versions: Release 1.2
    • Fix versions: None
    • Labels:
    • Environment:

      Clojure 1.2.0, 1.2.1, 1.3.0-alpha6, JDK 1.6.0_24, Ubuntu 10.10

      Description

      If I create a deftype that refers to itself in a protocol extension like below:

      (ns type-test)
      
      (defprotocol Foo
        (isa-foo [x]))
      
      (deftype TypeTest []
        Foo
        (isa-foo [x]
                 (instance? TypeTest x)))
      

      And use that code via another namespace:

      (ns test-type-user
        (:use [type-test :only (isa-foo)])
        (:import [type-test TypeTest]))
      
      (isa-foo (TypeTest.))
      

      When I try to AOT compile the test-type-user namespace with Clojure 1.2.0, I get java.lang.NoClassDefFoundError: compilestub/type-test/TypeTest (test_type_user.clj:5). Full stack trace attached. Running the same code on 1.2.1 and 1.3.0-alpha6 yielded the same exception with a slightly different error message (stacktrace for 1.2.1 is also in the attached file).

      This came up in a test at Revelytix. We worked around this issue by not using instance? and instead comparing based on class name. Another workaround is to define the deftype and the extension separately (using extend-type or something similar). This problem also doesn't occur if the usage of the deftype and the definition of it are in the same namespace (i.e. if type-test and test-type-user were in the same file).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ryansenior Ryan Senior
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: