| 1 |
Just because a package (e.g. log) is imported by the caller, |
| 2 |
and the name log is in scope, doesn't mean the name in scope |
| 3 |
refers to the package: it could be locally shadowed. |
| 4 |
|
| 5 |
In all three scenarios in this file and import-shadow-2.txtar, a renaming |
| 6 |
import with a fresh name is added because the usual name is locally |
| 7 |
shadowed: in cases 1, 2 an existing import is shadowed by (respectively) |
| 8 |
a local constant, parameter; in case 3 there is no existing import. |
| 9 |
|
| 10 |
-- go.mod -- |
| 11 |
module testdata |
| 12 |
go 1.12 |
| 13 |
|
| 14 |
-- a/a.go -- |
| 15 |
package a |
| 16 |
|
| 17 |
import ( |
| 18 |
"testdata/b" |
| 19 |
"log" |
| 20 |
) |
| 21 |
|
| 22 |
func A() { |
| 23 |
const log = "shadow" |
| 24 |
b.B() //@ inline(re"B", bresult) |
| 25 |
} |
| 26 |
|
| 27 |
var _ log.Logger |
| 28 |
|
| 29 |
-- b/b.go -- |
| 30 |
package b |
| 31 |
|
| 32 |
import "log" |
| 33 |
|
| 34 |
func B() { |
| 35 |
log.Printf("") |
| 36 |
} |
| 37 |
|
| 38 |
-- bresult -- |
| 39 |
package a |
| 40 |
|
| 41 |
import ( |
| 42 |
log0 "log" |
| 43 |
|
| 44 |
"log" |
| 45 |
) |
| 46 |
|
| 47 |
func A() { |
| 48 |
const log = "shadow" |
| 49 |
log0.Printf("") //@ inline(re"B", bresult) |
| 50 |
} |
| 51 |
|
| 52 |
var _ log.Logger |