Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 13, 2025
1 parent d860319 commit 3691d5a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions vlib/v/type_resolver/type_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,10 @@ pub fn (mut t TypeResolver) get_type_or_default(node ast.Expr, default_typ ast.T
}
ast.SelectorExpr {
if node.expr is ast.Ident && node.expr.ct_expr {
struct_typ := t.resolver.unwrap_generic(t.get_type(node.expr))
struct_sym := t.table.final_sym(struct_typ)
// Struct[T] can have field with generic type
if struct_sym.info is ast.Struct && struct_sym.info.generic_types.len > 0 {
if field := t.table.find_field(struct_sym, node.field_name) {
return field.typ
}
}
ctyp := t.get_type(node)
return if ctyp != ast.void_type { ctyp } else { default_typ }
}
return default_typ
}
ast.ParExpr {
return t.get_type_or_default(node.expr, default_typ)
Expand Down Expand Up @@ -189,8 +184,21 @@ pub fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type {
} else if node is ast.ComptimeSelector {
// val.$(field.name)
return t.get_comptime_selector_type(node, ast.void_type)
} else if node is ast.SelectorExpr && t.info.is_comptime_selector_type(node) {
return t.get_type_from_comptime_var(node.expr as ast.Ident)
} else if node is ast.SelectorExpr {
if t.info.is_comptime_selector_type(node) {
return t.get_type_from_comptime_var(node.expr as ast.Ident)
}
if node.expr is ast.Ident && node.expr.ct_expr {
struct_typ := t.resolver.unwrap_generic(t.get_type(node.expr))
struct_sym := t.table.final_sym(struct_typ)
// Struct[T] can have field with generic type
if struct_sym.info is ast.Struct && struct_sym.info.generic_types.len > 0 {
if field := t.table.find_field(struct_sym, node.field_name) {
return field.typ
}
}
}
return node.typ
} else if node is ast.ComptimeCall {
method_name := t.info.comptime_for_method.name
left_sym := t.table.sym(t.resolver.unwrap_generic(node.left_type))
Expand Down

0 comments on commit 3691d5a

Please sign in to comment.