Update to go1.24.2
This commit is contained in:
85
test/fixedbugs/issue72090.go
Normal file
85
test/fixedbugs/issue72090.go
Normal file
@@ -0,0 +1,85 @@
|
||||
// build
|
||||
|
||||
// Copyright 2025 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"iter"
|
||||
)
|
||||
|
||||
type leafSet map[rune]struct{}
|
||||
|
||||
type branchMap map[rune]*node
|
||||
|
||||
func (bm branchMap) findOrCreateBranch(r rune) *node {
|
||||
if _, ok := bm[r]; !ok {
|
||||
bm[r] = newNode()
|
||||
}
|
||||
return bm[r]
|
||||
}
|
||||
|
||||
func (bm branchMap) allSuffixes() iter.Seq[string] {
|
||||
return func(yield func(string) bool) {
|
||||
for r, n := range bm {
|
||||
for s := range n.allStrings() {
|
||||
if !yield(string(r) + s) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type node struct {
|
||||
leafSet
|
||||
branchMap
|
||||
}
|
||||
|
||||
func newNode() *node {
|
||||
return &node{make(leafSet), make(branchMap)}
|
||||
}
|
||||
|
||||
func (n *node) add(s []rune) {
|
||||
switch len(s) {
|
||||
case 0:
|
||||
return
|
||||
case 1:
|
||||
n.leafSet[s[0]] = struct{}{}
|
||||
default:
|
||||
n.branchMap.findOrCreateBranch(s[0]).add(s[1:])
|
||||
}
|
||||
}
|
||||
|
||||
func (n *node) addString(s string) {
|
||||
n.add([]rune(s))
|
||||
}
|
||||
|
||||
func (n *node) allStrings() iter.Seq[string] {
|
||||
return func(yield func(string) bool) {
|
||||
for s := range n.leafSet {
|
||||
if !yield(string(s)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for r, n := range n.branchMap {
|
||||
for s := range n.allSuffixes() {
|
||||
if !yield(string(r) + s) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
root := newNode()
|
||||
for _, s := range []string{"foo", "bar", "baz", "a", "b", "c", "hello", "world"} {
|
||||
root.addString(s)
|
||||
}
|
||||
for s := range root.allStrings() {
|
||||
println(s)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// errorcheck -0 -m=2
|
||||
// errorcheck -0 -m
|
||||
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
@@ -15,7 +15,7 @@ func caninline(x int) int { // ERROR "can inline caninline"
|
||||
return x
|
||||
}
|
||||
|
||||
func cannotinline(b *testing.B) { // ERROR "b does not escape" "cannot inline cannotinline.*"
|
||||
func test(b *testing.B) { // ERROR "leaking param: b"
|
||||
for i := 0; i < b.N; i++ {
|
||||
caninline(1) // ERROR "inlining call to caninline"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user