-
Notifications
You must be signed in to change notification settings - Fork 12
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(injector): source import shadowed results in build error "X is not a type" #463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ aspects: | |
}() | ||
|
||
syntheticReferences: | ||
github.com/go-chi/chi/v5: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That reference exists in the original file, so it should be be reported as a synthetic one? It's not a big deal here (it'd be filtered later one due to it already being present in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is part of the idea to mitigate shadowing when dot imports are used |
||
gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5: true | ||
|
||
code: |- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
%YAML 1.1 | ||
--- | ||
aspects: | ||
- id: Register | ||
join-point: | ||
function-call: database/sql.Register | ||
advice: | ||
- wrap-expression: | ||
imports: | ||
sqltrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql | ||
sql: database/sql | ||
driver: database/sql/driver | ||
template: |- | ||
func(driverName string, driver driver.Driver) { | ||
sql.Register(driverName, driver) | ||
sqltrace.Register(driverName, driver) | ||
}({{ index .AST.Args 0 }}, {{ index .AST.Args 1 }}) | ||
|
||
syntheticReferences: | ||
database/sql/driver: true # shadowed import | ||
gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql: true | ||
|
||
code: |- | ||
package test | ||
|
||
import ( | ||
"database/sql" | ||
"database/sql/driver" | ||
) | ||
|
||
var conn driver.Connector | ||
|
||
func main() { | ||
var driver string // shadowing import | ||
sql.Register("foo", nil) | ||
|
||
db1, err := sql.Open("foo", "bar") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db1.Close() | ||
|
||
println(driver) | ||
|
||
db2 := sql.OpenDB(conn) | ||
defer db2.Close() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- input.go | ||
+++ output.go | ||
@@ -1,15 +1,25 @@ | ||
+//line input.go:1:1 | ||
package test | ||
|
||
import ( | ||
"database/sql" | ||
- "database/sql/driver" | ||
+//line <generated>:1 | ||
+ __orchestrion_driver "database/sql/driver" | ||
+ __orchestrion_sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" | ||
) | ||
|
||
-var conn driver.Connector | ||
+//line input.go:8 | ||
+var conn __orchestrion_driver.Connector | ||
|
||
func main() { | ||
var driver string // shadowing import | ||
- sql.Register("foo", nil) | ||
+//line <generated>:1 | ||
+ func(driverName string, driver __orchestrion_driver.Driver) { | ||
+ sql.Register(driverName, driver) | ||
+ __orchestrion_sqltrace.Register(driverName, driver) | ||
+ }( | ||
+//line input.go:12 | ||
+ "foo", nil) | ||
|
||
db1, err := sql.Open("foo", "bar") | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just pass the
c.NodeChain
? That would be equivalent, but incur fewer allocations? (Here you're basically copying a linked list into an array list...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of circular imports :/