ClojureCLR

Reifying properties does not work when called from Clojure

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows 7 x64, Clojure CLR 1.6.0

Description

When implementing an interface with reify there seems to be a problem when trying to access the reifyed property from Clojure. Here's how to reproduce:

(def o 
  (reify IAsyncResult
    (get_AsyncState [_]
             (println "hello"))))

(.AsyncState o)

causes

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocatio
n. ---> System.MissingMethodException: Cannot find instance field/property/member name AsyncState

Using

(.get_AsyncState o)
works, though.

Note that using interface System.IAsyncState in the example is arbitrary, I just chose some platform interface with properties.

Activity

Hide
Antti Karanta added a comment -

I have previously used reify to implement interfaces and passed those objects to C# code where the properties have been successfully accessed so the problem seems to occur just when trying to access the property from Clojure.

Show
Antti Karanta added a comment - I have previously used reify to implement interfaces and passed those objects to C# code where the properties have been successfully accessed so the problem seems to occur just when trying to access the property from Clojure.
Hide
David Miller added a comment -

Type hinting allows the property to be accessed. Without type-hinting, equivalent to working with dynamic in C#, a callsite is generated. This callsite does not work with properties – same as C#.

More info at http://clojureclr.blogspot.com/2014/10/reflecting-properties.html

If you have another example, I'd like to see it.

Show
David Miller added a comment - Type hinting allows the property to be accessed. Without type-hinting, equivalent to working with dynamic in C#, a callsite is generated. This callsite does not work with properties – same as C#. More info at http://clojureclr.blogspot.com/2014/10/reflecting-properties.html If you have another example, I'd like to see it.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: