Dechenjm / crack-language

Automatically exported from code.google.com/p/crack-language
Other
0 stars 0 forks source link

casting from an interface to its implementation is broken #117

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

import crack.io cout;
import crack.functor Functor0;

@import crack.ann implements;

class Foo : Object @implements Functor0[void] {
    void oper call() {
        cout `getting called\n`;
    }
}

Foo foo = {};
Functor0[void] f = foo;
cout `$(uintz(foo)) $(uintz(Foo.unsafeCast(f)))\n`;

We get two different addresses and a seg-fault.

Original issue reported on code.google.com by mind...@gmail.com on 9 Dec 2012 at 6:23

GoogleCodeExporter commented 9 years ago
As I suspected, this is actually a problem with any cast from a non-primary 
base class with an offset: "class A { int x; } class B {} class C : A, B {}  B 
b = C(); C.cast(b)" is also broken.

This turns out to be very difficult to fix for the unsafeCast() case.  I'm 
going to focus on fixing it in cast() and add an unsafeCast(X value, uintz 
offset) overload to facilitate the fix.  Users of unsafeCast() should continue 
to reflect on their reasons for using it. 

Original comment by mmul...@google.com on 14 Dec 2012 at 2:17