mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
This commit is contained in:
parent
eab148eaa5
commit
7b97709449
6 changed files with 18 additions and 0 deletions
|
@ -28,6 +28,7 @@ pub mut:
|
|||
arr_reverse bool // arr.reverse()
|
||||
arr_init bool // [1, 2, 3]
|
||||
arr_map bool // []map[key]value
|
||||
type_name bool // var.type_name()
|
||||
map_update bool // {...foo}
|
||||
interpolation bool // '${foo} ${bar}'
|
||||
option_or_result bool // has panic call
|
||||
|
|
|
@ -1988,6 +1988,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||
}
|
||||
if left_sym.kind in [.sum_type, .interface] {
|
||||
if method_name == 'type_name' {
|
||||
c.table.used_features.type_name = true
|
||||
return ast.string_type
|
||||
}
|
||||
if method_name == 'type_idx' {
|
||||
|
|
|
@ -212,6 +212,9 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
|
|||
core_fns << '__print_assert_failure'
|
||||
core_fns << 'isnil'
|
||||
}
|
||||
if table.used_features.type_name {
|
||||
core_fns << charptr_idx_str + '.vstring_literal'
|
||||
}
|
||||
if pref_.trace_calls || pref_.trace_fns.len > 0 {
|
||||
include_panic_deps = true
|
||||
core_fns << 'vgettid'
|
||||
|
|
2
vlib/v/tests/skip_unused/sumtype_type_name.run.out
Normal file
2
vlib/v/tests/skip_unused/sumtype_type_name.run.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Dbv
|
||||
string
|
|
@ -0,0 +1,2 @@
|
|||
Dbv
|
||||
string
|
9
vlib/v/tests/skip_unused/sumtype_type_name.vv
Normal file
9
vlib/v/tests/skip_unused/sumtype_type_name.vv
Normal file
|
@ -0,0 +1,9 @@
|
|||
module main
|
||||
|
||||
type Dbv = int | string
|
||||
|
||||
fn main() {
|
||||
mut m := Dbv('foo')
|
||||
println(typeof(m).name)
|
||||
println(m.type_name())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue