From 0c70e9efb76029e9a1075fe322fe55a5e19eed19 Mon Sep 17 00:00:00 2001 From: JalonSolov Date: Sun, 11 Aug 2024 11:56:32 -0400 Subject: [PATCH] better handling of (#118) --- fn_call.v | 7 +++-- tests/delete/delete.go | 4 +++ tests/delete/delete.go.json | 62 ++++++++++++++++++++++++++++++++++--- tests/delete/delete.vv | 3 ++ 4 files changed, 69 insertions(+), 7 deletions(-) diff --git a/fn_call.v b/fn_call.v index 8127d94..8c1ce06 100644 --- a/fn_call.v +++ b/fn_call.v @@ -32,9 +32,10 @@ fn (mut app App) call_expr(call CallExpr) { if fun is Ident && fun.name == 'delete' { arg0 := call.args[0] - arg1 := call.args[1] - if arg0 is Ident && arg1 is BasicLit { - app.gen('${arg0.name}.${fun.name}(${arg1.value})') + if arg0 is Ident { + app.gen('${arg0.name}.${fun.name}(') + app.expr(call.args[1]) + app.genln(')') } return } diff --git a/tests/delete/delete.go b/tests/delete/delete.go index e6e107f..8d1b77c 100644 --- a/tests/delete/delete.go +++ b/tests/delete/delete.go @@ -3,6 +3,10 @@ package main func main() { m := map[string]float64{ "pi": 3.14, + "f": 1.0, } delete(m, "pi") + + key := "f" + delete(m, key) } diff --git a/tests/delete/delete.go.json b/tests/delete/delete.go.json index 5b51287..d3f3bf3 100644 --- a/tests/delete/delete.go.json +++ b/tests/delete/delete.go.json @@ -62,6 +62,19 @@ "Kind": "FLOAT", "Value": "3.14" } + }, + { + "_type": "KeyValueExpr", + "Key": { + "_type": "BasicLit", + "Kind": "STRING", + "Value": "\"f\"" + }, + "Value": { + "_type": "BasicLit", + "Kind": "FLOAT", + "Value": "1.0" + } } ], "Incomplete": false @@ -88,6 +101,43 @@ } ] } + }, + { + "_type": "AssignStmt", + "Lhs": [ + { + "_type": "Ident", + "Name": "key" + } + ], + "Tok": ":=", + "Rhs": [ + { + "_type": "BasicLit", + "Kind": "STRING", + "Value": "\"f\"" + } + ] + }, + { + "_type": "ExprStmt", + "X": { + "_type": "CallExpr", + "Fun": { + "_type": "Ident", + "Name": "delete" + }, + "Args": [ + { + "_type": "Ident", + "Name": "m" + }, + { + "_type": "Ident", + "Name": "key" + } + ] + } } ] } @@ -97,12 +147,12 @@ "Unresolved": null, "Comments": null, "FileSet": { - "Base": 92, + "Base": 134, "Files": [ { "Name": "tests/delete/delete.go", "Base": 1, - "Size": 90, + "Size": 132, "Lines": [ 0, 13, @@ -110,8 +160,12 @@ 28, 54, 68, - 71, - 88 + 81, + 84, + 101, + 102, + 114, + 130 ], "Infos": null } diff --git a/tests/delete/delete.vv b/tests/delete/delete.vv index 0a29a5c..44911ea 100644 --- a/tests/delete/delete.vv +++ b/tests/delete/delete.vv @@ -3,6 +3,9 @@ module main fn main() { mut m := { 'pi': 3.14 + 'f': 1.0 } m.delete('pi') + mut key := 'f' + m.delete(key) }