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

structure printing: minor fixes

This commit is contained in:
Alexander Medvednikov 2019-06-27 01:55:37 +02:00
parent 40df91fc08
commit 7e641cd5ba
2 changed files with 5 additions and 6 deletions

View File

@ -690,8 +690,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
}
typ := p.bool_expression()
// TODO temporary hack to allow println(777)
if i == 0 && f.name == 'println' && typ != 'string'
&& typ != 'void' {
if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' {
// If we dont check for void, then V will compile "println(procedure())"
T := p.table.find_type(typ)
if typ == 'u8' {
@ -706,7 +705,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
else {
// Make sure this type has a `str()` method
if !T.has_method('str') {
if ((*T).fields.len > 0) {
if T.fields.len > 0 {
mut index := p.cgen.cur_line.len - 1
for index > 0 && p.cgen.cur_line[index] != ` ` { index-- }
name := p.cgen.cur_line.right(index + 1)
@ -714,7 +713,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
p.error('`$typ` needs to have method `str() string` to be printable')
}
p.cgen.cur_line = p.cgen.cur_line.left(index)
p.create_type_string(*T, name)
p.create_type_string(T, name)
p.cgen.cur_line.replace(typ, '')
p.next()
return p.fn_call_args(f)

View File

@ -677,13 +677,13 @@ fn (s mut Scanner) get_opening_bracket() int {
return pos
}
// Foo { bar: 3, baz: 'hi' } => '{ bar: 3, baz: "hi" }'
fn (s mut Scanner) create_type_string(T Type, name string) {
line := s.line_nr
inside_string := s.inside_string
mut newtext := '\'{ '
start := s.get_opening_bracket() + 1
end := s.pos
for i, field in T.fields {
if i != 0 {
newtext += ', '
@ -699,4 +699,4 @@ fn (s mut Scanner) create_type_string(T Type, name string) {
fn (p mut Parser) create_type_string(T Type, name string) {
p.scanner.create_type_string(T, name)
}
}