Skip to content

x/tools/internal/refactor/inline: missing shadowing check when forming qualified identifiers #62667

@adonovan

Description

@adonovan

The inliner fails to detect that the reference to Split in the path.Dir function, which is turned into path.Split in the caller, is shadowed by the parameter name path:

xtools$ go run ./gopls fix -a -d /Users/adonovan/w/xtools/go/buildutil/util.go:#2005 refactor.inline
2023/09/15 17:15:27 inline path.Dir(filepath.ToSlash(filename)) @ /Users/adonovan/w/xtools/go/buildutil/util.go:66:22
2023/09/15 17:15:27 - replace id "Split" @ #42 to "path.Split"
2023/09/15 17:15:27 - replace id "Clean" @ #62 to "path.Clean"
2023/09/15 17:15:27 keeping param "path": argument filepath.ToSlash(filename) is impure
2023/09/15 17:15:27 strategy: literalization
--- /Users/adonovan/w/xtools/go/buildutil/util.go.orig
+++ /Users/adonovan/w/xtools/go/buildutil/util.go
@@ -63,7 +63,10 @@
 	// paths will not use `\` unless the PathSeparator
 	// is also `\`, thus we can rely on filepath.ToSlash for some sanity.
 
-	dirSlash := path.Dir(filepath.ToSlash(filename)) + "/"
+	dirSlash := func(path string) string {
+		dir, _ := path.Split(path)
+		return path.Clean(dir)
+	}(filepath.ToSlash(filename)) + "/"
 
 	// We assume that no source root (GOPATH[i] or GOROOT) contains any other.
 	for _, srcdir := range ctxt.SrcDirs() {
xtools$ 

The fix is to tabulate for each free name all the shadowing definitions (like we do for parameters) and check whether the introduced package name is in that set.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions