Search code examples
gogoland

Goland shows os.Remove() can't be resolved?


In Goland (2022.1.3), using go (1.19.1), it can't resolve os.Remove(), but if I change to os.RemoveAll(), it's ok.

I've checked go doc and source code, the function does exists.

So, what's wrong ? Is that a goland bug ?

(BTW, I'm using linux os, if that matters.)


Screenshot (in Goland):

goland pic


Update: An example code that can run

package main

import (
    "os"
)

func main() {
    os.Create("/tmp/a.txt")
    os.Remove("/tmp/a.txt")
}

The code can run without error, so I think it's goland's bug.


Solution

  • Go introduces a new build tag unix in Go 1.19, but GoLand lower than 2022.2 doesn't support it natively.

    • Update GoLand to 2022.2.3.
    • Alternatively, add unix build tag in Preferences/Settings | Go | Build Tags & Vendoring | Custom tags.

    If you use IntelliJ with the Go plugin, make sure to upgrade IntelliJ to 2022.2 or above first. It will prompt to upgrade the plugins at the same time.