Browse Source

Merge pull request #1334 from jockus/allow-enum-any-int

Allow enums to pass #any_int checks
gingerBill 3 years ago
parent
commit
44897b5eac
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/check_type.cpp

+ 3 - 3
src/check_type.cpp

@@ -1564,7 +1564,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
 					p->flags &= ~FieldFlag_const;
 					p->flags &= ~FieldFlag_const;
 				}
 				}
 				if (p->flags&FieldFlag_any_int) {
 				if (p->flags&FieldFlag_any_int) {
-					error(name, "'#const' can only be applied to variable fields");
+					error(name, "'#any_int' can only be applied to variable fields");
 					p->flags &= ~FieldFlag_any_int;
 					p->flags &= ~FieldFlag_any_int;
 				}
 				}
 
 
@@ -1614,7 +1614,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
 								ok = false;
 								ok = false;
 							}
 							}
 						} else if (p->flags&FieldFlag_any_int) {
 						} else if (p->flags&FieldFlag_any_int) {
-							if (!is_type_integer(op.type) || !is_type_integer(type)) {
+							if ((!is_type_integer(op.type) && !is_type_enum(op.type)) || (!is_type_integer(type) && !is_type_enum(type))) {
 								ok = false;
 								ok = false;
 							} else if (!check_is_castable_to(ctx, &op, type)) {
 							} else if (!check_is_castable_to(ctx, &op, type)) {
 								ok = false;
 								ok = false;
@@ -1684,7 +1684,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
 				param->flags |= EntityFlag_AutoCast;
 				param->flags |= EntityFlag_AutoCast;
 			}
 			}
 			if (p->flags&FieldFlag_any_int) {
 			if (p->flags&FieldFlag_any_int) {
-				if (!is_type_integer(param->type)) {
+				if (!is_type_integer(param->type) && !is_type_enum(param->type)) {
 					gbString str = type_to_string(param->type);
 					gbString str = type_to_string(param->type);
 					error(name, "A parameter with '#any_int' must be an integer, got %s", str);
 					error(name, "A parameter with '#any_int' must be an integer, got %s", str);
 					gb_string_free(str);
 					gb_string_free(str);