Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): fix typename comparison in function overloading #3661

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE FUNCTION foo(bar TEXT) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
CREATE FUNCTION foo(bar TEXT[]) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
CREATE FUNCTION foo(bar INTEGER) RETURNS TEXT AS $$ SELECT 'baz' $$ LANGUAGE sql;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE FUNCTION foo(bar TEXT) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
CREATE FUNCTION foo(bar TEXT[]) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;
CREATE FUNCTION foo(bar INTEGER) RETURNS TEXT AS $$ SELECT 'baz' $$ LANGUAGE sql;
7 changes: 6 additions & 1 deletion internal/engine/postgresql/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,21 @@ func translate(node *nodes.Node) (ast.Node, error) {
for _, item := range n.Parameters {
arg := item.Node.(*nodes.Node_FunctionParameter).FunctionParameter
rel, err := parseRelationFromNodes(arg.ArgType.Names)

relType := rel.TypeName()
relType.ArrayBounds = convertSlice(arg.ArgType.ArrayBounds)

if err != nil {
return nil, err
}
mode, err := convertFuncParamMode(arg.Mode)
if err != nil {
return nil, err
}

fp := &ast.FuncParam{
Name: &arg.Name,
Type: rel.TypeName(),
Type: relType,
Mode: mode,
}
if arg.Defexpr != nil {
Expand Down
10 changes: 10 additions & 0 deletions internal/sql/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func (ct *CompositeType) SetComment(c string) {
ct.Comment = c
}

func arrayDims(n *ast.TypeName) int {
if n == nil || n.ArrayBounds == nil {
return 0
}
return len(n.ArrayBounds.Items)
}

func sameType(a, b *ast.TypeName) bool {
if a.Catalog != b.Catalog {
return false
Expand All @@ -59,6 +66,9 @@ func sameType(a, b *ast.TypeName) bool {
if a.Name != b.Name {
return false
}
if arrayDims(a) != arrayDims(b) {
return false
}
return true
}

Expand Down
Loading