mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
loader: don't panic when main package is not named 'main'
This can in fact happen in practice, so return an actual error message instead.
This commit is contained in:
@@ -24,6 +24,7 @@ func TestErrors(t *testing.T) {
|
|||||||
{name: "cgo"},
|
{name: "cgo"},
|
||||||
{name: "compiler"},
|
{name: "compiler"},
|
||||||
{name: "interp"},
|
{name: "interp"},
|
||||||
|
{name: "invalidmain"},
|
||||||
{name: "linker-flashoverflow", target: "cortex-m-qemu"},
|
{name: "linker-flashoverflow", target: "cortex-m-qemu"},
|
||||||
{name: "linker-ramoverflow", target: "cortex-m-qemu"},
|
{name: "linker-ramoverflow", target: "cortex-m-qemu"},
|
||||||
{name: "linker-undefined", target: "darwin/arm64"},
|
{name: "linker-undefined", target: "darwin/arm64"},
|
||||||
|
|||||||
+6
-2
@@ -418,8 +418,12 @@ func (p *Package) Check() error {
|
|||||||
packageName := p.ImportPath
|
packageName := p.ImportPath
|
||||||
if p == p.program.MainPkg() {
|
if p == p.program.MainPkg() {
|
||||||
if p.Name != "main" {
|
if p.Name != "main" {
|
||||||
// Sanity check. Should not ever trigger.
|
return Errors{p, []error{
|
||||||
panic("expected main package to have name 'main'")
|
scanner.Error{
|
||||||
|
Pos: p.program.fset.Position(p.Files[0].Name.Pos()),
|
||||||
|
Msg: fmt.Sprintf("expected main package to have name \"main\", not %#v", p.Name),
|
||||||
|
},
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
packageName = "main"
|
packageName = "main"
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// some comment to move the first line
|
||||||
|
|
||||||
|
package foobar
|
||||||
|
|
||||||
|
// ERROR: # command-line-arguments
|
||||||
|
// ERROR: invalidmain.go:3:9: expected main package to have name "main", not "foobar"
|
||||||
Reference in New Issue
Block a user