vfmt: do not replace module aliases in fn param and return types (#7472)
parent
6aadc828b1
commit
c4aae2b55f
|
@ -105,7 +105,7 @@ fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string {
|
||||||
for s in f.stmts {
|
for s in f.stmts {
|
||||||
if s is ast.FnDecl {
|
if s is ast.FnDecl {
|
||||||
if s.is_pub {
|
if s.is_pub {
|
||||||
fn_signature := s.stringify(b.table, mod_name)
|
fn_signature := s.stringify(b.table, mod_name, map[string]string)
|
||||||
fn_mod := s.modname()
|
fn_mod := s.modname()
|
||||||
if fn_mod == mod_name {
|
if fn_mod == mod_name {
|
||||||
fline := '$fn_mod: $fn_signature'
|
fline := '$fn_mod: $fn_signature'
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub fn (node &FnDecl) modname() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// These methods are used only by vfmt, vdoc, and for debugging.
|
// These methods are used only by vfmt, vdoc, and for debugging.
|
||||||
pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string) string {
|
pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string, m2a map[string]string) string {
|
||||||
mut f := strings.new_builder(30)
|
mut f := strings.new_builder(30)
|
||||||
if node.is_pub {
|
if node.is_pub {
|
||||||
f.write('pub ')
|
f.write('pub ')
|
||||||
|
@ -84,6 +84,9 @@ pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = util.no_cur_mod(s, cur_mod)
|
s = util.no_cur_mod(s, cur_mod)
|
||||||
|
for mod, alias in m2a {
|
||||||
|
s = s.replace(mod, alias)
|
||||||
|
}
|
||||||
if should_add_type {
|
if should_add_type {
|
||||||
if !is_type_only {
|
if !is_type_only {
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
|
@ -99,9 +102,11 @@ pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string) string {
|
||||||
}
|
}
|
||||||
f.write(')')
|
f.write(')')
|
||||||
if node.return_type != table.void_type {
|
if node.return_type != table.void_type {
|
||||||
// typ := t.type_to_str(node.typ)
|
mut rs := util.no_cur_mod(t.type_to_str(node.return_type), cur_mod)
|
||||||
// if typ.starts_with('
|
for mod, alias in m2a {
|
||||||
f.write(' ' + util.no_cur_mod(t.type_to_str(node.return_type), cur_mod))
|
rs = rs.replace(mod, alias)
|
||||||
|
}
|
||||||
|
f.write(' ' + rs)
|
||||||
}
|
}
|
||||||
return f.str()
|
return f.str()
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,7 +331,7 @@ fn (b &Builder) print_warnings_and_errors() {
|
||||||
for stmt in file.stmts {
|
for stmt in file.stmts {
|
||||||
if stmt is ast.FnDecl {
|
if stmt is ast.FnDecl {
|
||||||
if stmt.name == fn_name {
|
if stmt.name == fn_name {
|
||||||
fheader := stmt.stringify(b.table, 'main')
|
fheader := stmt.stringify(b.table, 'main', map[string]string{})
|
||||||
redefines << FunctionRedefinition{
|
redefines << FunctionRedefinition{
|
||||||
fpath: file.path
|
fpath: file.path
|
||||||
fline: stmt.pos.line_nr
|
fline: stmt.pos.line_nr
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub fn (mut d Doc) stmt_signature(stmt ast.Stmt) string {
|
||||||
return 'module $stmt.name'
|
return 'module $stmt.name'
|
||||||
}
|
}
|
||||||
ast.FnDecl {
|
ast.FnDecl {
|
||||||
return stmt.stringify(d.table, d.fmt.cur_mod)
|
return stmt.stringify(d.table, d.fmt.cur_mod, d.fmt.mod2alias)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
d.fmt.out = strings.new_builder(1000)
|
d.fmt.out = strings.new_builder(1000)
|
||||||
|
|
|
@ -705,7 +705,7 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||||
f.comments_after_last_field(node.pre_comments)
|
f.comments_after_last_field(node.pre_comments)
|
||||||
for method in node.methods {
|
for method in node.methods {
|
||||||
f.write('\t')
|
f.write('\t')
|
||||||
f.write(method.stringify(f.table, f.cur_mod).after('fn '))
|
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
|
||||||
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
|
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
|
@ -1251,7 +1251,7 @@ pub fn (mut f Fmt) fn_decl(node ast.FnDecl) {
|
||||||
// println('$it.name find_comment($it.pos.line_nr)')
|
// println('$it.name find_comment($it.pos.line_nr)')
|
||||||
// f.find_comment(it.pos.line_nr)
|
// f.find_comment(it.pos.line_nr)
|
||||||
f.attrs(node.attrs)
|
f.attrs(node.attrs)
|
||||||
f.write(node.stringify(f.table, f.cur_mod)) // `Expr` instead of `ast.Expr` in mod ast
|
f.write(node.stringify(f.table, f.cur_mod, f.mod2alias)) // `Expr` instead of `ast.Expr` in mod ast
|
||||||
if node.language == .v {
|
if node.language == .v {
|
||||||
if !node.no_body {
|
if !node.no_body {
|
||||||
f.writeln(' {')
|
f.writeln(' {')
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
fn (v JS.String) toString() JS.String
|
|
||||||
|
|
||||||
fn JS.Math.abs(f64) f64
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
JS.Math.abs(0)
|
|
||||||
}
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
fn (v JS.String) toString() JS.String
|
||||||
|
|
||||||
|
fn (v JS.String) toMultiRet() (JS.String, int)
|
||||||
|
|
||||||
|
fn JS.Math.abs(f64) f64
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
JS.Math.abs(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn object_ref_optional() ?&C.File {
|
||||||
|
return error('')
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import time
|
||||||
|
import semver as sv
|
||||||
|
|
||||||
|
fn foo(f time.Time) time.Time {
|
||||||
|
f2 := time.Time{}
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(b sv.Version) sv.Version {
|
||||||
|
b2 := sv.Version{}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar_multi_return(b sv.Version) (sv.Version, int) {
|
||||||
|
b2 := sv.Version{}
|
||||||
|
return b, 0
|
||||||
|
}
|
Loading…
Reference in New Issue