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

gen: implement type_name method for sum type instances (#6802)

This commit is contained in:
Nick Treleaven
2020-11-14 11:59:03 +00:00
committed by GitHub
parent 2dc9a45e06
commit 50163508f8
7 changed files with 38 additions and 2 deletions

View File

@ -1634,8 +1634,11 @@ struct Venus {}
type World = Moon | Mars | Venus
sum := World(Moon{})
assert sum.type_name() == 'Moon'
println(sum)
```
The built-in method `type_name` returns the name of the currently held
type.
#### Dynamic casts