fmt: x.foo!() experiment

pull/5241/head
Alexander Medvednikov 2020-06-06 16:05:16 +02:00
parent e5f12ad74a
commit 2770077cb0
3 changed files with 20 additions and 3 deletions

View File

@ -245,7 +245,6 @@ pub:
pub mut: pub mut:
name string name string
is_method bool is_method bool
is_mut bool // !
args []CallArg args []CallArg
expected_arg_types []table.Type expected_arg_types []table.Type
language table.Language language table.Language

View File

@ -799,7 +799,7 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
} }
if method.args[0].is_mut { if method.args[0].is_mut {
c.fail_if_immutable(call_expr.left) c.fail_if_immutable(call_expr.left)
call_expr.is_mut = true // call_expr.is_mut = true
} }
if method.return_type == table.void_type && method.ctdefine.len > 0 && method.ctdefine !in if method.return_type == table.void_type && method.ctdefine.len > 0 && method.ctdefine !in
c.pref.compile_defines { c.pref.compile_defines {

View File

@ -888,6 +888,24 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
} }
*/ */
if node.is_method { if node.is_method {
/*
// x.foo!() experiment
mut is_mut := false
if node.left is ast.Ident {
scope := f.file.scope.innermost(node.pos.pos)
x := node.left as ast.Ident
var := scope.find_var(x.name) or {
panic(err)
}
println(var.typ)
if var.typ != 0 {
sym := f.table.get_type_symbol(var.typ)
if method := f.table.type_find_method(sym, node.name) {
is_mut = method.args[0].is_mut
}
}
}
*/
if node.left is ast.Ident { if node.left is ast.Ident {
it := node.left as ast.Ident it := node.left as ast.Ident
// `time.now()` without `time imported` is processed as a method call with `time` being // `time.now()` without `time imported` is processed as a method call with `time` being
@ -910,7 +928,7 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
f.write('.' + node.name + '(') f.write('.' + node.name + '(')
f.call_args(node.args) f.call_args(node.args)
f.write(')') f.write(')')
if node.is_mut { if is_mut {
// f.write('!') // f.write('!')
} }
f.or_expr(node.or_block) f.or_expr(node.or_block)