From 2770077cb0bb3c8b5babfb0a2e09c2fbd5e92d28 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 6 Jun 2020 16:05:16 +0200 Subject: [PATCH] fmt: x.foo!() experiment --- vlib/v/ast/ast.v | 1 - vlib/v/checker/checker.v | 2 +- vlib/v/fmt/fmt.v | 20 +++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 35f229e635..1b0598ef87 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -245,7 +245,6 @@ pub: pub mut: name string is_method bool - is_mut bool // ! args []CallArg expected_arg_types []table.Type language table.Language diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 2be05fe81a..d9f14f6158 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -799,7 +799,7 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type { } if method.args[0].is_mut { 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 c.pref.compile_defines { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index c073989c08..ce70e6b44c 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -888,6 +888,24 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) { } */ 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 { it := node.left as ast.Ident // `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.call_args(node.args) f.write(')') - if node.is_mut { + if is_mut { // f.write('!') } f.or_expr(node.or_block)