From 35f5acb2e3e1cd138cab279085aa2a8feabdcc3c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 2 Jan 2025 18:37:23 -0300 Subject: [PATCH] fix --- vlib/math/stats/stats_test.v | 7 +++---- vlib/v/gen/c/infix.v | 4 +++- vlib/v/type_resolver/type_resolver.v | 13 ++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/vlib/math/stats/stats_test.v b/vlib/math/stats/stats_test.v index ba8189695622cf..4472421714b12a 100644 --- a/vlib/math/stats/stats_test.v +++ b/vlib/math/stats/stats_test.v @@ -464,7 +464,6 @@ fn test_kurtosis() { fn test_skew() { mut data := [10.0, 4.45, 5.9, 2.7] mut o := stats.skew(data) - dump(o) assert math.alike(o, 0.5754021106320453) data = [-3.0, 67.31, 4.4, 1.89] o = stats.skew(data) @@ -485,13 +484,13 @@ fn test_quantile() { mut data := [2.7, 4.45, 5.9, 10.0] mut o := stats.quantile(data, 0.1)! - assert math.alike(o, 3.2249999046325684) + assert math.alike(o, 3.225) data = [-3.0, 1.89, 4.4, 67.31] o = stats.quantile(data, 0.2)! - assert math.alike(o, -0.06600001454353333) + assert math.alike(o, -0.06599999999999961) data = [7.88, 12.0, 54.83, 76.122] o = stats.quantile(data, 0.3)! - assert math.alike(o, 11.588000297546387) + assert math.alike(o, 11.588) stats.quantile(data, -0.3) or { assert err.msg() == 'index out of range' } diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index bb446e4ddea887..ad68ab8db72351 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -1188,8 +1188,10 @@ fn (mut g Gen) gen_plain_infix_expr(node ast.InfixExpr) { && node.op in [.plus, .minus, .mul, .div, .mod] && !(g.pref.translated || g.file.is_translated) if needs_cast { - typ_str := if g.comptime.is_comptime(node.left) { + typ_str := if !node.left.is_literal() && g.comptime.is_comptime(node.left) { g.styp(g.type_resolver.get_type_or_default(node.left, node.promoted_type)) + } else if !node.right.is_literal() && g.comptime.is_comptime(node.right) { + g.styp(g.type_resolver.get_type_or_default(node.right, node.promoted_type)) } else { g.styp(node.promoted_type) } diff --git a/vlib/v/type_resolver/type_resolver.v b/vlib/v/type_resolver/type_resolver.v index c74cc58f888ae3..0bdeb8b48d4bbf 100644 --- a/vlib/v/type_resolver/type_resolver.v +++ b/vlib/v/type_resolver/type_resolver.v @@ -115,9 +115,12 @@ pub fn (mut t TypeResolver) get_type_or_default(node ast.Expr, default_typ ast.T return t.get_type_or_default(node.expr, default_typ) } ast.InfixExpr { - if node.op in [.plus, .minus, .mul, .div, .mod] { + if !node.left.is_literal() && node.op in [.plus, .minus, .mul, .div, .mod] { return t.get_type_or_default(node.left, default_typ) } + if !node.right.is_literal() && node.op in [.plus, .minus, .mul, .div, .mod] { + return t.get_type_or_default(node.right, default_typ) + } } ast.IndexExpr { if node.left is ast.Ident && node.left.ct_expr { @@ -199,8 +202,12 @@ pub fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type { return t.table.value_type(nltype_unwrapped) } else if node is ast.ParExpr && t.info.is_comptime(node.expr) { return t.get_type(node.expr) - } else if node is ast.InfixExpr && t.info.is_comptime(node.left) { - return t.get_type(node.left) + } else if node is ast.InfixExpr { + if !node.left.is_literal() && t.info.is_comptime(node.left) { + return t.get_type(node.left) + } else if !node.right.is_literal() && t.info.is_comptime(node.right) { + return t.get_type(node.right) + } } else if node is ast.CastExpr && node.typ.has_flag(.generic) { return t.resolver.unwrap_generic(node.typ) }