blob: cfe4b32ffdf6f9d649ec5d234c51b00fad43b33a [file] [log] [blame]
This test checks that hover reports the sizes of vars/types,
and the offsets of struct fields.
Notes:
- this only works on the declaring identifier, not on refs.
- the size of a type is undefined if it depends on type parameters.
- the offset of a field is undefined if it or any preceding field
has undefined size/alignment.
- the test's size expectations assumes a 64-bit machine.
-- flags --
-skip_goarch=386
-- go.mod --
module example.com
go 1.18
-- a.go --
package a
type T struct {
a int //@ hover("a", "a", a)
U U //@ hover("U", "U", U)
y, z int //@ hover("y", "y", y), hover("z", "z", z)
}
type U struct {
slice []string
}
type G[T any] struct {
p T //@ hover("p", "p", p)
q int //@ hover("q", "q", q)
}
var _ struct {
Gint G[int] //@ hover("Gint", "Gint", Gint)
Gstring G[string] //@ hover("Gstring", "Gstring", Gstring)
}
-- @a --
```go
field a int // size=8, offset=0
```
@ hover("a", "a", a)
-- @U --
```go
field U U // size=24 (0x18), offset=8
```
@ hover("U", "U", U)
[`(a.T).U` on pkg.go.dev](https://pkg.go.dev/example.com#T.U)
-- @y --
```go
field y int // size=8, offset=32 (0x20)
```
@ hover("y", "y", y), hover("z", "z", z)
-- @z --
```go
field z int // size=8, offset=40 (0x28)
```
@ hover("y", "y", y), hover("z", "z", z)
-- @p --
```go
field p T
```
@ hover("p", "p", p)
-- @q --
```go
field q int // size=8
```
@ hover("q", "q", q)
-- @Gint --
```go
field Gint G[int] // size=16 (0x10), offset=0
```
@ hover("Gint", "Gint", Gint)
-- @Gstring --
```go
field Gstring G[string] // size=24 (0x18), offset=16 (0x10)
```
@ hover("Gstring", "Gstring", Gstring)