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:noinline // ERROR "misplaced compiler directive"
    17  type (
    18  	T2  int //go:noinline // ERROR "misplaced compiler directive"
    19  	T2b int
    20  	T2c int
    21  	T3  int
    22  )
    23  
    24  //go:noinline // ERROR "misplaced compiler directive"
    25  type (
    26  	T4 int
    27  )
    28  
    29  //go:noinline // ERROR "misplaced compiler directive"
    30  type ()
    31  
    32  type T5 int
    33  
    34  func g() {} //go:noinline // ERROR "misplaced compiler directive"
    35  
    36  // ok: attached to f (duplicated yes, but ok)
    37  //go:noinline
    38  
    39  //go:noinline
    40  func f() {
    41  	//go:noinline // ERROR "misplaced compiler directive"
    42  	x := 1
    43  
    44  	//go:noinline // ERROR "misplaced compiler directive"
    45  	{
    46  		_ = x //go:noinline // ERROR "misplaced compiler directive"
    47  	}
    48  	var y int //go:noinline // ERROR "misplaced compiler directive"
    49  	//go:noinline // ERROR "misplaced compiler directive"
    50  	_ = y
    51  
    52  	const c = 1
    53  
    54  	_ = func() {}
    55  }
    56  
    57  // EOF
    58  //go:noinline // ERROR "misplaced compiler directive"
    59  

View as plain text