mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 18:02:02 +00:00
Update demo.odin
This commit is contained in:
@@ -1095,7 +1095,7 @@ inline_for_statement :: proc() {
|
||||
}
|
||||
}
|
||||
|
||||
procedure_where_clauses :: proc() {
|
||||
where_clauses :: proc() {
|
||||
fmt.println("\n#procedure 'where' clauses");
|
||||
|
||||
{ // Sanity checks
|
||||
@@ -1156,6 +1156,20 @@ procedure_where_clauses :: proc() {
|
||||
assert(ok_x == true);
|
||||
assert(ok_y == false);
|
||||
}
|
||||
|
||||
{ // Record types
|
||||
Foo :: struct(T: typeid, N: int)
|
||||
where intrinsics.type_is_integer(T),
|
||||
N > 2 {
|
||||
x: [N]T,
|
||||
y: [N-2]T,
|
||||
}
|
||||
|
||||
T :: i32;
|
||||
N :: 5;
|
||||
f: Foo(T, N);
|
||||
#assert(size_of(f) == (N+N-2)*size_of(T));
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
@@ -1179,6 +1193,6 @@ main :: proc() {
|
||||
reflection();
|
||||
quaternions();
|
||||
inline_for_statement();
|
||||
procedure_where_clauses();
|
||||
where_clauses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array<
|
||||
struct_type->Struct.is_poly_specialized = is_poly_specialized;
|
||||
|
||||
if (!is_polymorphic) {
|
||||
if (st->where_clauses.count > 0 && st->polymorphic_params != nullptr) {
|
||||
if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) {
|
||||
error(st->where_clauses[0], "'where' clauses can only be used on structures with polymorphic parameters");
|
||||
} else {
|
||||
bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &st->where_clauses, true);
|
||||
@@ -690,7 +690,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op
|
||||
union_type->Union.is_polymorphic = is_polymorphic;
|
||||
union_type->Union.is_poly_specialized = is_poly_specialized;
|
||||
|
||||
if (ut->where_clauses.count > 0 && ut->polymorphic_params != nullptr) {
|
||||
if (ut->where_clauses.count > 0 && ut->polymorphic_params == nullptr) {
|
||||
error(ut->where_clauses[0], "'where' clauses can only be used on unions with polymorphic parameters");
|
||||
} else {
|
||||
bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &ut->where_clauses, true);
|
||||
|
||||
Reference in New Issue
Block a user