Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type_resolver: remove type_resolver.get_expr_type_or_default and type_resolver.is_comptime_expr #23621

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
@@ -3936,7 +3936,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
typ := c.type_resolver.get_type_or_default(node, info.typ)
// Got a var with type T, return current generic type
if node.or_expr.kind != .absent {
if !typ.has_flag(.option) {
if !info.typ.has_flag(.option) {
if node.or_expr.kind == .propagate_option {
c.error('cannot use `?` on non-option variable', node.pos)
} else if node.or_expr.kind == .block {
4 changes: 2 additions & 2 deletions vlib/v/gen/c/infix.v
Original file line number Diff line number Diff line change
@@ -96,8 +96,8 @@ fn (mut g Gen) infix_expr_arrow_op(node ast.InfixExpr) {

// infix_expr_eq_op generates code for `==` and `!=`
fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
left_type := g.type_resolver.get_expr_type_or_default(node.left, node.left_type)
right_type := g.type_resolver.get_expr_type_or_default(node.right, node.right_type)
left_type := g.type_resolver.get_type_or_default(node.left, node.left_type)
right_type := g.type_resolver.get_type_or_default(node.right, node.right_type)
left := g.unwrap(left_type)
right := g.unwrap(right_type)
mut has_defined_eq_operator := false
27 changes: 0 additions & 27 deletions vlib/v/type_resolver/comptime_resolver.v
Original file line number Diff line number Diff line change
@@ -13,15 +13,6 @@ pub fn (mut t TypeResolver) get_comptime_selector_var_type(node ast.ComptimeSele
return field, field_name
}

// is_comptime_expr checks if the node is related to a comptime expr
@[inline]
pub fn (t &ResolverInfo) is_comptime_expr(node ast.Expr) bool {
return (node is ast.Ident && node.ct_expr)
|| (node is ast.IndexExpr && t.is_comptime_expr(node.left))
|| node is ast.ComptimeSelector
|| (node is ast.PostfixExpr && t.is_comptime_expr(node.expr))
}

// has_comptime_expr checks if the expr contains some comptime expr
@[inline]
pub fn (t &ResolverInfo) has_comptime_expr(node ast.Expr) bool {
@@ -110,24 +101,6 @@ pub fn (t &ResolverInfo) get_ct_type_var(node ast.Expr) ast.ComptimeVarKind {
return .no_comptime
}

// get_expr_type_or_default computes the ast node type regarding its or_expr if its comptime var otherwise default_typ is returned
pub fn (mut t TypeResolver) get_expr_type_or_default(node ast.Expr, default_typ ast.Type) ast.Type {
if !t.info.is_comptime_expr(node) {
return default_typ
}
ctyp := t.get_type(node)
match node {
ast.Ident {
// returns the unwrapped type of the var
if ctyp.has_flag(.option) && node.or_expr.kind != .absent {
return ctyp.clear_flag(.option)
}
}
else {}
}
return if ctyp != ast.void_type { ctyp } else { default_typ }
}

// get_type_from_comptime_var retrives the comptime type related to $for variable
@[inline]
pub fn (t &TypeResolver) get_type_from_comptime_var(var ast.Ident) ast.Type {
10 changes: 9 additions & 1 deletion vlib/v/type_resolver/type_resolver.v
Original file line number Diff line number Diff line change
@@ -104,7 +104,15 @@ pub fn (mut t TypeResolver) get_type_or_default(node ast.Expr, default_typ ast.T
ast.Ident {
if node.ct_expr {
ctyp := t.get_type(node)
return if ctyp != ast.void_type { ctyp } else { default_typ }
return if ctyp != ast.void_type {
if node.or_expr.kind == .absent {
ctyp
} else {
ctyp.clear_flag(.option)
}
} else {
default_typ
}
}
}
ast.SelectorExpr {