Source file test/fixedbugs/issue79236b.go

     1  // run
     2  
     3  // Copyright 2026 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 main
     8  
     9  import "strings"
    10  
    11  type S struct {
    12  	a [3]int
    13  }
    14  
    15  //go:noinline
    16  func f(i int) {
    17  	var x [0]S
    18  	x[i].a[1] = 3
    19  }
    20  
    21  func main() {
    22  	defer func() {
    23  		r := recover()
    24  		if r == nil {
    25  			panic("no panic (bug)")
    26  		}
    27  		got := r.(error).Error()
    28  		if !strings.Contains(got, "index out of range [3] ") {
    29  			panic("unexpected panic: " + got)
    30  		}
    31  	}()
    32  	f(3)
    33  }
    34  

View as plain text