bcc
bcc copied to clipboard
Interface type parameters do not accept objects when using TMethod.Invoke
Bug Report
- Declare an
Interface
, e.g.Foo
- Declare a type conforming to
Foo
, e.g.FooImpl
- Passing an object of
FooImpl
to a function expecting a parameter of typeFoo
works, but using brl.reflection to pass the same object viaTMethod.Invoke
produces an error
Example code:
Interface AnInterface
End Interface
Type AType Implements AnInterface
End Type
Type AnEventListener
Method OnEventSent(source:AnInterface) ' use :AType or :Object to fix
Print("OnEvent")
End Method
End Type
Global listener:AnEventListener = New AnEventListener()
Function Fire(eventName:String, source:Object, payload:Object = Null)
Local callbackName:String = "On" + eventName
DebugLog("Firing " + eventName)
Local callback:TMethod = TTypeId.ForObject(listener).FindMethod(callbackName)
If callback
callback.Invoke(listener, [source]) ' Produces "ERROR" message during runtime
End If
End Function
Local obj:AType = New AType()
Fire("EventSent", obj)
Expected Behavior
The method is invoked and executed with the object available inside.
Actual Behavior
Alert with Unhandled Exception:ERROR
during runtime as long as the method parameter's type is the one of an interface. Works with concrete classes or Object
, though.
Environment
- Operating System: macOS 10.14
- Output of
bcc -v
: 0.99 release