]> Cypherpunks repositories - gostls13.git/commitdiff
test: add another regression test for issue 73309
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 3 Jun 2025 17:04:26 +0000 (00:04 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 4 Jun 2025 14:40:51 +0000 (07:40 -0700)
Fixed #73309

Change-Id: Id715b9c71c95c92143a7fdb5a66b24305346dd3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/678415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/types2/stdlib_test.go
src/go/types/stdlib_test.go
test/fixedbugs/issue73309b.go [new file with mode: 0644]

index 4de698baaf823692808d9ea5db51409ce7af8bf5..35e15d814defbb0a180c936605c025ce2e46d828 100644 (file)
@@ -333,6 +333,7 @@ func TestStdFixed(t *testing.T) {
                "issue56103.go",  // anonymous interface cycles; will be a type checker error in 1.22
                "issue52697.go",  // types2 does not have constraints on stack size
                "issue73309.go",  // this test requires GODEBUG=gotypesalias=1
+               "issue73309b.go", // this test requires GODEBUG=gotypesalias=1
 
                // These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
                // However, types2 does not know about build constraints.
index 633d7be84da7338d81ce861a7bc9f304c9521ec2..8e95d23ec38375b0bee23150e97fff2af07d0e33 100644 (file)
@@ -335,6 +335,7 @@ func TestStdFixed(t *testing.T) {
                "issue56103.go",  // anonymous interface cycles; will be a type checker error in 1.22
                "issue52697.go",  // go/types does not have constraints on stack size
                "issue73309.go",  // this test requires GODEBUG=gotypesalias=1
+               "issue73309b.go", // this test requires GODEBUG=gotypesalias=1
 
                // These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
                // However, go/types does not know about build constraints.
diff --git a/test/fixedbugs/issue73309b.go b/test/fixedbugs/issue73309b.go
new file mode 100644 (file)
index 0000000..1e29781
--- /dev/null
@@ -0,0 +1,88 @@
+// compile
+
+// 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
+
+type Unsigned interface {
+       ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
+}
+
+// a Validator instance
+type Validator []Validable
+
+type Numeric interface {
+       ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64
+}
+
+func (v Validator) Valid() bool {
+       for _, field := range v {
+               if !field.Validate() {
+                       return false
+               }
+       }
+       return true
+}
+
+type Validable interface {
+       Validate() bool
+}
+
+type FieldDef[T any] struct {
+       value T
+       rules []Rule[T]
+}
+
+func (f FieldDef[T]) Validate() bool {
+       for _, rule := range f.rules {
+               if !rule(f) {
+                       return false
+               }
+       }
+       return true
+}
+
+type Rule[T any] = func(FieldDef[T]) bool
+
+func Field[T any](value T, rules ...Rule[T]) *FieldDef[T] {
+       return &FieldDef[T]{value: value, rules: rules}
+}
+
+type StringRule = Rule[string]
+
+type NumericRule[T Numeric] = Rule[T]
+
+type UnsignedRule[T Unsigned] = Rule[T]
+
+func MinS(n int) StringRule {
+       return func(fd FieldDef[string]) bool {
+               return len(fd.value) < n
+       }
+}
+
+func MinD[T Numeric](n T) NumericRule[T] {
+       return func(fd FieldDef[T]) bool {
+               return fd.value < n
+       }
+}
+
+func MinU[T Unsigned](n T) UnsignedRule[T] {
+       return func(fd FieldDef[T]) bool {
+               return fd.value < n
+       }
+}
+
+func main() {
+       v := Validator{
+               Field("test", MinS(5)),
+       }
+
+       if !v.Valid() {
+               println("invalid")
+               return
+       }
+
+       println("valid")
+}