Skip to content

Commit 4ad8011

Browse files
committed
Fix UnaryExpr formatting in FormatDataType for negative type parameters
Handle unary expressions (like -1) in data type parameters by properly formatting them as operator + value instead of falling through to the default fmt.Sprintf which showed Go struct representation.
1 parent 49339ac commit 4ad8011

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

internal/explain/format.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ func FormatDataType(dt *ast.DataType) string {
313313
} else if ident, ok := p.(*ast.Identifier); ok {
314314
// Identifier (e.g., function name in AggregateFunction types)
315315
params = append(params, ident.Name())
316+
} else if unary, ok := p.(*ast.UnaryExpr); ok {
317+
// Unary expression (e.g., -1 for negative numbers)
318+
if lit, ok := unary.Operand.(*ast.Literal); ok {
319+
params = append(params, fmt.Sprintf("%s%v", unary.Op, lit.Value))
320+
} else {
321+
params = append(params, fmt.Sprintf("%v", p))
322+
}
316323
} else {
317324
params = append(params, fmt.Sprintf("%v", p))
318325
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)