mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
another map bug fix + fix some warnings
This commit is contained in:
parent
fa24a0cec5
commit
ddb4f45b02
@ -193,6 +193,7 @@ fn (v mut V) compile() {
|
||||
#include <signal.h>
|
||||
#include <stdarg.h> // for va_list
|
||||
#include <inttypes.h> // int64_t etc
|
||||
#include <string.h> // memcpy
|
||||
|
||||
#define STRUCT_DEFAULT_VALUE {}
|
||||
#define EMPTY_STRUCT_DECLARATION
|
||||
|
@ -2309,19 +2309,17 @@ fn format_str(str string) string {
|
||||
}
|
||||
|
||||
fn (p mut Parser) string_expr() {
|
||||
// println('.str EXPR')
|
||||
str := p.lit
|
||||
// No ${}, just return a simple string
|
||||
if p.peek() != .dollar {
|
||||
p.fgen('\'$str\'')
|
||||
// println('before format: "$str"')
|
||||
f := format_str(str)
|
||||
// println('after format: "$str"')
|
||||
// `C.puts('hi')` => `puts("hi");`
|
||||
if p.calling_c || (p.pref.translated && p.mod == 'main') {
|
||||
p.gen('"$f"')
|
||||
}
|
||||
else {
|
||||
p.gen('tos2("$f")')
|
||||
p.gen('tos2((byte*)"$f")')
|
||||
}
|
||||
p.next()
|
||||
return
|
||||
@ -2387,8 +2385,8 @@ fn (p mut Parser) string_expr() {
|
||||
}
|
||||
}
|
||||
if complex_inter {
|
||||
p.fgen('}')
|
||||
}
|
||||
p.fgen('}')
|
||||
}
|
||||
p.fgen('\'')
|
||||
// println("hello %d", num) optimization.
|
||||
if p.cgen.nogen {
|
||||
|
@ -143,11 +143,10 @@ fn (m map) bs(query string, start, end int, out voidptr) {
|
||||
*/
|
||||
|
||||
fn (m mut map) preorder_keys(node &Node) {
|
||||
if node.is_empty {
|
||||
return
|
||||
}
|
||||
if !node.is_empty {
|
||||
m._keys[m.key_i] = node.key
|
||||
m.key_i++
|
||||
}
|
||||
if !isnil(node.left) {
|
||||
m.preorder_keys(node.left)
|
||||
}
|
||||
|
@ -38,8 +38,10 @@ fn test_map() {
|
||||
assert keys[1] == 'hello'
|
||||
m.delete('hi')
|
||||
assert m.size == 1
|
||||
|
||||
assert m['hi'] == 0
|
||||
assert m.keys().len == 1
|
||||
assert m.keys()[0] == 'hello'
|
||||
////
|
||||
mut users := map[string]User{}
|
||||
users['1'] = User{'Peter'}
|
||||
|
Loading…
Reference in New Issue
Block a user