Source file test/directive2.go

     1  // errorcheck
     2  
     3  // Copyright 2020 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  // Verify that misplaced directives are diagnosed.
     8  
     9  // ok
    10  //go:build !ignore
    11  
    12  package main
    13  
    14  //go:build bad // ERROR "misplaced compiler directive"
    15  
    16  //go:notinheap // ERROR "misplaced compiler directive"
    17  type (
    18  	T2  int //go:notinheap // ERROR "misplaced compiler directive"
    19  	T2b int
    20  	T2c int
    21  	T3  int
    22  )
    23  
    24  //go:notinheap // ERROR "misplaced compiler directive"
    25  type (
    26  	//go:notinheap
    27  	T4 int
    28  )
    29  
    30  //go:notinheap // ERROR "misplaced compiler directive"
    31  type ()
    32  
    33  type T5 int
    34  
    35  func g() {} //go:noinline // ERROR "misplaced compiler directive"
    36  
    37  // ok: attached to f (duplicated yes, but ok)
    38  //go:noinline
    39  
    40  //go:noinline
    41  func f() {
    42  	//go:noinline // ERROR "misplaced compiler directive"
    43  	x := 1
    44  
    45  	//go:noinline // ERROR "misplaced compiler directive"
    46  	{
    47  		_ = x //go:noinline // ERROR "misplaced compiler directive"
    48  	}
    49  	var y int //go:noinline // ERROR "misplaced compiler directive"
    50  	//go:noinline // ERROR "misplaced compiler directive"
    51  	_ = y
    52  
    53  	const c = 1
    54  
    55  	_ = func() {}
    56  
    57  	// ok:
    58  	//go:notinheap
    59  	type T int
    60  }
    61  
    62  // EOF
    63  //go:noinline // ERROR "misplaced compiler directive"
    64  

View as plain text