mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
d0e78b1da6
commit
c9345be6de
@ -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()
|
|
||||||
// remove generic part from name
|
|
||||||
// Abc[int] => Abc
|
// Abc[int] => Abc
|
||||||
if embed_name.contains('[') {
|
// main.Abc[main.Enum] => Abc
|
||||||
embed_name = embed_name.split('[')[0]
|
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 {
|
pub fn (t &TypeSymbol) has_method(name string) bool {
|
||||||
|
27
vlib/v/tests/embed_struct_name_test.v
Normal file
27
vlib/v/tests/embed_struct_name_test.v
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user