4

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.

Eric
  • 22,183
  • 20
  • 145
  • 196
  • It(the function) works? – spike014 Sep 30 '22 at 06:21
  • 1
    @spike014 Yes, it can run successfully. I've added an example. – Eric Sep 30 '22 at 06:24
  • 1
    Have you tried [File -> Invalidate Caches](https://www.jetbrains.com/help/go/invalidate-caches.html) and restarting (as suggested [here](https://stackoverflow.com/a/61356467/11810946))?. – Brits Sep 30 '22 at 07:16
  • If you use IntelliJ with the Go plugin instead of Goland, the solution is the same as the answer but you have to upgrade Intellij first. It will prompt you to update the plugins at the same time. – blackgreen Sep 30 '22 at 10:43

1 Answers1

10

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.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
s0xzwasd
  • 2,895
  • 3
  • 17
  • 26