diff options
| author | gingerBill <bill@gingerbill.org> | 2019-09-08 19:03:57 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-09-08 19:03:57 +0100 |
| commit | 42bbd31df143d49340f289326f949ad524a3a70e (patch) | |
| tree | 2c2f8d2f36fa965377036f69c4314f71c18cd729 /src/check_type.cpp | |
| parent | c7cc38b7d8894578e7158e8e092531c7ec71f815 (diff) | |
Disallow `where` clauses on non-polymorphic records
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index fe9e6f817..f2d42cfe1 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -503,7 +503,11 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array< struct_type->Struct.is_poly_specialized = is_poly_specialized; if (!is_polymorphic) { - bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &st->where_clauses, true); + 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); + } check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context); } @@ -686,7 +690,11 @@ 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; - bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &ut->where_clauses, true); + 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); + } for_array(i, ut->variants) { |