Skip to content

Commit

Permalink
ast: fix duplicated code gen for embedded generic fields (vlang#20054)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 authored Dec 1, 2023
1 parent 0b8a612 commit a017b53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
if mut parent_info is Struct {
for mut embed in parent_info.embeds {
if embed == orig_type {
embed = fields[i].typ.set_flag(.generic)
embed = fields[i].typ
break
}
}
Expand Down Expand Up @@ -2138,7 +2138,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
if fields[i].name.len > 1 && fields[i].name[0].is_capital() {
for mut embed in parent_info.embeds {
if embed == orig_type {
embed = fields[i].typ.set_flag(.generic)
embed = fields[i].typ
break
}
}
Expand Down
6 changes: 5 additions & 1 deletion vlib/v/ast/types.v
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,11 @@ pub fn (t &TypeSymbol) symbol_name_except_generic() string {
}

pub fn (t &TypeSymbol) embed_name() string {
if t.name.contains('[') {
if t.name.contains('<') {
// Abc<T>[int] => Abc
// main.Abc<T>[main.Enum] => Abc
return t.name.split('<')[0].split('.').last()
} else if t.name.contains('[') {
// Abc[int] => Abc
// main.Abc[main.Enum] => Abc
return t.name.split('[')[0].split('.').last()
Expand Down

0 comments on commit a017b53

Please sign in to comment.