Skip to content

Commit cd205b3

Browse files
committed
Fix nested array literal format for arrays with negative numbers
Updated containsNonLiteralExpressions to accept unary minus of literals (negative numbers) as literal-like expressions. This allows nested arrays containing negative numbers to be formatted as Literal Array_[Array_[...], ...] instead of Function array.
1 parent a960bd7 commit cd205b3

File tree

7 files changed

+15
-22
lines changed

7 files changed

+15
-22
lines changed

internal/explain/expressions.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,16 @@ func containsOnlyArraysOrTuples(exprs []ast.Expression) bool {
228228
// any non-literal expressions (identifiers, function calls, etc.)
229229
func containsNonLiteralExpressions(exprs []ast.Expression) bool {
230230
for _, e := range exprs {
231-
if _, ok := e.(*ast.Literal); !ok {
232-
return true
231+
if _, ok := e.(*ast.Literal); ok {
232+
continue
233+
}
234+
// Unary minus of a literal (negative number) is also acceptable
235+
if unary, ok := e.(*ast.UnaryExpr); ok && unary.Op == "-" {
236+
if _, ok := unary.Operand.(*ast.Literal); ok {
237+
continue
238+
}
233239
}
240+
return true
234241
}
235242
return false
236243
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt5":true}}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt12":true}}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt16": true,
4-
"stmt17": true,
5-
"stmt18": true,
6-
"stmt39": true,
7-
"stmt40": true,
8-
"stmt60": true,
9-
"stmt61": true
10-
}
11-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt3":true,"stmt4":true}}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt10":true,"stmt11":true,"stmt12":true,"stmt9":true}}
1+
{}

0 commit comments

Comments
 (0)