Skip to content

Commit 96cedff

Browse files
committed
Handle unary negation in tuple literal detection for IN lists
Use containsOnlyPrimitiveLiteralsWithUnary instead of containsOnlyPrimitiveLiterals when checking if tuple literals in IN expressions can be combined into a single Literal output. This fixes tuples like (1, -1), (3, -3) being incorrectly output as Function tuple instead of Literal Tuple_(UInt64_1, Int64_-1). Fixes 9 additional tests.
1 parent c34dd49 commit 96cedff

File tree

4 files changed

+7
-25
lines changed

4 files changed

+7
-25
lines changed

internal/explain/functions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,8 @@ func explainInExpr(sb *strings.Builder, n *ast.InExpr, indent string, depth int)
983983
if lit.Type != ast.LiteralTuple {
984984
allTuples = false
985985
} else {
986-
// Check if this tuple contains only primitive literals
987-
if !containsOnlyPrimitiveLiterals(lit) {
986+
// Check if this tuple contains only primitive literals (including unary negation)
987+
if !containsOnlyPrimitiveLiteralsWithUnary(lit) {
988988
allTuplesArePrimitive = false
989989
}
990990
}
@@ -1090,8 +1090,8 @@ func explainInExpr(sb *strings.Builder, n *ast.InExpr, indent string, depth int)
10901090

10911091
// explainTupleInInList renders a tuple in an IN list - either as Literal or Function tuple
10921092
func explainTupleInInList(sb *strings.Builder, lit *ast.Literal, indent string, depth int) {
1093-
if containsOnlyPrimitiveLiterals(lit) {
1094-
// All primitives - render as Literal Tuple_
1093+
if containsOnlyPrimitiveLiteralsWithUnary(lit) {
1094+
// All primitives (including unary negation) - render as Literal Tuple_
10951095
fmt.Fprintf(sb, "%s Literal %s\n", indent, FormatLiteral(lit))
10961096
} else {
10971097
// Contains expressions - render as Function tuple
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true,
4-
"stmt6": true,
5-
"stmt7": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true,
4-
"stmt14": true,
5-
"stmt15": true,
6-
"stmt16": true,
7-
"stmt17": true
8-
}
9-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)