Goland 调试器的问题

Problems with Goland's Debugger

我在 Golang 中遇到了一个奇怪的错误。

OS: Linux Ubuntu 18.04.

CPU: AMD with 64 Bit Support.

IDE is Goland 2018.1.5.

Go version is 1.10.1.

Compiler is set to: 'Any'.

我已经尝试了 'gc' 和 'gccgo' 编译器。结果一样。

在下面的程序中,Debugger 显示奇怪的东西。 'aUnion' 变量里面有 "John",但是里面有 Union 类型的 'aRecord' 变量里面没有 "John"。

如果我 'fmt.Printf' 他们,他们都在那里,但调试器显示 'aRecord' 中没有约翰。 这是调试器的错误吗?

程序非常简单。只是作为指针传递的嵌套结构。

    // 33.go.

    package main

    import "fmt"

    type Person struct {
        Name string
        Age  int
    }
    type GroupOfPeople struct {
        Name   string
        People []*Person
    }
    type Union struct {
        ID    int
        Group *GroupOfPeople
    }
    type Record struct {
        UnionField *Union
        Type       int
    }

    func main() {

        var aPerson *Person
        var people []*Person
        var aGroup *GroupOfPeople
        var aUnion *Union
        var aRecord *Record

        aPerson = &Person{
            Name: "John",
            Age:  10,
        }
        people = []*Person{aPerson}
        aGroup = &GroupOfPeople{
            Name:   "A Group",
            People: people,
        }
        aUnion = &Union{
            ID:    123,
            Group: aGroup,
        } // John is inside 'aUnion'.
        aRecord = &Record{
            UnionField: aUnion,
            Type:       666,
        }
        // John is NOT inside 'aRecord'.
        // WHY ?!
        fmt.Printf("aUnion: %+v.\r\n", aUnion.Group.People[0])
        fmt.Printf("aRecord: %+v.\r\n", aRecord.UnionField.Group.People[0])
    }

感谢您的帮助!

这是 GoLand 如何在运行时处理这些变量值的嵌套的问题。

我创建了 this issue 来跟踪和修复它。

同时,您可以使用 "Watches" 功能来监视 "aRecord.UnionField.Group.People" 作为示例,然后它将正确显示值。抱歉给您带来不便。