loader: fix testing a main package

This was broken because multiple packages in the program were named
'main', even one that was imported (by the generated main package).

This fixes tests for main packages.
Этот коммит содержится в:
Ayke van Laethem 2021-06-02 13:14:13 +02:00 коммит произвёл Ron Evans
родитель 98f117fca4
коммит af65c006e6

Просмотреть файл

@ -343,12 +343,11 @@ func (p *Package) Check() error {
checker.Importer = p checker.Importer = p
packageName := p.ImportPath packageName := p.ImportPath
if p.Name == "main" { if p == p.program.MainPkg() {
// The main package normally has a different import path, such as if p.Name != "main" {
// "command-line-arguments" or "./testdata/cgo". Therefore, use the name // Sanity check. Should not ever trigger.
// "main" in such a case: this package isn't imported from anywhere. panic("expected main package to have name 'main'")
// This is safe as it isn't possible to import a package with the name }
// "main".
packageName = "main" packageName = "main"
} }
typesPkg, err := checker.Check(packageName, p.program.fset, p.Files, &p.info) typesPkg, err := checker.Check(packageName, p.program.fset, p.Files, &p.info)