Source file test/directive.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  //go:noinline // ERROR "misplaced compiler directive"
    10  
    11  //go:noinline // ERROR "misplaced compiler directive"
    12  package main
    13  
    14  //go:nosplit
    15  func f1() {}
    16  
    17  //go:nosplit
    18  //go:noinline
    19  func f2() {}
    20  
    21  //go:noinline // ERROR "misplaced compiler directive"
    22  
    23  //go:noinline // ERROR "misplaced compiler directive"
    24  var x int
    25  
    26  //go:noinline // ERROR "misplaced compiler directive"
    27  const c = 1
    28  
    29  //go:noinline // ERROR "misplaced compiler directive"
    30  type T int
    31  
    32  // ok
    33  //go:notinheap
    34  type T1 int
    35  
    36  type (
    37  	//go:notinheap
    38  	//go:noinline // ERROR "misplaced compiler directive"
    39  	T2  int
    40  	T2b int
    41  	//go:notinheap
    42  	T2c int
    43  	//go:noinline // ERROR "misplaced compiler directive"
    44  	T3 int
    45  )
    46  
    47  //go:noinline
    48  func f() {
    49  	x := 1
    50  
    51  	{
    52  		_ = x
    53  	}
    54  	//go:noinline // ERROR "misplaced compiler directive"
    55  	var y int
    56  	_ = y
    57  
    58  	//go:noinline // ERROR "misplaced compiler directive"
    59  	const c = 1
    60  
    61  	_ = func() {}
    62  
    63  	//go:noinline // ERROR "misplaced compiler directive"
    64  	// ok:
    65  	//go:notinheap
    66  	type T int
    67  }
    68  
    69  // someday there might be a directive that can apply to type aliases, but go:notinheap doesn't.
    70  //go:notinheap // ERROR "misplaced compiler directive"
    71  type T6 = int
    72  

View as plain text