-
Notifications
You must be signed in to change notification settings - Fork 777
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
Strange error: unsupported reference type: <nil> #2786
Comments
if I change |
Updated desc to reflect issues: |
On a second look, it looks more like arguments are simply not accepted as part of ELSE. It doesn't stop the code generation, but if I change the name of the argument, the argument mentioned in ELSE is not generated as part of the parameter struct. |
First, I noticed that your The issue is that sqlc isn't generated the correct number of parameters for your query. It should be three, not two // Incorrect
func (q *Queries) AddEvent(ctx context.Context, arg AddEventParams) error {
_, err := q.db.Exec(ctx, addEvent, arg.Timezone, arg.CalendarIdKey)
return err
}
// Correct
func (q *Queries) AddEvent(ctx context.Context, arg AddEventParams) error {
_, err := q.db.Exec(ctx, addEvent, arg.Timezone, arg.CalendarIdKey, arg.Timezone)
return err
} Can you confirm that the manually updated Go code works? |
In a case like sqlc/internal/compiler/find_params.go Lines 56 to 219 in b2e42f8
resolveCatalogRefs ignores paramRefs with nil parent and outputs error messages like the one in the description sqlc/internal/compiler/resolve.go Line 603 in b2e42f8
There are two ways to solve this problem.
I think it is better to deal with 1 first, and then deal with 2. This is fundamentally the same problem as #2748. |
This is a compiler problem that occurs with all engines, not just MySQL. |
@kyleconroy indeed, manually adding the same parameter in the list work. As a workaround for my current situation I used a param with different name that I'm assigning the same value. As a secondary issue, I had to write the workaround SQL as
Without the specific convert, it would complain that it can't figure the type |
Fix has been merged, will be included in v1.23.0 |
Version
1.22.0
What happened?
I am trying to generate queries in a local project and it results in this error
unsupported reference type: <nil>
The reason for this is unclear in the sense that the exact same structure/queries works fine in Playground. It only appears locally on my Mac, running go 1.21.1
Now, the code is generated - despite the error showing.
I've tried installing sqlc both with go install and brew, made no difference. I can't figure out what's different between what runs in playground and what runs locally. Or maybe the playground simply ignores that output?
The real issue comes when trying to run the function generated =>
sql: expected 3 arguments, got 2
This is particularly strange because it seems it doesn't recognize arguments with the same name which are part of the same .... scope? I think, because I wrote more complex cases where arguments like
calendarIdKey
were reused in different parts of the same INSERT and they were fine. However, the timezone argument here is taken separately when part of the CASE test vs when it's used to provide the value in ELSE.Relevant log output
`unsupported reference type: <nil>` With debug: https://gist.github.com/andrei-dascalu/700814035f1998de27a80e0203e9657a
Database schema
SQL queries
Configuration
No response
Playground URL
https://play.sqlc.dev/p/296540930cfa87073b096c229df93152bae688b9c997bc70f94b4264928d5464
What operating system are you using?
macOS
What database engines are you using?
MySQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: