v.markused: support a const used as default value in struct init

pull/11357/head
Delyan Angelov 2021-08-31 15:55:32 +03:00
parent f68bdb7805
commit a208138283
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 57 additions and 0 deletions

View File

@ -33,6 +33,9 @@ pub fn (mut w Walker) mark_const_as_used(ckey string) {
$if trace_skip_unused_marked ? {
eprintln(' const > |$ckey|')
}
if w.used_consts[ckey] {
return
}
w.used_consts[ckey] = true
cfield := w.all_consts[ckey] or { return }
w.expr(cfield.expr)
@ -42,6 +45,9 @@ pub fn (mut w Walker) mark_global_as_used(ckey string) {
$if trace_skip_unused_marked ? {
eprintln(' global > |$ckey|')
}
if w.used_globals[ckey] {
return
}
w.used_globals[ckey] = true
gfield := w.all_globals[ckey] or { return }
w.expr(gfield.expr)

View File

@ -0,0 +1,12 @@
&Symbol{
name: 'void'
parent: &nil
return_type: &nil
is_top_level: true
generic_placeholder_len: 0
sumtype_children_len: 0
interface_children_len: 0
children: []
file_path: ''
file_version: 0
}

View File

@ -0,0 +1,12 @@
&Symbol{
name: 'void'
parent: &nil
return_type: &nil
is_top_level: true
generic_placeholder_len: 0
sumtype_children_len: 0
interface_children_len: 0
children: []
file_path: ''
file_version: 0
}

View File

@ -0,0 +1,27 @@
module main
pub const void_type = &Symbol{
name: 'void'
file_path: ''
file_version: 0
is_top_level: true
}
[heap]
pub struct Symbol {
pub mut:
name string
parent &Symbol = void_type // parent is for typedefs, aliases
return_type &Symbol = void_type // return_type is for functions and variables
is_top_level bool [required]
generic_placeholder_len int
sumtype_children_len int
interface_children_len int
children []&Symbol // methods, sum types, map types, optionals, struct fields, etc.
file_path string [required] // required in order to register the symbol at its appropriate directory.
file_version int [required] // file version when the symbol was registered
}
fn main() {
println(void_type)
}