| 1 |
This is a regression test for bug #63592 in "organize imports" whereby |
| 2 |
the new imports would shadow predeclared names. |
| 3 |
|
| 4 |
In the original example, the conflict was between predeclared error |
| 5 |
type and the unfortunately named package github.com/coreos/etcd/error, |
| 6 |
but this example uses a package with the ludicrous name of complex128. |
| 7 |
|
| 8 |
The new behavior is that we will not attempt to import packages |
| 9 |
that shadow predeclared names. (Ideally we would do that only if |
| 10 |
the predeclared name is actually referenced in the file, which |
| 11 |
complex128 happens to be in this example, but that's a trickier |
| 12 |
analysis than the internal/imports package is game for.) |
| 13 |
|
| 14 |
The name complex127 works as usual. |
| 15 |
|
| 16 |
-- go.mod -- |
| 17 |
module example.com |
| 18 |
go 1.18 |
| 19 |
|
| 20 |
-- complex128/a.go -- |
| 21 |
package complex128 |
| 22 |
|
| 23 |
var V int |
| 24 |
|
| 25 |
-- complex127/a.go -- |
| 26 |
package complex127 |
| 27 |
|
| 28 |
var V int |
| 29 |
|
| 30 |
-- main.go -- |
| 31 |
package main |
| 32 |
|
| 33 |
import () //@codeaction("import", "source.organizeImports", result=out) |
| 34 |
|
| 35 |
func main() { |
| 36 |
complex128.V() //@diag("V", re"type complex128 has no field") |
| 37 |
complex127.V() //@diag("complex127", re"(undeclared|undefined)") |
| 38 |
} |
| 39 |
|
| 40 |
func _() { |
| 41 |
var _ complex128 = 1 + 2i |
| 42 |
} |
| 43 |
-- @out/main.go -- |
| 44 |
package main |
| 45 |
|
| 46 |
import "example.com/complex127" //@codeaction("import", "source.organizeImports", result=out) |
| 47 |
|
| 48 |
func main() { |
| 49 |
complex128.V() //@diag("V", re"type complex128 has no field") |
| 50 |
complex127.V() //@diag("complex127", re"(undeclared|undefined)") |
| 51 |
} |
| 52 |
|
| 53 |
func _() { |
| 54 |
var _ complex128 = 1 + 2i |
| 55 |
} |