funcdef inside shared interface; "interface already implement" warning

Started by
13 comments, last by WitchLord 11 years, 1 month ago

1st thing--


// module 1
funcdef void Func();

shared interface ielement
{
    Func@ f { get; set; }
}

// module 2
funcdef void Func();

shared interface ielement
{
    Func@ f { get; set; }
}

class celement : ielement
{
    Func@ fdef;

    Func@ get_f()
    {
       return( this.fdef ); 
    }
    void set_f( Func@ newF )
    {
       @this.fdef = newF;
    }
}

Used that way, makes "Missing implementation of ..." error for both, getter and setter. So i tried to use "normal" functions.


// module 1
 
funcdef void Func();

shared interface ielement
{
     Func@ fGet();
     void fSet( Func@ );
}

// module 2

funcdef void Func();

shared interface ielement
{
    Func@ fGet();
    void fSet( Func@ );
}

class celement : ielement
{
    Func@ fdef;

    Func@ fGet()
    {
       return( this.fdef ); 
    }

    void fSet( Func@ newF )
    {
       @this.fdef = newF;
    }
}

Error changed to " Shared type 'ielement' doesn't match the original declaration in other module"

----

2nd thing--


shared interface ielement
{
   void dummy1();
}

shared interface isprite : ielement
{
    void dummy2();
}

class celement : ielement
{
   void dummy1() {}
}

class csprite : celement, isprite
{
    csprite()
    {
        super();
    }

    void dummy2() {}
}

Makes warning "The interface 'ielement' is already implemented" - is that possible to make this warning go away? smile.png

EDIT: everything was tested with r1563

Games are meant to be created, not played...

Advertisement

Makes warning "The interface 'ielement' is already implemented" - is that possible to make this warning go away?

I am wondering why this warning is even needed. We have:

1. Multiple inheritance for interfaces, i.e. abstract classes.

2. Single inheritance for regular classes.

3. All inheritance is virtual anyway.

This is a nice setup, and we can't ever suffer from the diamond problem. However,

4. It's impossible to decouple class declaration from its implementation (notwithstanding the shared keyword).

Because of 4. it's still reasonable to create otherwise superfluous interfaces, if only to make script headers more readable. For now I don't see a reason to report that an interface is already implemented as it manifests itself in typical and practical situations. But maybe I don't see the entire picture (how do mixin classes come into this?).

edit: this might be interesting:


interface I
{
    void f();
}

interface J : I
{
}

mixin class M1 : I
{
    void f() { x = 1; }
};

mixin class M2 : I
{
    void f() { x = 2; }
};

class T : M1, M2
{
    X() { x = 0; }
    int x;
};

This does not generate any warning, but it does if I change "mixin class M : I" to "mixin class M : J". But in both cases T inherits I along two paths.

edit2: Another issue:


mixin class M1
{
    void f() { x = 1; }
};

mixin class M2
{
    void f() { x = 2; }
};

class T : M1, M2
{
    T() { x = 0; }
    void g()
    {
        f(); // cannot use qualified names: M1::f() or M2::f()
    }
    int x;
};

There is no warning that T inherits f() twice (but g() calls f() in M1, the closest base class, I assume this is correct) and maybe this actually should warrant a warning, since it's actually a real function being inherited, not just an an interface method. Especially since there appers to be no way to explicitly call f() from the other base class, M2 (is this at all intended?).

I'll look into the problems reported.

As for mixin classes; they are not really inherited. When including a mixin class only the parts that are not already in the class will be included, for example, if the class already has a property that is also in the mixin class, the version from the mixin class won't be included again. The same goes for methods and implemented interfaces.

You can think of mixin classes as macros for providing default implementations.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

All problems reported should now be fixed in revision 1573.

Thanks,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hm, looks like there are still problems when loading from bytecode (shared type doesn't match the original declaration).

Games are meant to be created, not played...

That's strange. I fixed that too yesterday. Loading from bytecode had the same problem as compiling the script in the first place, in that the funcdef didn't get the same type in both modules.

What script is failing to load from bytecode? I'll have to do some further investigation on it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Two modules with same code; both need to be loaded from bytecode or error won't show up.

funcdef void fdef();

shared interface iface
{
	fdef@ dummy();
}

Games are meant to be created, not played...

Thanks. I'll investigate it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

You were right (of course). My previous test didn't catch this problem because I loaded the bytecode right after having compiled the script from source. Only when loading the bytecode into a fresh engine did the problem appear.

The bug was a bit more complex than I had imagined, but it should now be fixed in revision 1574.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Another dark secrets of funcdefs found, sorry! ;) We call start() function and expect to reach end().

Let's start from crash in cfuncdef1_1::crashme().
[spoiler]
funcdef void funcdef1( ifuncdef1_1& i );

shared interface ifuncdef1_1
{
    ifuncdef1_2@ events { get; set; }
    void crashme();
}

shared interface ifuncdef1_2
{
    funcdef1@ f { get; set; }
}

class cfuncdef1_1 : ifuncdef1_1
{
    ifuncdef1_2@ _events_;

    cfuncdef1_1() { @this._events_ = cfuncdef1_2(); }

    ifuncdef1_2@ get_events() { return( this._events_ ); }
    void set_events( ifuncdef1_2@ events ) { @this._events_ = events; }

    void crashme()
    {
         if( @this._events_ != null && @this._events_.f != null )
            this.events.f( this );

    }
}

class cfuncdef1_2 : ifuncdef1_2
{
    funcdef1@ ff;

    cfuncdef1_2() { @ff = null; }

    funcdef1@ get_f() { return( @this.ff ); }
    void set_f( funcdef1@ _f ) { @this.ff = _f; }
}

void start()
{
    ifuncdef1_1@ i = cfuncdef1_1();
    i.events.f = end;
    i.crashme();
}

void end( ifuncdef1_1& i  )
{
    Log( "you win!" );
}
[/spoiler]

If we change crashme() a bit, everything looks like it works without any problems (we can reach end()), but generated bytecode cannot be loaded (LoadByteCode() returns -1).
    void crashme()
    {
        if( @this._events_ != null && @this._events_.f != null )
        {
            funcdef1@ crash = this.events.f;
            crash( this );
        }
    }

And finally, different edit makes "GC cannot free an object of type '_builtin_function_', it is kept alive by the application." error show up.
cfuncdef1_1() { @this._events_ = null; }

Games are meant to be created, not played...

This topic is closed to new replies.

Advertisement