mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix a buggy comparison, add ability to do println(sym.debug())
This commit is contained in:
parent
0114333d34
commit
321daede1d
@ -0,0 +1,17 @@
|
||||
import v.table
|
||||
|
||||
fn main() {
|
||||
t := table.new_table()
|
||||
ityp := table.int_type
|
||||
isym := t.get_type_symbol(ityp)
|
||||
println(ityp.debug())
|
||||
println(isym)
|
||||
println(isym.debug())
|
||||
x := ityp == table.string_type
|
||||
// the next line should produce at least a warning, or even an error, without an explicit cast:
|
||||
z := isym == table.string_type
|
||||
println(typeof(isym))
|
||||
println(typeof(table.string_type))
|
||||
println(x)
|
||||
println(z)
|
||||
}
|
@ -1678,7 +1678,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||
if left.left_type.is_ptr() {
|
||||
g.write('*')
|
||||
}
|
||||
needs_clone := elem_typ == table.string_type && g.pref.autofree
|
||||
needs_clone := info.elem_type == table.string_type && g.pref.autofree
|
||||
if needs_clone {
|
||||
g.write('/*1*/string_clone(')
|
||||
}
|
||||
|
@ -183,6 +183,21 @@ pub fn (t Type) has_flag(flag TypeFlag) bool {
|
||||
return int(t) & (1 << (int(flag) + 24)) > 0
|
||||
}
|
||||
|
||||
pub fn (ts TypeSymbol) debug() []string {
|
||||
mut res := []string{}
|
||||
res << 'parent_idx: $ts.parent_idx'
|
||||
res << 'mod: $ts.mod'
|
||||
res << 'name: $ts.name'
|
||||
res << 'source_name: $ts.source_name'
|
||||
res << 'info: $ts.info'
|
||||
res << 'kind: $ts.kind'
|
||||
res << 'is_public: $ts.is_public'
|
||||
res << 'is_written: $ts.is_written'
|
||||
res << 'language: $ts.language'
|
||||
res << 'methods ($ts.methods.len): ' + ts.methods.map(it.str()).join(', ')
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (t Type) debug() []string {
|
||||
mut res := []string{}
|
||||
res << 'idx: ${t.idx():5}'
|
||||
|
Loading…
Reference in New Issue
Block a user