Source file src/internal/types/testdata/check/lookup1.go
1 // Copyright 2024 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package lookup 6 7 import "math/big" // provides big.Float struct with unexported fields and methods 8 9 func _() { 10 var s struct { 11 x, aBc int 12 } 13 _ = s.x 14 _ = s /* ERROR "invalid operation: cannot call non-function s.x (variable of type int)" */ .x() 15 _ = s.X // ERROR "s.X undefined (type struct{x int; aBc int} has no field or method X, but does have field x)" 16 _ = s.X /* ERROR "s.X undefined (type struct{x int; aBc int} has no field or method X, but does have field x)" */ () 17 18 _ = s.aBc 19 _ = s.abc // ERROR "s.abc undefined (type struct{x int; aBc int} has no field or method abc, but does have field aBc)" 20 _ = s.ABC // ERROR "s.ABC undefined (type struct{x int; aBc int} has no field or method ABC, but does have field aBc)" 21 } 22 23 func _() { 24 type S struct { 25 x int 26 } 27 var s S 28 _ = s.x 29 _ = s /* ERROR "invalid operation: cannot call non-function s.x (variable of type int)" */ .x() 30 _ = s.X // ERROR "s.X undefined (type S has no field or method X, but does have field x)" 31 _ = s.X /* ERROR "s.X undefined (type S has no field or method X, but does have field x)" */ () 32 } 33 34 type S struct { 35 x int 36 } 37 38 func (S) m() {} 39 func (S) aBc() {} 40 41 func _() { 42 var s S 43 _ = s.m 44 s.m() 45 _ = s.M // ERROR "s.M undefined (type S has no field or method M, but does have method m)" 46 s.M /* ERROR "s.M undefined (type S has no field or method M, but does have method m)" */ () 47 48 _ = s.aBc 49 _ = s.abc // ERROR "s.abc undefined (type S has no field or method abc, but does have method aBc)" 50 _ = s.ABC // ERROR "s.ABC undefined (type S has no field or method ABC, but does have method aBc)" 51 } 52 53 func _() { 54 type P *S 55 var s P 56 _ = s.m // ERROR "s.m undefined (type P has no field or method m)" 57 _ = s.M // ERROR "s.M undefined (type P has no field or method M)" 58 _ = s.x 59 _ = s.X // ERROR "s.X undefined (type P has no field or method X, but does have field x)" 60 } 61 62 func _() { 63 var x big.Float 64 _ = x.neg // ERROR "x.neg undefined (type big.Float has no field or method neg, but does have method Neg)" 65 _ = x.nEg // ERROR "x.nEg undefined (type big.Float has no field or method nEg)" 66 _ = x.Neg 67 _ = x.NEg // ERROR "x.NEg undefined (type big.Float has no field or method NEg, but does have method Neg)" 68 69 _ = x.form // ERROR "x.form undefined (cannot refer to unexported field form)" 70 _ = x.fOrm // ERROR "x.fOrm undefined (type big.Float has no field or method fOrm)" 71 _ = x.Form // ERROR "x.Form undefined (type big.Float has no field or method Form, but does have unexported field form)" 72 _ = x.FOrm // ERROR "x.FOrm undefined (type big.Float has no field or method FOrm)" 73 } 74