Skip to content
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

cmd/compile: use aliased names in error outputs #33765

Closed
dsnet opened this issue Aug 21, 2019 · 1 comment
Closed

cmd/compile: use aliased names in error outputs #33765

dsnet opened this issue Aug 21, 2019 · 1 comment

Comments

@dsnet
Copy link
Member

dsnet commented Aug 21, 2019

Consider this multi-file snippet:

package main

import "play.ground/foo"

func main() {
	foo.MyFunc()
}
package foo // play.ground/foo

import "play.ground/foo/internal/foo"

type Foo = foo.InternalFoo

func MyFunc(Foo) {}
package foo // play.ground/foo/internal/foo

type InternalFoo int

Compiling this project produces the following error:

# play.ground
./prog.go:6:12: not enough arguments in call to "play.ground/foo".MyFunc
	have ()
	want ("play.ground/foo/internal/foo".InternalFoo)

While technically correct, this error message is unhelpful for the end user since they are unable to access "play.ground/internal/foo".InternalFoo since it is declared in an internal package.

If possible, the compiler should report the name of a type that the user can access. While this is not possible in all cases, a reasonable heuristic is to use the name of the type in the function/method signature. In the example above, it would be "play.ground/foo".Foo.

Currently, I am refactoring a widely used package in a large code base. As part of the migration, I needed to move some types to an internal package. Since the compiler error messages point to the internal declarations, I keep getting repeated requests from users to "externalize" these types. Users do not realize that they are actually already externalized, but through an alias elsewhere. I've already documented on the internal type where to find the external version, but that has not stopped the requests.

@dsnet dsnet changed the title cmd/compile: used aliased names in error outputs cmd/compile: use aliased names in error outputs Aug 21, 2019
@bcmills
Copy link
Contributor

bcmills commented Aug 22, 2019

Duplicate of #21866

@bcmills bcmills marked this as a duplicate of #21866 Aug 22, 2019
@bcmills bcmills closed this as completed Aug 22, 2019
@golang golang locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants