// package should be complete or marked fake, but be cautious
if imp.complete || imp.fake {
check.impMap[key] = imp
- // Once we've formatted an error message once, keep the pkgPathMap
- // up-to-date on subsequent imports.
+ // Once we've formatted an error message, keep the pkgPathMap
+ // up-to-date on subsequent imports. It is used for package
+ // qualification in error messages.
if check.pkgPathMap != nil {
check.markImports(imp)
}
if s.LocalPkgName != nil {
name = s.LocalPkgName.Value
if path == "C" {
- // match cmd/compile (not prescribed by spec)
+ // match 1.17 cmd/compile (not prescribed by spec)
check.error(s.LocalPkgName, `cannot rename import "C"`)
continue
}
check.recordImplicit(s, pkgName)
}
- if path == "C" {
- // match cmd/compile (not prescribed by spec)
+ if imp.fake {
+ // match 1.17 cmd/compile (not prescribed by spec)
pkgName.used = true
}
// unusedImports checks for unused imports.
func (check *Checker) unusedImports() {
- // if function bodies are not checked, packages' uses are likely missing - don't check
+ // If function bodies are not checked, packages' uses are likely missing - don't check.
if check.conf.IgnoreFuncBodies {
return
}
--- /dev/null
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Ensure there is no "imported but not used" error
+// if a package wasn't imported in the first place.
+
+package p
+
+import . "/foo" // ERROR could not import \/foo
// package should be complete or marked fake, but be cautious
if imp.complete || imp.fake {
check.impMap[key] = imp
- // Once we've formatted an error message once, keep the pkgPathMap
- // up-to-date on subsequent imports.
+ // Once we've formatted an error message, keep the pkgPathMap
+ // up-to-date on subsequent imports. It is used for package
+ // qualification in error messages.
if check.pkgPathMap != nil {
check.markImports(imp)
}
if d.spec.Name != nil {
name = d.spec.Name.Name
if path == "C" {
- // match cmd/compile (not prescribed by spec)
+ // match 1.17 cmd/compile (not prescribed by spec)
check.errorf(d.spec.Name, _ImportCRenamed, `cannot rename import "C"`)
return
}
check.recordImplicit(d.spec, pkgName)
}
- if path == "C" {
- // match cmd/compile (not prescribed by spec)
+ if imp.fake {
+ // match 1.17 cmd/compile (not prescribed by spec)
pkgName.used = true
}
// unusedImports checks for unused imports.
func (check *Checker) unusedImports() {
- // if function bodies are not checked, packages' uses are likely missing - don't check
+ // If function bodies are not checked, packages' uses are likely missing - don't check.
if check.conf.IgnoreFuncBodies {
return
}
--- /dev/null
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Ensure there is no "imported but not used" error
+// if a package wasn't imported in the first place.
+
+package p
+
+import . "/foo" // ERROR could not import \/foo