The function used a global `ticker` variable but never incremented it inside the loop, causing an infinite loop if the first generated name was already in the used set. This fix removes the global state and uses the loop variable `i` directly, which is cleaner and avoids the bug.
20 lines
398 B
Go
20 lines
398 B
Go
package lambda
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.maximhutz.com/max/lambda/pkg/set"
|
|
)
|
|
|
|
// GenerateFreshName generates a variable name that is not in the used set.
|
|
// This function does not mutate the used set.
|
|
func GenerateFreshName(used set.Set[string]) string {
|
|
for i := uint64(0); ; i++ {
|
|
attempt := "_" + string(strconv.AppendUint(nil, i, 10))
|
|
|
|
if !used.Has(attempt) {
|
|
return attempt
|
|
}
|
|
}
|
|
}
|