mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Made contracts aggregate from types etc
This commit is contained in:
@@ -1,26 +1,30 @@
|
||||
module mylib::ifaces;
|
||||
interface IOp {
|
||||
fn void op();
|
||||
interface IOp
|
||||
{
|
||||
fn void op();
|
||||
}
|
||||
module mylib{Type};
|
||||
import std::io;
|
||||
import mylib::ifaces;
|
||||
struct Op (IOp){
|
||||
Type data;
|
||||
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();
|
||||
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();
|
||||
// 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);
|
||||
fn void main(String[] args)
|
||||
{
|
||||
Op{int}* t = mem::new(Op{int}, {.data = 1});
|
||||
test(&t);
|
||||
}
|
||||
|
||||
13
test/test_suite/generic/generic_contract_aggregation.c3
Normal file
13
test/test_suite/generic/generic_contract_aggregation.c3
Normal file
@@ -0,0 +1,13 @@
|
||||
import std::io;
|
||||
|
||||
<* @require Type.kindof == SIGNED_INT *>
|
||||
struct Foo @generic(Type)
|
||||
{
|
||||
Type a;
|
||||
}
|
||||
|
||||
fn int main()
|
||||
{
|
||||
Foo{double} d; // #error: Parameter(s) failed validation: @require "Type.kindof == SIGNED_INT"
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user