assigning value to function typed field via interface

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

assigning value to function typed field via interface

alexbor
Hi.

An error occures when trying to compile code assigning function to function typed field using interface typed link (see example below). The following example crashes when compiling for cpp but works fine in flash.

package ;

class Main
{
        static function main()
        {
                new Main();
        }
       
        function new()
        {
                var i:MyInterface = new MyClass();
                i.handler = handle;
                i.handler();
        }
        function handle():Void
        {
                trace('success');
        }
}

interface MyInterface
{
        var handler:Void->Void;
}

class MyClass implements MyInterface
{
        public function new() { }
        public var handler:Void->Void;
}

The same logic is used in Robothaxe (haxe port of Robotlegs), that's how the error was found.
Does anyone knows what is wrong with this code?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: assigning value to function typed field via interface

Julien CASTETS

You don't have to re declare handler in MyClass. Interface fields are always public. I guess.

Best
Julien

Le 8 sept. 2011 12:36, "alexbor" <[hidden email]> a écrit :
> Hi.
>
> An error occures when trying to compile code assigning function to function
> typed field using interface typed link (see example below). The following
> example crashes when compiling for cpp but works fine in flash.
>
> package ;
>
> class Main
> {
> static function main()
> {

> new Main();
> }
>
> function new()
> {
> var i:MyInterface = new MyClass();
> i.handler = handle;
> i.handler();
> }
> function handle():Void
> {

> trace('success');
> }
> }
>
> interface MyInterface
> {
> var handler:Void->Void;
> }
>
> class MyClass implements MyInterface
> {
> public function new() { }
> public var handler:Void->Void;
> }
>
> The same logic is used in Robothaxe (haxe port of Robotlegs), that's how the
> error was found.
> Does anyone knows what is wrong with this code?
>
> Thanks.
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/assigning-value-to-function-typed-field-via-interface-tp6771220p6771220.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: assigning value to function typed field via interface

alexbor
If I comment out handler in MyClass compiler says that required field is missing, so I suppose fields defined in interface must be declared in implementing class.
Reply | Threaded
Open this post in threaded view
|

Re: assigning value to function typed field via interface

alexbor
In reply to this post by alexbor
The problem here is that this code can't be compiled by hxcpp, but it works fine when compiling into swf.

When targetting cpp compiler writes the following to console:


./src/Main.cpp(22) : error C2659: '=' : function as left operand
D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) : error C2664: 'null::null(const null &)' : cannot convert parameter 1 from 'Dynamic' to 'const null &'
        Reason: cannot convert from 'Dynamic' to 'const null'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) : while compiling class template member function 'Void MyInterface_delegate_<IMPL>::handler(void)'
        with
        [
            IMPL=MyClass_obj
        ]
        D:\Projects\_temporary\hxcpp-test\bin\include\MyClass.h(31) : see reference to class template instantiation 'MyInterface_delegate_<IMPL>' being compiled
        with
        [
            IMPL=MyClass_obj
        ]
Called from ? line 1
Called from BuildTool.hx line 1100
Called from BuildTool.hx line 501
Called from BuildTool.hx line 538
Called from BuildTool.hx line 657
Called from BuildTool.hx line 729
Uncaught exception - Error in building thread
D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) : error C2664: 'null::null(const null &)' : cannot convert parameter 1 from 'Dynamic' to 'const null &'
        Reason: cannot convert from 'Dynamic' to 'const null'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) : while compiling class template member function 'Void MyInterface_delegate_<IMPL>::handler(void)'
        with
        [
            IMPL=MyClass_obj
        ]
        D:\Projects\_temporary\hxcpp-test\bin\include\MyClass.h(31) : see reference to class template instantiation 'MyInterface_delegate_<IMPL>' being compiled
        with
        [
            IMPL=MyClass_obj
        ]
Error : Build failed
Build halted with errors (haxe.exe).
Reply | Threaded
Open this post in threaded view
|

Re: assigning value to function typed field via interface

Julien CASTETS

Sounds like you should post to the issue list then :-)
Maybe you could workaround with Dynamic :-(

Best
Julien

Le 8 sept. 2011 13:52, "alexbor" <[hidden email]> a écrit :
> The problem here is that this code can't be compiled by hxcpp, but it works
> fine when compiling into swf.
>
> When targetting cpp compiler writes the following to console:
>
>
> ./src/Main.cpp(22) : error C2659: '=' : function as left operand
> D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) : error
> C2664: 'null::null(const null &)' : cannot convert parameter 1 from
> 'Dynamic' to 'const null &'
> Reason: cannot convert from 'Dynamic' to 'const null'
> No user-defined-conversion operator available that can perform this
> conversion, or the operator cannot be called
> D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) :
> while compiling class template member function 'Void
> MyInterface_delegate_<IMPL>::handler(void)'
> with
> [
> IMPL=MyClass_obj
> ]
> D:\Projects\_temporary\hxcpp-test\bin\include\MyClass.h(31) : see
> reference to class template instantiation 'MyInterface_delegate_<IMPL>'
> being compiled
> with
> [
> IMPL=MyClass_obj
> ]
> Called from ? line 1
> Called from BuildTool.hx line 1100
> Called from BuildTool.hx line 501
> Called from BuildTool.hx line 538
> Called from BuildTool.hx line 657
> Called from BuildTool.hx line 729
> Uncaught exception - Error in building thread
> D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) : error
> C2664: 'null::null(const null &)' : cannot convert parameter 1 from
> 'Dynamic' to 'const null &'
> Reason: cannot convert from 'Dynamic' to 'const null'
> No user-defined-conversion operator available that can perform this
> conversion, or the operator cannot be called
> D:\Projects\_temporary\hxcpp-test\bin\include\MyInterface.h(33) :
> while compiling class template member function 'Void
> MyInterface_delegate_<IMPL>::handler(void)'
> with
> [
> IMPL=MyClass_obj
> ]
> D:\Projects\_temporary\hxcpp-test\bin\include\MyClass.h(31) : see
> reference to class template instantiation 'MyInterface_delegate_<IMPL>'
> being compiled

> with
> [
> IMPL=MyClass_obj
> ]
> Error : Build failed
> Build halted with errors (haxe.exe).
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/assigning-value-to-function-typed-field-via-interface-tp6771220p6771475.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: assigning value to function typed field via interface

alexbor
I created an issue report. :)