github.com/remobjects/goldbaselibrary@v0.0.0-20230924164425-d458680a936b/Source/Gold/types/testdata/issues.src (about)

     1  // Copyright 2014 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 issues
     6  
     7  import "fmt"
     8  import syn "cmd/compile/internal/syntax"
     9  
    10  func issue7035() {
    11  	type T struct{ X int }
    12  	_ = func() {
    13  		fmt.Println() // must refer to imported fmt rather than the fmt below
    14  	}
    15  	fmt := new(T)
    16  	_ = fmt.X
    17  }
    18  
    19  func issue8066() {
    20  	const (
    21  		_ = float32(340282356779733661637539395458142568447)
    22  		_ = float32(340282356779733661637539395458142568448 /* ERROR cannot convert */ )
    23  	)
    24  }
    25  
    26  // Check that a missing identifier doesn't lead to a spurious error cascade.
    27  func issue8799a() {
    28  	x, ok := missing /* ERROR undeclared */ ()
    29  	_ = !ok
    30  	_ = x
    31  }
    32  
    33  func issue8799b(x int, ok bool) {
    34  	x, ok = missing /* ERROR undeclared */ ()
    35  	_ = !ok
    36  	_ = x
    37  }
    38  
    39  func issue9182() {
    40  	type Point C /* ERROR undeclared */ .Point
    41  	// no error for composite literal based on unknown type
    42  	_ = Point{x: 1, y: 2}
    43  }
    44  
    45  func f0() (a []int)         { return }
    46  func f1() (a []int, b int)  { return }
    47  func f2() (a, b []int)      { return }
    48  
    49  func append_([]int, ...int) {}
    50  
    51  func issue9473(a []int, b ...int) {
    52  	// variadic builtin function
    53  	_ = append(f0())
    54  	_ = append(f0(), f0()...)
    55  	_ = append(f1())
    56  	_ = append(f2 /* ERROR cannot use .* in argument */ ())
    57  	_ = append(f2()... /* ERROR cannot use ... */ )
    58  	_ = append(f0(), f1 /* ERROR 2-valued f1 */ ())
    59  	_ = append(f0(), f2 /* ERROR 2-valued f2 */ ())
    60  	_ = append(f0(), f1 /* ERROR 2-valued f1 */ ()...)
    61  	_ = append(f0(), f2 /* ERROR 2-valued f2 */ ()...)
    62  
    63  	// variadic user-defined function
    64  	append_(f0())
    65  	append_(f0(), f0()...)
    66  	append_(f1())
    67  	append_(f2 /* ERROR cannot use .* in argument */ ())
    68  	append_(f2()... /* ERROR cannot use ... */ )
    69  	append_(f0(), f1 /* ERROR 2-valued f1 */ ())
    70  	append_(f0(), f2 /* ERROR 2-valued f2 */ ())
    71  	append_(f0(), f1 /* ERROR 2-valued f1 */ ()...)
    72  	append_(f0(), f2 /* ERROR 2-valued f2 */ ()...)
    73  }
    74  
    75  // Check that embedding a non-interface type in an interface results in a good error message.
    76  func issue10979() {
    77  	type _ interface {
    78  		int /* ERROR int is not an interface */
    79  	}
    80  	type T struct{}
    81  	type _ interface {
    82  		T /* ERROR T is not an interface */
    83  	}
    84  	type _ interface {
    85  		nosuchtype /* ERROR undeclared name: nosuchtype */
    86  	}
    87  	type _ interface {
    88  		fmt.Nosuchtype /* ERROR Nosuchtype not declared by package fmt */
    89  	}
    90  	type _ interface {
    91  		nosuchpkg /* ERROR undeclared name: nosuchpkg */ .Nosuchtype
    92  	}
    93  	type I interface {
    94  		I /* ERROR I\.m \(value of type func\(I\)\) is not a type */ .m
    95  		m()
    96  	}
    97  }
    98  
    99  // issue11347
   100  // These should not crash.
   101  var a1, b1 /* ERROR cycle */ , c1 /* ERROR cycle */ b1 = 0 > 0<<""[""[c1]]>c1
   102  var a2, b2 /* ERROR cycle */ = 0 /* ERROR cannot initialize */ /* ERROR cannot initialize */ > 0<<""[b2]
   103  var a3, b3 /* ERROR cycle */ = int /* ERROR cannot initialize */ /* ERROR cannot initialize */ (1<<""[b3])
   104  
   105  // issue10260
   106  // Check that error messages explain reason for interface assignment failures.
   107  type (
   108  	I0 interface{}
   109  	I1 interface{ foo() }
   110  	I2 interface{ foo(x int) }
   111  	T0 struct{}
   112  	T1 struct{}
   113  	T2 struct{}
   114  )
   115  
   116  func (*T1) foo() {}
   117  func (*T2) foo(x int) {}
   118  
   119  func issue10260() {
   120  	var (
   121  		i0 I0
   122  		i1 I1
   123  		i2 I2
   124  		t0 *T0
   125  		t1 *T1
   126  		t2 *T2
   127  	)
   128  	i1 = i0 /* ERROR cannot use .* missing method foo */
   129  	i1 = t0 /* ERROR cannot use .* missing method foo */
   130  	i1 = i2 /* ERROR cannot use .* wrong type for method foo */
   131  	i1 = t2 /* ERROR cannot use .* wrong type for method foo */
   132  	i2 = i1 /* ERROR cannot use .* wrong type for method foo */
   133  	i2 = t1 /* ERROR cannot use .* wrong type for method foo */
   134  
   135  	_ = func() I1 { return i0 /* ERROR cannot use .* missing method foo */ }
   136  	_ = func() I1 { return t0 /* ERROR cannot use .* missing method foo */ }
   137  	_ = func() I1 { return i2 /* ERROR cannot use .* wrong type for method foo */ }
   138  	_ = func() I1 { return t2 /* ERROR cannot use .* wrong type for method foo */ }
   139  	_ = func() I2 { return i1 /* ERROR cannot use .* wrong type for method foo */ }
   140  	_ = func() I2 { return t1 /* ERROR cannot use .* wrong type for method foo */ }
   141  
   142  	// a few more - less exhaustive now
   143  
   144  	f := func(I1, I2){}
   145  	f(i0 /* ERROR cannot use .* missing method foo */ , i1 /* ERROR cannot use .* wrong type for method foo */)
   146  
   147  	_ = [...]I1{i0 /* ERROR cannot use .* missing method foo */ }
   148  	_ = [...]I1{i2 /* ERROR cannot use .* wrong type for method foo */ }
   149  	_ = []I1{i0 /* ERROR cannot use .* missing method foo */ }
   150  	_ = []I1{i2 /* ERROR cannot use .* wrong type for method foo */ }
   151  	_ = map[int]I1{0: i0 /* ERROR cannot use .* missing method foo */ }
   152  	_ = map[int]I1{0: i2 /* ERROR cannot use .* wrong type for method foo */ }
   153  
   154  	make(chan I1) <- i0 /* ERROR cannot use .* in send: missing method foo */
   155  	make(chan I1) <- i2 /* ERROR cannot use .* in send: wrong type for method foo */
   156  }
   157  
   158  // Check that constants representable as integers are in integer form
   159  // before being used in operations that are only defined on integers.
   160  func issue14229() {
   161  	// from the issue
   162  	const _ = int64(-1<<63) % 1e6
   163  
   164  	// related
   165  	const (
   166  		a int = 3
   167  		b = 4.0
   168  		_ = a / b
   169  		_ = a % b
   170  		_ = b / a
   171  		_ = b % a
   172  	)
   173  }
   174  
   175  // Check that in a n:1 variable declaration with type and initialization
   176  // expression the type is distributed to all variables of the lhs before
   177  // the initialization expression assignment is checked.
   178  func issue15755() {
   179  	// from issue
   180  	var i interface{}
   181  	type b bool
   182  	var x, y b = i.(b)
   183  	_ = x == y
   184  
   185  	// related: we should see an error since the result of f1 is ([]int, int)
   186  	var u, v []int = f1 /* ERROR cannot use f1 */ ()
   187  	_ = u
   188  	_ = v
   189  }
   190  
   191  // Test that we don't get "declared but not used"
   192  // errors in the context of invalid/C objects.
   193  func issue20358() {
   194  	var F C /* ERROR "undeclared" */ .F
   195  	var A C /* ERROR "undeclared" */ .A
   196  	var S C /* ERROR "undeclared" */ .S
   197  	type T C /* ERROR "undeclared" */ .T
   198  	type P C /* ERROR "undeclared" */ .P
   199  
   200  	// these variables must be "used" even though
   201  	// the LHS expressions/types below in which
   202  	// context they are used are unknown/invalid
   203  	var f, a, s1, s2, s3, t, p int
   204  
   205  	_ = F(f)
   206  	_ = A[a]
   207  	_ = S[s1:s2:s3]
   208  	_ = T{t}
   209  	_ = P{f: p}
   210  }
   211  
   212  // Test that we don't declare lhs variables in short variable
   213  // declarations before we type-check function literals on the
   214  // rhs.
   215  func issue24026() {
   216  	f := func() int { f(0) /* must refer to outer f */; return 0 }
   217  	_ = f
   218  
   219  	_ = func() {
   220  		f := func() { _ = f() /* must refer to outer f */ }
   221  		_ = f
   222  	}
   223  
   224  	// b and c must not be visible inside function literal
   225  	a := 0
   226  	a, b, c := func() (int, int, int) {
   227  		return a, b /* ERROR undeclared */ , c /* ERROR undeclared */
   228  	}()
   229  	_, _ = b, c
   230  }
   231  
   232  func f(int) {} // for issue24026
   233  
   234  // Test that we don't report a "missing return statement" error
   235  // (due to incorrect context when type-checking interfaces).
   236  func issue24140(x interface{}) int {
   237          switch x.(type) {
   238          case interface{}:
   239                  return 0
   240          default:
   241                  panic(0)
   242          }
   243  }
   244  
   245  // Test that we don't crash when the 'if' condition is missing.
   246  func issue25438() {
   247  	if { /* ERROR missing condition */ }
   248  	if x := 0; /* ERROR missing condition */ { _ = x }
   249  	if
   250  	{ /* ERROR missing condition */ }
   251  }
   252  
   253  // Test that we can embed alias type names in interfaces.
   254  type issue25301 interface {
   255  	E
   256  }
   257  
   258  type E = interface {
   259  	m()
   260  }
   261  
   262  // Test case from issue. Eventually we may disallow this due
   263  // to the cycle via the alias type name. But for now we make
   264  // sure this is accepted.
   265  type issue25301b = interface {
   266  	m() interface{ issue25301b }
   267  }
   268  
   269  type issue25301c interface {
   270  	notE // ERROR struct\{\} is not an interface
   271  }
   272  
   273  type notE = struct{}
   274  
   275  // Test that method declarations don't introduce artificial cycles
   276  // (issue #26124).
   277  const CC TT = 1
   278  type TT int
   279  func (TT) MM() [CC]TT
   280  
   281  // Reduced test case from issue #26124.
   282  const preloadLimit LNumber = 128
   283  type LNumber float64
   284  func (LNumber) assertFunction() *LFunction
   285  type LFunction struct {
   286  	GFunction LGFunction
   287  }
   288  type LGFunction func(*LState)
   289  type LState struct {
   290  	reg *registry
   291  }
   292  type registry struct {
   293  	alloc *allocator
   294  }
   295  type allocator struct {
   296  	_ [int(preloadLimit)]int
   297  }
   298  
   299  // Test that we don't crash when type-checking composite literals
   300  // containing errors in the type.
   301  var issue27346 = [][n /* ERROR undeclared */ ]int{
   302  	0: {},
   303  }
   304  
   305  var issue22467 = map[int][... /* ERROR invalid use of ... */ ]int{0: {}}
   306  
   307  // Test that invalid use of ... in parameter lists is recognized
   308  // (issue #28281).
   309  func issue28281a(int, int, ...int)
   310  func issue28281b(a, b int, c ...int)
   311  func issue28281c(a, b, c ... /* ERROR can only use ... with final parameter */ int)
   312  func issue28281d(... /* ERROR can only use ... with final parameter */ int, int)
   313  func issue28281e(a, b, c  ... /* ERROR can only use ... with final parameter */ int, d int)
   314  func issue28281f(... /* ERROR can only use ... with final parameter */ int, ... /* ERROR can only use ... with final parameter */ int, int)
   315  func (... /* ERROR expected type */ TT) f()
   316  func issue28281g() (... /* ERROR expected type */ TT)
   317  
   318  // Issue #26234: Make various field/method lookup errors easier to read by matching cmd/compile's output
   319  func issue26234a(f *syn.File) {
   320  	// The error message below should refer to the actual package path base (syntax)
   321  	// not the local package name (syn).
   322  	f.foo /* ERROR f.foo undefined \(type \*syntax.File has no field or method foo\) */
   323  }
   324  
   325  type T struct {
   326  	x int
   327  	E1
   328  	E2
   329  }
   330  
   331  type E1 struct{ f int }
   332  type E2 struct{ f int }
   333  
   334  func issue26234b(x T) {
   335  	_ = x.f /* ERROR ambiguous selector f */
   336  }
   337  
   338  func issue26234c() {
   339  	T.x /* ERROR T.x undefined \(type T has no method x\) */ ()
   340  }