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

Hints don't work with #() form of function

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: None
    • Fix versions: Release 1.7
    • Labels:
    • Approval:
      Ok
    • Patch:
      Code and Test

      Description

      Example showing how a local fn can be hinted but an anonymous function cannot:

      ;; OK
      user> (let [ex (java.util.concurrent.Executors/newFixedThreadPool 1)
                  f (fn [])]
              (.submit ex ^Runnable f))
      nil
      ;; ERROR - this should work the same as the previous
      user> (let [ex (java.util.concurrent.Executors/newFixedThreadPool 1)]
              (.submit ex #()))
      CompilerException java.lang.IllegalArgumentException: More than one matching method found: submit, compiling:(/private/var/folders/7r/_1fj0f517rgcxwx79mn79mfc0000gn/T/form-init7901279404687292754.clj:3:9) 
      

      Cause: Functions have metadata, but Compiler does not look in them for type hints. Var expressions and local bindings use :tag metadata to override return of getJavaClass(). Compiler parses #() into a FnExpr, which always return AFunction as its class.

      Proposed: Change FnExpr.getJavaClass() to return tag as type if it is available.

      Patch: clj-1378-v2.diff

      Screened by: Alex Miller

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: