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 {
// main.Abc[int] => Abc[int]
mut embed_name := t.name.split('.').last()
// remove generic part from name
// Abc[int] => Abc
if embed_name.contains('[') {
embed_name = embed_name.split('[')[0]
if t.name.contains('[') {
// Abc[int] => Abc
// main.Abc[main.Enum] => Abc
return t.name.split('[')[0].split('.').last()
} else {
// main.Abc => Abc
return t.name.split('.').last()
}
return embed_name
}
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
}