diff options
author | Ayke van Laethem <[email protected]> | 2021-01-13 17:00:08 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-01-15 14:43:43 +0100 |
commit | dbc438b2ae23414241b693b03697410248b44768 (patch) | |
tree | f936759d7fe1767c9a75b124b72934aedf45365f /loader | |
parent | c4d642007e6747ef9425471c16536617ac2d1ca5 (diff) | |
download | tinygo-dbc438b2ae23414241b693b03697410248b44768.tar.gz tinygo-dbc438b2ae23414241b693b03697410248b44768.zip |
loader: use name "main" for the main package
This should make exported names a bit more consistent.
I believe there was a bug report for this issue, but I can't easily find
it. In any case, I think it's an important improvement to match the
behavior of the Go toolchain.
Diffstat (limited to 'loader')
-rw-r--r-- | loader/loader.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/loader/loader.go b/loader/loader.go index 847acc258..d25b08a91 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -43,6 +43,7 @@ type Program struct { type PackageJSON struct { Dir string ImportPath string + Name string ForTest string // Source files @@ -335,7 +336,16 @@ func (p *Package) Check() error { // Do typechecking of the package. checker.Importer = p - typesPkg, err := checker.Check(p.ImportPath, p.program.fset, p.Files, &p.info) + packageName := p.ImportPath + if p.Name == "main" { + // The main package normally has a different import path, such as + // "command-line-arguments" or "./testdata/cgo". Therefore, use the name + // "main" in such a case: this package isn't imported from anywhere. + // This is safe as it isn't possible to import a package with the name + // "main". + packageName = "main" + } + typesPkg, err := checker.Check(packageName, p.program.fset, p.Files, &p.info) if err != nil { if err, ok := err.(Errors); ok { return err |