tg.cd(tg.path("src/rsc.io"))
        tg.run("get", "./toolstash")
 }
+
+// Test that you can not import a main package.
+func TestIssue4210(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.tempFile("src/x/main.go", `package main
+               var X int
+               func main() {}`)
+       tg.tempFile("src/y/main.go", `package main
+               import "fmt"
+               import xmain "x"
+               func main() {
+                       fmt.Println(xmain.X)
+               }`)
+       tg.setenv("GOPATH", tg.path("."))
+       tg.runFail("build", "y")
+       tg.grepBoth("is a program", `did not find expected error message ("is a program")`)
+}
 
                        continue
                }
                p1 := loadImport(path, p.Dir, stk, p.build.ImportPos[path])
+               if p1.Name == "main" {
+                       p.Error = &PackageError{
+                               ImportStack: stk.copy(),
+                               Err:         fmt.Sprintf("import %q is a program, not an importable package", path),
+                       }
+                       pos := p.build.ImportPos[path]
+                       if len(pos) > 0 {
+                               p.Error.Pos = pos[0].String()
+                       }
+               }
                if p1.local {
                        if !p.local && p.Error == nil {
                                p.Error = &PackageError{