GoLand(JetBrains)显示错误消息“ Unresolved Reference”。但是代码编译并运行

问题描述 投票:0回答:1

我正在GoLanguage中做一个项目,并将Jetbrains的GoLand用作IDE。GoLand在IDE中向我显示了一条错误消息(“未解决的引用”),但仍可以编译并正确运行。

这里是我在stackoverflow(Go - append to slice in struct)上找到的一些类似(但更简单)的代码示例。出现相同的错误消息。但是显然我仅在上面几行中实现了该方法。

package main

import (
"fmt"
)

 type MyBoxItem struct {
Name string
 }

 type MyBox struct {
Items []MyBoxItem
 }

func (box *MyBox) AddItem(item MyBoxItem) {
box.Items = append(box.Items, item)
}


 func main() {

item1 := MyBoxItem{Name: "Test Item 1"}
item2 := MyBoxItem{Name: "Test Item 2"}

box := MyBox{}

box.AddItem(item1)
box.AddItem(item2)

// checking the output
fmt.Println(len(box.Items))
fmt.Println(box.Items)
}

box.AddItem(item1)box.AddItem(item2)被标记为红色为错误。如果将光标移到光标上方,它会显示(unresolved reference "AddItem")。但是代码可以编译并运行。并且由于这是另一个stackoverflow问题的解决方案,因此我认为代码不是错误的。此外,我找不到任何错误。

enter image description here

有人可以帮忙吗?非常感谢

[编辑:我从远程服务器加载代码,然后在我的私人PC上进行本地编辑。完成更改后,我将其上传到远程服务器(使用“浏览远程主机”之类的GoLands工具)并在那里进行编译。在使用完全相同的代码在本地尝试后,错误消息有时存在,有时不存在。我完全感到困惑]

go jetbrains-ide goland
1个回答
0
投票

我无法在GoLand 2019.3.1中重现该问题。我建议升级到它。

如果问题仍然存在,请描述问题发生的位置。从屏幕快照中可以看到,该文件看起来像是一个Scratch文件,而不是常规项目文件。

© www.soinside.com 2019 - 2024. All rights reserved.