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()
|
// 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 {
|
||||||
|
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