...

Source file src/internal/types/testdata/check/importC.go

Documentation: internal/types/testdata/check

     1  // -fakeImportC
     2  
     3  // Copyright 2015 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package importC
     8  
     9  import "C"
    10  import _ /* ERROR `cannot rename import "C"` */ "C"
    11  import foo /* ERROR `cannot rename import "C"` */ "C"
    12  import . /* ERROR `cannot rename import "C"` */ "C"
    13  
    14  // Test cases extracted from issue #22090.
    15  
    16  import "unsafe"
    17  
    18  const _ C.int = 0xff // no error due to invalid constant type
    19  
    20  type T struct {
    21  	Name    string
    22  	Ordinal int
    23  }
    24  
    25  func _(args []T) {
    26  	var s string
    27  	for i, v := range args {
    28  		cname := C.CString(v.Name)
    29  		args[i].Ordinal = int(C.sqlite3_bind_parameter_index(s, cname)) // no error due to i not being "used"
    30  		C.free(unsafe.Pointer(cname))
    31  	}
    32  }
    33  
    34  type CType C.Type
    35  
    36  const _ CType = C.X // no error due to invalid constant type
    37  const _ = C.X
    38  
    39  // Test cases extracted from issue #23712.
    40  
    41  func _() {
    42  	var a [C.ArrayLength]byte
    43  	_ = a[0] // no index out of bounds error here
    44  }
    45  
    46  // Additional tests to verify fix for #23712.
    47  
    48  func _() {
    49  	var a [C.ArrayLength1]byte
    50  	_ = 1 / len(a) // no division by zero error here and below
    51  	_ = 1 / cap(a)
    52  	_ = uint(unsafe.Sizeof(a)) // must not be negative
    53  
    54  	var b [C.ArrayLength2]byte
    55  	a = b // should be valid
    56  }
    57  

View as plain text