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:
parent
40df91fc08
commit
7e641cd5ba
@ -690,8 +690,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
|
|||||||
}
|
}
|
||||||
typ := p.bool_expression()
|
typ := p.bool_expression()
|
||||||
// TODO temporary hack to allow println(777)
|
// TODO temporary hack to allow println(777)
|
||||||
if i == 0 && f.name == 'println' && typ != 'string'
|
if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' {
|
||||||
&& typ != 'void' {
|
|
||||||
// If we dont check for void, then V will compile "println(procedure())"
|
// If we dont check for void, then V will compile "println(procedure())"
|
||||||
T := p.table.find_type(typ)
|
T := p.table.find_type(typ)
|
||||||
if typ == 'u8' {
|
if typ == 'u8' {
|
||||||
@ -706,7 +705,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
|
|||||||
else {
|
else {
|
||||||
// Make sure this type has a `str()` method
|
// Make sure this type has a `str()` method
|
||||||
if !T.has_method('str') {
|
if !T.has_method('str') {
|
||||||
if ((*T).fields.len > 0) {
|
if T.fields.len > 0 {
|
||||||
mut index := p.cgen.cur_line.len - 1
|
mut index := p.cgen.cur_line.len - 1
|
||||||
for index > 0 && p.cgen.cur_line[index] != ` ` { index-- }
|
for index > 0 && p.cgen.cur_line[index] != ` ` { index-- }
|
||||||
name := p.cgen.cur_line.right(index + 1)
|
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.error('`$typ` needs to have method `str() string` to be printable')
|
||||||
}
|
}
|
||||||
p.cgen.cur_line = p.cgen.cur_line.left(index)
|
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.cgen.cur_line.replace(typ, '')
|
||||||
p.next()
|
p.next()
|
||||||
return p.fn_call_args(f)
|
return p.fn_call_args(f)
|
||||||
|
@ -677,13 +677,13 @@ fn (s mut Scanner) get_opening_bracket() int {
|
|||||||
return pos
|
return pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Foo { bar: 3, baz: 'hi' } => '{ bar: 3, baz: "hi" }'
|
||||||
fn (s mut Scanner) create_type_string(T Type, name string) {
|
fn (s mut Scanner) create_type_string(T Type, name string) {
|
||||||
line := s.line_nr
|
line := s.line_nr
|
||||||
inside_string := s.inside_string
|
inside_string := s.inside_string
|
||||||
mut newtext := '\'{ '
|
mut newtext := '\'{ '
|
||||||
start := s.get_opening_bracket() + 1
|
start := s.get_opening_bracket() + 1
|
||||||
end := s.pos
|
end := s.pos
|
||||||
|
|
||||||
for i, field in T.fields {
|
for i, field in T.fields {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
newtext += ', '
|
newtext += ', '
|
||||||
|
Loading…
Reference in New Issue
Block a user