mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- 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:
26
test/test_suite/any/casting_voidptr_to_any.c3
Normal file
26
test/test_suite/any/casting_voidptr_to_any.c3
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user