Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 2, 2025
1 parent 6dcfa64 commit d8a06a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions vlib/math/stats/stats_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ fn test_kurtosis() {
assert stats.kurtosis[int]([1, 2, 3, 1]) == 1
assert stats.kurtosis[i64]([i64(1), 2, 3, 1]) == 1
o = stats.kurtosis[f32]([f32(1.0), 3, 5, 7, 3])
assert math.alike(o, -1.0443782806396484)
assert math.alike(o, -1.044378399848938)
}

fn test_skew() {
Expand All @@ -476,7 +476,7 @@ fn test_skew() {
assert stats.skew[int]([1, 2, 3, 1]) == 2
assert stats.skew[i64]([i64(1), 2, 3, 1]) == 2
o = stats.skew[f32]([f32(1.0), 3, 5, 7, 3])
assert math.alike(o, 0.2715454697608948)
assert math.alike(o, 0.27154541015625)
}

fn test_quantile() {
Expand Down
8 changes: 7 additions & 1 deletion vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,13 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
}
} else if mut right is ast.InfixExpr {
right_ct_var := c.comptime.get_ct_type_var(right.left)
if right_ct_var in [.generic_var, .generic_param] {
if right_ct_var != .no_comptime {
left.obj.ct_type_var = right_ct_var
}
} else if mut right is ast.IndexExpr
&& c.comptime.is_comptime(right) {
right_ct_var := c.comptime.get_ct_type_var(right.left)
if right_ct_var != .no_comptime {
left.obj.ct_type_var = right_ct_var
}
} else if mut right is ast.Ident && right.obj is ast.Var
Expand Down
6 changes: 5 additions & 1 deletion vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,13 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
left.obj.typ = var_type
g.assign_ct_type = var_type
}
} else if val is ast.InfixExpr {
} else if val is ast.InfixExpr && g.comptime.is_comptime(val.left) {
ctyp := g.unwrap_generic(g.type_resolver.get_type(val.left))
if ctyp != ast.void_type {
ct_type_var := g.comptime.get_ct_type_var(val.left)
if ct_type_var in [.key_var, .value_var] {
g.type_resolver.update_ct_type(left.name, g.unwrap_generic(ctyp))
}
var_type = ctyp
val_type = var_type
left.obj.typ = var_type
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/type_resolver/comptime_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ pub fn (t &ResolverInfo) get_ct_type_var(node ast.Expr) ast.ComptimeVarKind {
}
} else if node is ast.IndexExpr {
return t.get_ct_type_var(node.left)
} else if node is ast.InfixExpr {
return t.get_ct_type_var(node.left)
} else if node is ast.ParExpr {
return t.get_ct_type_var(node.expr)
}
return .no_comptime
}
Expand Down

0 comments on commit d8a06a8

Please sign in to comment.