Clojure

protocol fns with dashes may get compiled into property access when used higher order

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Problem: Protocol functions with leading hyphens may be incorrectly compiled into field accesses.

Demonstration:

(defprotocol Foo (-foo [x]))

(deftype Bar [] Foo (-foo [_] "foo"))

(map -foo (repeatedly 3 ->Bar))
;; IllegalArgumentException No matching field found: foo for class user.Bar  
;; clojure.lang.Reflector.getInstanceField (Reflector.java:271)

Cause: This was caused by CLJ-872, dash property support.

Solution: Emit forms like (. foo (bar)) instead of (. foo bar), so that names starting with a - don't look like field accesses.

Patch: CLJ-1202.patch

Activity

Hide
Alan Malloy added a comment -

Attached patch fixes the issue, and adds regression test for it.

Show
Alan Malloy added a comment - Attached patch fixes the issue, and adds regression test for it.
Hide
Gabriel Horner added a comment -

Verified patch works

Show
Gabriel Horner added a comment - Verified patch works
Hide
Stuart Sierra added a comment -

Screened and cleaned up description.

Show
Stuart Sierra added a comment - Screened and cleaned up description.
Hide
Alex Miller added a comment -

More cleansing.

Show
Alex Miller added a comment - More cleansing.

People

Vote (0)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: