mirror of
https://github.com/vlang/v.git
synced 2025-09-18 03:46:36 -04:00
cgen: fix using custom enum static from_string() (#19171)
This commit is contained in:
parent
56644b2b52
commit
f4eede8d23
@ -1720,7 +1720,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
||||
g.write('panic_debug(${paline}, tos3("${pafile}"), tos3("${pamod}"), tos3("${pafn}"), ')
|
||||
g.call_args(node)
|
||||
g.write(')')
|
||||
} else if node.name.ends_with('__static__from_string') {
|
||||
} else if node.name.ends_with('__static__from_string') && !g.table.known_fn(node.name) {
|
||||
if node.name !in g.str_fn_names {
|
||||
g.gen_enum_static_from_string(node.name)
|
||||
g.str_fn_names << node.name
|
||||
|
14
vlib/v/tests/enum_custom_static_from_string_test.v
Normal file
14
vlib/v/tests/enum_custom_static_from_string_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
enum Color {
|
||||
red
|
||||
green
|
||||
blue
|
||||
}
|
||||
|
||||
fn Color.from_string(x string) Color {
|
||||
return Color.red
|
||||
}
|
||||
|
||||
fn test_enum_custom_static_from_string() {
|
||||
ret := Color.from_string('abc')
|
||||
assert ret == Color.red
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user