-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(injector): source import shadowed results in build error "X is no…
…t a type" (#463) ### What Previously we would only check if the import was present in a fix. Now, we are checking if import is accessible as the import we are looking for. ### References Fixes #458 Fixes #448 Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
- Loading branch information
1 parent
5e5d184
commit 4d4eb9b
Showing
7 changed files
with
173 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
internal/injector/testdata/injector/import-shadowing/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
31 changes: 31 additions & 0 deletions
31
internal/injector/testdata/injector/import-shadowing/expected.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters