-
Notifications
You must be signed in to change notification settings - Fork 49
fix: align unexported package member diagnostics #2265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,6 +257,7 @@ func loadPackageEx(dedup Deduper, ld *loader, lpkg *loaderPackage) { | |
| return // not a source package, don't get syntax trees | ||
| } | ||
|
|
||
| var packageSelectors map[token.Pos]string | ||
| appendError := func(err error) { | ||
| // Convert various error types into the one true Error. | ||
| var errs []packages.Error | ||
|
|
@@ -285,6 +286,12 @@ func loadPackageEx(dedup Deduper, ld *loader, lpkg *loaderPackage) { | |
|
|
||
| case types.Error: | ||
| // from type checker | ||
| if selector, ok := packageSelectors[err.Pos]; ok { | ||
| name := selector[strings.LastIndexByte(selector, '.')+1:] | ||
| if strings.HasPrefix(err.Msg, "name "+name+" not exported by package ") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rewrite is coupled to go/types' exact diagnostic wording ( |
||
| err.Msg = "undefined: " + selector | ||
| } | ||
| } | ||
| lpkg.TypeErrors = append(lpkg.TypeErrors, err) | ||
| errs = append(errs, packages.Error{ | ||
| Pos: err.Fset.Position(err.Pos).String(), | ||
|
|
@@ -366,6 +373,20 @@ func loadPackageEx(dedup Deduper, ld *loader, lpkg *loaderPackage) { | |
| if ld.Context.Err() != nil { | ||
| return | ||
| } | ||
| packageSelectors = make(map[token.Pos]string) | ||
| for _, file := range files { | ||
| ast.Inspect(file, func(node ast.Node) bool { | ||
| sel, ok := node.(*ast.SelectorExpr) | ||
| if !ok { | ||
| return true | ||
| } | ||
| qualifier, ok := sel.X.(*ast.Ident) | ||
| if ok { | ||
| packageSelectors[sel.Sel.Pos()] = qualifier.Name + "." + sel.Sel.Name | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This records every ident-qualified selector ( |
||
| } | ||
| return true | ||
| }) | ||
| } | ||
|
|
||
| lpkg.TypesInfo = &types.Info{ | ||
| Types: make(map[ast.Expr]types.TypeAndValue), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.