| 1 |
This test checks that hovering over a range reveals the expression type. |
| 2 |
|
| 3 |
-- a.go -- |
| 4 |
package a |
| 5 |
|
| 6 |
import "time" |
| 7 |
|
| 8 |
const ( |
| 9 |
_ = 'a' + 2//@hover("'a' + 2", "'a' + 2", "99") |
| 10 |
|
| 11 |
_ = "A" + "B"//@hover("\"A\" + \"B\"", "\"A\" + \"B\"", "AB") |
| 12 |
|
| 13 |
_ = 2 * 3 * 4//@hover("3 * 4", "2 * 3 * 4", "24") |
| 14 |
|
| 15 |
_ = (1 < 2)//@hover("1 < 2", "1 < 2", "true") |
| 16 |
|
| 17 |
_ = (1 + 2i) * (3 + 4i)//@hover("(1 + 2i) * (3 + 4i)", "(1 + 2i) * (3 + 4i)", "(-5 + 10i)") |
| 18 |
) |
| 19 |
|
| 20 |
type Foo struct { |
| 21 |
foo string |
| 22 |
} |
| 23 |
|
| 24 |
func _() { |
| 25 |
// type of slice expression. |
| 26 |
ints := []int{} |
| 27 |
_ = ints[1:2]//@hover("ints[1:2]", "ints[1:2]", "[]int") |
| 28 |
|
| 29 |
foos := []Foo{} |
| 30 |
_ = foos[1:2]//@hover("foos[1:2]", "foos[1:2]", "[]Foo") |
| 31 |
|
| 32 |
// type of map expression |
| 33 |
m := map[string]int{"one": 1} |
| 34 |
_ = m["one"]//@hover("m[\"one\"]", "m[\"one\"]", "int") |
| 35 |
|
| 36 |
// type of channel expression |
| 37 |
ch := make(chan bool) |
| 38 |
_ = <-ch//@hover("<-ch", "<-ch", "bool") |
| 39 |
|
| 40 |
// type of pointer expression |
| 41 |
ptr := &ch//@hover("&ch", "&ch", "*chan bool") |
| 42 |
_ = *ptr//@hover("*ptr", "*ptr", "chan bool") |
| 43 |
|
| 44 |
// type of unary |
| 45 |
_ = -ints[0]//@hover("-ints[0]", "-ints[0]", "int") |
| 46 |
|
| 47 |
// type of type assertion |
| 48 |
var x any |
| 49 |
|
| 50 |
_ = x.(*Foo)//@hover("x.(*Foo)", "x.(*Foo)", "*Foo"),diag(re"x.()", re"nil dereference in type assertion") |
| 51 |
|
| 52 |
// Expression inside of switch statement does not have a type. |
| 53 |
switch x := x.(type) {//@hover("x.(type)",_, _) |
| 54 |
default: |
| 55 |
_ = x |
| 56 |
} |
| 57 |
|
| 58 |
// type of function/method return value. |
| 59 |
_ = time.Now().UTC().Add(10 * time.Minute)//@hover("time.Now().UTC()", "time.Now().UTC()", "time.Time") |
| 60 |
|
| 61 |
// type of function/method signature. |
| 62 |
_ = time.Now().UTC().Add(10 * time.Minute)//@hover("time.Now().UTC", "time.Now().UTC", "func() time.Time") |
| 63 |
|
| 64 |
// type of field |
| 65 |
var t time.Timer |
| 66 |
_ = <-t.C//@hover("t.C", "t.C", "<-chan time.Time"),hover("<-t.C", "<-t.C", "time.Time") |
| 67 |
} |