- Disallow casting a void* to any or an interface, unless it is null.

- Defer resolution of declarations when looked up in `def` aliased #1559.
This commit is contained in:
Christoffer Lerno
2024-10-16 12:50:47 +02:00
parent 4445b6c054
commit 705856d51a
7 changed files with 54 additions and 14 deletions

View File

@@ -0,0 +1,26 @@
module mylib::ifaces;
interface IOp {
fn void op();
}
module mylib(<Type>);
import std::io;
import mylib::ifaces;
struct Op (IOp){
Type data;
}
fn void Op.op(&self) @dynamic => io::printn("op");
module myapp;
import mylib;
fn void test(void* tptr){
// this work
IOp iop = (Op(<int>)*)tptr;
iop.op();
// this don't work
iop = tptr; // #error: Casting a 'void*' to 'IOp' is not permitted
iop.op();
}
fn void! main(String[] args) {
Op(<int>)* t = mem::new(Op(<int>), {.data = 1});
test(&t);
}

View File

@@ -5,14 +5,8 @@ fn void any_compare()
int x;
any a = &x;
any b = &x;
void* v = &x;
any c = v;
assert(a == b);
assert(a == a);
assert(a.ptr == c.ptr);
assert(a != c);
bool aisc = a == c;
assert(!aisc);
}
def AnyAlias = any;