1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: fix embed name with enum as generic struct type (fix #17721) (#17727)

This commit is contained in:
Felipe Pena 2023-03-22 04:50:58 -03:00 committed by GitHub
parent d0e78b1da6
commit c9345be6de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 7 deletions

View File

@ -1492,14 +1492,14 @@ pub fn (t &TypeSymbol) symbol_name_except_generic() string {
} }
pub fn (t &TypeSymbol) embed_name() string { pub fn (t &TypeSymbol) embed_name() string {
// main.Abc[int] => Abc[int] if t.name.contains('[') {
mut embed_name := t.name.split('.').last() // Abc[int] => Abc
// remove generic part from name // main.Abc[main.Enum] => Abc
// Abc[int] => Abc return t.name.split('[')[0].split('.').last()
if embed_name.contains('[') { } else {
embed_name = embed_name.split('[')[0] // main.Abc => Abc
return t.name.split('.').last()
} }
return embed_name
} }
pub fn (t &TypeSymbol) has_method(name string) bool { pub fn (t &TypeSymbol) has_method(name string) bool {

View File

@ -0,0 +1,27 @@
struct MyTemplate[T] {
data T
}
enum MyEnum as u8 {
client
server
}
struct Embed {
a int
}
struct MyStructure {
Embed
MyTemplate[MyEnum]
}
fn test_embed_name_with_enum() {
t := MyStructure{
a: 10
data: .server
}
dump(t)
assert t.a == 10
assert t.data == .server
}