]> Cypherpunks repositories - gostls13.git/commitdiff
text/template improved comparison error addresses issue #71421
authorDiego Lara <diegolara93345@gmail.com>
Fri, 31 Jan 2025 20:57:20 +0000 (20:57 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 3 Feb 2025 16:43:47 +0000 (08:43 -0800)
Addresses issue #71421, improves the error message given for comparison. Previous error message did not specify the types causing conflict, just said incompatible types, new error message specifies the two types causing the issue.

Change-Id: I9d940ab7573c2763a9d052445140ecd6d38cde5e
GitHub-Last-Rev: 6fe7d8101317ea616fd9a8f3f430874b5f946d3e
GitHub-Pull-Request: golang/go#71431
Reviewed-on: https://go-review.googlesource.com/c/go/+/644175
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/text/template/funcs.go

index 7d63cf8b7bb6db3864672e162394d21d6090b83b..4d733135fe5a85e0541f1f04f967a8d9fbdea63f 100644 (file)
@@ -409,7 +409,6 @@ func not(arg reflect.Value) bool {
 
 var (
        errBadComparisonType = errors.New("invalid type for comparison")
-       errBadComparison     = errors.New("incompatible types for comparison")
        errNoComparison      = errors.New("missing argument for comparison")
 )
 
@@ -487,7 +486,7 @@ func eq(arg1 reflect.Value, arg2 ...reflect.Value) (bool, error) {
                                truth = arg.Int() >= 0 && arg1.Uint() == uint64(arg.Int())
                        default:
                                if arg1.IsValid() && arg.IsValid() {
-                                       return false, errBadComparison
+                                       return false, fmt.Errorf("incompatible types for comparison: %v and %v", arg1.Type(), arg.Type())
                                }
                        }
                } else {
@@ -553,7 +552,7 @@ func lt(arg1, arg2 reflect.Value) (bool, error) {
                case k1 == uintKind && k2 == intKind:
                        truth = arg2.Int() >= 0 && arg1.Uint() < uint64(arg2.Int())
                default:
-                       return false, errBadComparison
+                       return false, fmt.Errorf("incompatible types for comparison: %v and %v", arg1.Type(), arg2.Type())
                }
        } else {
                switch k1 {