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

wire can not recognize the alias any of interface{} in go 1.18.2 #361

Open
xiazemin opened this issue Jun 2, 2022 · 4 comments
Open

wire can not recognize the alias any of interface{} in go 1.18.2 #361

xiazemin opened this issue Jun 2, 2022 · 4 comments

Comments

@xiazemin
Copy link

xiazemin commented Jun 2, 2022

You can use go bug to have a cool, automatically filled out bug template, or
fill out the template below.

Describe the bug

cannot use (*sql.DB)(db) (value of type *sql.DB) as sqlc.DBTX value in argument to sqlc.New: wrong type for method ExecContext (have func(ctx context.Context, query string, args ...invalid type) (database/sql.Result, error), want func(context.Context, string, ...interface{}) (database/sql.Result, error))

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior.

Expected behavior

A clear and concise description of what you expected to happen.

Version

go1.18.2
Which version of Wire are you seeing the bug with?

Additional context

Add any other context about the problem here.

@xiazemin xiazemin changed the title wire can not recognize the alias any of interface{} in go wire can not recognize the alias any of interface{} in go 1.18.2 Jun 2, 2022
@xiazemin
Copy link
Author

xiazemin commented Jun 2, 2022

go 1.18.2

func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (Result, error) {

lower version

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) {

@jayzhuang
Copy link
Collaborator

Hey @xiazemin, I tried reproing your failure with the following two file, but wire ran successfully for me. Do you have a repro that I can follow?

==> main.go <==
package main

import "fmt"

func NewAny() any {
        return 0
}

func NewTest(any) int {
        return 0
}

func main() {
        fmt.Printf("got %d\n", InitializeTest())
}

==> wire.go <==
//go:build wireinject
// +build wireinject

package main

import "github.com/google/wire"

func InitializeTest() int {
        wire.Build(NewTest, NewAny)
        return 0
}

@pantsmann
Copy link

I believe I have the same or similar error.

First the error message I see (note the file in question is not a wire.go file):
wire: /home/blah/blah/blah.go:290:31: cannot use params (variable of type []interface{}) as []invalid type value in argument to db.Query

The line in question:
params := make([]interface{}, 0)
...
< do stuff like adding items to params and query>
...
rows, err := db.Query(query, params...)`

db.Query is defined with '...any':
func (db *DB) Query(query string, args ...any) (*Rows, error) {

I FIXED it by uninstalling wire and reinstalling wire using go 1.18.4. I think the issue is that wire on my system was compiled long ago before Go 1.18 came out. 'any' was introduced in Go 1.18 so that old existing binary didn't know what 'any' was. It works just fine after cleaning out the old wire binary and reinstalling the same version, but compiled with Go 1.18

@ghost
Copy link

ghost commented Aug 9, 2022

I believe I have the same or similar error.

First the error message I see (note the file in question is not a wire.go file): wire: /home/blah/blah/blah.go:290:31: cannot use params (variable of type []interface{}) as []invalid type value in argument to db.Query

The line in question: params := make([]interface{}, 0) ... < do stuff like adding items to params and query> ... rows, err := db.Query(query, params...)`

db.Query is defined with '...any': func (db *DB) Query(query string, args ...any) (*Rows, error) {

I FIXED it by uninstalling wire and reinstalling wire using go 1.18.4. I think the issue is that wire on my system was compiled long ago before Go 1.18 came out. 'any' was introduced in Go 1.18 so that old existing binary didn't know what 'any' was. It works just fine after cleaning out the old wire binary and reinstalling the same version, but compiled with Go 1.18

I agree and verify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants