aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-15 12:56:59 +0100
committergingerBill <bill@gingerbill.org>2021-08-15 12:56:59 +0100
commit7bbc9a4634c2a4f1f3d4e932571883dce55c21fd (patch)
tree5fd7a6224876544877c62d4a88725e756d13874b /src/check_type.cpp
parent1cd3b693aeb19a952c22e2aec69fd00025b99fc5 (diff)
Add `#any_int` directive to replace `auto_cast` uses on parameters.
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index ab3004320..d2a216c93 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -1526,6 +1526,10 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
error(name, "'#const' can only be applied to variable fields");
p->flags &= ~FieldFlag_const;
}
+ if (p->flags&FieldFlag_any_int) {
+ error(name, "'#const' can only be applied to variable fields");
+ p->flags &= ~FieldFlag_any_int;
+ }
param = alloc_entity_type_name(scope, name->Ident.token, type, EntityState_Resolved);
param->TypeName.is_type_alias = true;
@@ -1572,6 +1576,12 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
if (!check_is_castable_to(ctx, &op, type)) {
ok = false;
}
+ } else if (p->flags&FieldFlag_any_int) {
+ if (!is_type_integer(op.type) || !is_type_integer(type)) {
+ ok = false;
+ } else if (!check_is_castable_to(ctx, &op, type)) {
+ ok = false;
+ }
}
if (!ok) {
success = false;
@@ -1609,6 +1619,10 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
error(name, "'auto_cast' can only be applied to variable fields");
p->flags &= ~FieldFlag_auto_cast;
}
+ if (p->flags&FieldFlag_any_int) {
+ error(name, "'#any_int' can only be applied to variable fields");
+ p->flags &= ~FieldFlag_any_int;
+ }
if (p->flags&FieldFlag_const) {
error(name, "'#const' can only be applied to variable fields");
p->flags &= ~FieldFlag_const;
@@ -1632,6 +1646,14 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
if (p->flags&FieldFlag_auto_cast) {
param->flags |= EntityFlag_AutoCast;
}
+ if (p->flags&FieldFlag_any_int) {
+ if (!is_type_integer(param->type)) {
+ gbString str = type_to_string(param->type);
+ error(name, "A parameter with '#any_int' must be an integer, got %s", str);
+ gb_string_free(str);
+ }
+ param->flags |= EntityFlag_AnyInt;
+ }
if (p->flags&FieldFlag_const) {
param->flags |= EntityFlag_ConstInput;
}