Clojure

Compiler loses 'loop's return type in some cases

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Backlog
  • Fix Version/s: Release 1.8
  • Component/s: None
  • Labels:
    None
  • Environment:
    Clojure commit 9052ca1854b7b6202dba21fe2a45183a4534c501, version 1.3.0-master-SNAPSHOT
  • Patch:
    Code
  • Approval:
    Vetted

Description

(set! *warn-on-reflection* true)
(fn [] (loop [b 0] (recur (loop [a 1] a))))

Generates the following warnings:

recur arg for primitive local: b is not matching primitive, had: Object, needed: long
Auto-boxing loop arg: b

This is interesting for several reasons. For one, if the arg to recur is a let form, there is no warning:

(fn [] (loop [b 0] (recur (let [a 1] a))))

Also, the compiler appears to understand the return type of loop forms just fine:

(use '[clojure.contrib.repl-utils :only [expression-info]])
(expression-info '(loop [a 1] a))
;=> {:class long, :primitive? true}

The problem can of course be worked around using an explicit cast on the loop form:

(fn [] (loop [b 0] (recur (long (loop [a 1] a)))))

Reported by leafw in IRC: http://clojure-log.n01se.net/date/2011-01-03.html#10:31

  1. hoistedmethod-pass-1.diff
    22/Jul/14 8:39 PM
    22 kB
    Kevin Downey
  2. hoistedmethod-pass-2.diff
    23/Jul/14 12:43 AM
    24 kB
    Kevin Downey
  3. hoistedmethod-pass-3.diff
    25/Jul/14 7:08 PM
    24 kB
    Kevin Downey
  4. hoistedmethod-pass-4.diff
    26/Jul/14 12:52 PM
    29 kB
    Kevin Downey
  5. hoistedmethod-pass-5.diff
    26/Jul/14 12:58 PM
    29 kB
    Kevin Downey

Activity

People

  • Assignee:
    Unassigned
    Reporter:
    Chouser
Vote (1)
Watch (6)

Dates

  • Created:
    Updated: