Skip to content

Commit f91bff6

Browse files
committed
fix(compiler): fix typename comparison in function overloading
1 parent 8bf2817 commit f91bff6

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CREATE FUNCTION foo(bar TEXT) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
2+
CREATE FUNCTION foo(bar TEXT[]) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
23
CREATE FUNCTION foo(bar INTEGER) RETURNS TEXT AS $$ SELECT 'baz' $$ LANGUAGE sql;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CREATE FUNCTION foo(bar TEXT) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
2+
CREATE FUNCTION foo(bar TEXT[]) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
23
CREATE FUNCTION foo(bar INTEGER) RETURNS TEXT AS $$ SELECT 'baz' $$ LANGUAGE sql;

internal/engine/postgresql/parse.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,21 @@ func translate(node *nodes.Node) (ast.Node, error) {
498498
for _, item := range n.Parameters {
499499
arg := item.Node.(*nodes.Node_FunctionParameter).FunctionParameter
500500
rel, err := parseRelationFromNodes(arg.ArgType.Names)
501+
502+
relType := rel.TypeName()
503+
relType.ArrayBounds = convertSlice(arg.ArgType.ArrayBounds)
504+
501505
if err != nil {
502506
return nil, err
503507
}
504508
mode, err := convertFuncParamMode(arg.Mode)
505509
if err != nil {
506510
return nil, err
507511
}
512+
508513
fp := &ast.FuncParam{
509514
Name: &arg.Name,
510-
Type: rel.TypeName(),
515+
Type: relType,
511516
Mode: mode,
512517
}
513518
if arg.Defexpr != nil {

internal/sql/catalog/types.go

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ func (ct *CompositeType) SetComment(c string) {
3939
ct.Comment = c
4040
}
4141

42+
func arrayDims(n *ast.TypeName) int {
43+
if n == nil || n.ArrayBounds == nil {
44+
return 0
45+
}
46+
return len(n.ArrayBounds.Items)
47+
}
48+
4249
func sameType(a, b *ast.TypeName) bool {
4350
if a.Catalog != b.Catalog {
4451
return false
@@ -59,6 +66,9 @@ func sameType(a, b *ast.TypeName) bool {
5966
if a.Name != b.Name {
6067
return false
6168
}
69+
if arrayDims(a) != arrayDims(b) {
70+
return false
71+
}
6272
return true
6373
}
6474

0 commit comments

Comments
 (0)