fmt: fix import with symbols (fix #12065) (#12069)

pull/12075/head
yuyi 2021-10-05 16:44:48 +08:00 committed by GitHub
parent 7555b337b9
commit 7bc3e67e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 2 deletions

View File

@ -42,7 +42,6 @@ const (
]
vfmt_known_failing_exceptions = arrays.merge(verify_known_failing_exceptions, [
'vlib/regex/regex_test.v' /* contains meaningfull formatting of the test case data */,
'vlib/readline/readline_test.v' /* vfmt eats `{ Readline }` from `import readline { Readline }` */,
'vlib/glm/glm.v' /* `mut res &f32` => `mut res f32`, which then fails to compile */,
'vlib/crypto/sha512/sha512block_generic.v' /* formatting of large constant arrays wraps to too many lines */,
'vlib/crypto/aes/const.v' /* formatting of large constant arrays wraps to too many lines */,

View File

@ -17,4 +17,4 @@ fn test_struct_readline() {
// eprintln('methods: $methods')
assert 'read_line_utf8' in methods
assert 'read_line' in methods
}
}

View File

@ -760,6 +760,7 @@ pub fn (mut f Fmt) branch_stmt(node ast.BranchStmt) {
pub fn (mut f Fmt) comp_for(node ast.CompFor) {
typ := f.no_cur_mod(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
f.write('\$for $node.val_var in ${typ}.$node.kind.str() {')
f.mark_types_import_as_used(node.typ)
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {
f.writeln('')
f.stmts(node.stmts)

View File

@ -0,0 +1,14 @@
import readline { Readline }
fn no_lines(s string) string {
return s.replace('\n', ' ')
}
fn main() {
mut methods := []string{}
$for method in Readline.methods {
methods << method.name
}
assert 'read_line_utf8' in methods
assert 'read_line' in methods
}