x-motemen / gore

Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.
MIT License
5.11k stars 148 forks source link

Cannot use symbols defined by internal packages #184

Closed nekketsuuu closed 4 years ago

nekketsuuu commented 4 years ago

If an internal packages is imported on gore, an error "use of internal package not allowed" occurs after evaluating an expression which uses symbols defined in the internal package.

Steps to reproduce

$ echo $GOPATH
/Users/nekketsuuu/dev
$ pwd
/Users/nekketsuuu/dev/src/github.com/nekketsuuu/gore-internal
$ tree .
.
├── cmd
│   └── main.go
├── go.mod
├── internal
│   └── foo
│       └── foo.go
└── pkg
    └── bar
        └── bar.go

5 directories, 4 files
$ cat ./internal/foo/foo.go 
package foo

import "fmt"

func Hello() {
    fmt.Println("Hello!")
}
$ cat ./pkg/bar/bar.go 
package bar

import "fmt"

func World() {
    fmt.Println("World!")
}
$ cat ./cmd/main.go 
package main

import (
    "github.com/nekketsuuu/gore-internal/internal/foo"
    "github.com/nekketsuuu/gore-internal/pkg/bar"
)

func main() {
    foo.Hello()
    bar.World()
}
$ cat go.mod
module github.com/nekketsuuu/gore-internal

go 1.13
$ go run cmd/main.go  # The internal package can be imported normally from `go run`.
Hello!
World!
$ gore
gore version 0.5.0  :help for help
gore> :import github.com/nekketsuuu/gore-internal/internal/foo
gore> :import github.com/nekketsuuu/gore-internal/pkg/bar
gore> foo.Hello()
use of internal package github.com/nekketsuuu/gore-internal/internal/foo not allowed
gore> bar.World()
use of internal package github.com/nekketsuuu/gore-internal/internal/foo not allowed
gore> 
$ gore
gore version 0.5.0  :help for help
gore> :import github.com/nekketsuuu/gore-internal/pkg/bar
gore> bar.World()
World!
gore> 

Environment

itchyny commented 4 years ago

I don't think we can fix this. Maybe print error quickly on :import command?