Skip to content

Commit

Permalink
better handling of (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonSolov authored Aug 11, 2024
1 parent 778b67e commit 0c70e9e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
7 changes: 4 additions & 3 deletions fn_call.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions tests/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
62 changes: 58 additions & 4 deletions tests/delete/delete.go.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
]
}
}
]
}
Expand All @@ -97,21 +147,25 @@
"Unresolved": null,
"Comments": null,
"FileSet": {
"Base": 92,
"Base": 134,
"Files": [
{
"Name": "tests/delete/delete.go",
"Base": 1,
"Size": 90,
"Size": 132,
"Lines": [
0,
13,
14,
28,
54,
68,
71,
88
81,
84,
101,
102,
114,
130
],
"Infos": null
}
Expand Down
3 changes: 3 additions & 0 deletions tests/delete/delete.vv
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 0c70e9e

Please sign in to comment.