From 44a49755047720bc73176a83f19b348d341d6b68 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Thu, 1 May 2025 14:12:35 +0800 Subject: [PATCH] type_resolver: i32 is now `$int` too (fix #24346) (#24378) --- vlib/v/tests/comptime/comptime_if_is_test.v | 7 +++++++ vlib/v/type_resolver/comptime_resolver.v | 2 +- vlib/x/json2/encoder.v | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vlib/v/tests/comptime/comptime_if_is_test.v b/vlib/v/tests/comptime/comptime_if_is_test.v index aae291cfa..48767d06f 100644 --- a/vlib/v/tests/comptime/comptime_if_is_test.v +++ b/vlib/v/tests/comptime/comptime_if_is_test.v @@ -26,3 +26,10 @@ fn test_is_or() { assert g(i8(1)) == 1 assert g(1) == 2 } + +fn test_i32_is_int() { + a := i32(33) + $if a !is $int { + assert false + } +} diff --git a/vlib/v/type_resolver/comptime_resolver.v b/vlib/v/type_resolver/comptime_resolver.v index af37d42c2..9792209c6 100644 --- a/vlib/v/type_resolver/comptime_resolver.v +++ b/vlib/v/type_resolver/comptime_resolver.v @@ -250,7 +250,7 @@ pub fn (t &TypeResolver) is_comptime_type(x ast.Type, y ast.ComptimeType) bool { return x_kind == .string } .int { - return x_kind in [.i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .usize, .isize, + return x_kind in [.i8, .i16, .i32, .int, .i64, .u8, .u16, .u32, .u64, .usize, .isize, .int_literal] } .float { diff --git a/vlib/x/json2/encoder.v b/vlib/x/json2/encoder.v index cf617af13..b270f87c0 100644 --- a/vlib/x/json2/encoder.v +++ b/vlib/x/json2/encoder.v @@ -186,8 +186,7 @@ fn (e &Encoder) encode_value_with_level[T](val T, level int, mut buf []u8) ! { } $else $if T is $enum { str_int := int(val).str() unsafe { buf.push_many(str_int.str, str_int.len) } - } $else $if T is $int || T is bool || T is i32 { - // bug? `i32` not in `$int`? + } $else $if T is $int || T is bool { str_int := val.str() unsafe { buf.push_many(str_int.str, str_int.len) } } $else $if T is $float { -- 2.39.5