From 135750a71111d228b1b5c552b20eacb227a663be Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 28 Nov 2021 17:39:45 -0800 Subject: design/43651-type-parameters: absolute difference does not work in 1.18 Change-Id: Ic42e1113c96b087badcb3dcbe6ebd0a6a3460a7d Reviewed-on: https://go-review.googlesource.com/c/proposal/+/367414 Trust: Ian Lance Taylor Reviewed-by: Robert Griesemer --- design/43651-type-parameters.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/design/43651-type-parameters.md b/design/43651-type-parameters.md index 454059e..7ee6dfe 100644 --- a/design/43651-type-parameters.md +++ b/design/43651-type-parameters.md @@ -3875,6 +3875,9 @@ It is intended to show how the common part of algorithms can be factored into code that uses methods, where the exact definition of the methods can vary based on the kind of type being used. +Note: the code used in this example will not work in Go 1.18. +We hope to resolve this and make it work in future releases. + ``` // NumericAbs matches numeric types with an Abs method. type NumericAbs[T any] interface { @@ -3887,7 +3890,7 @@ type NumericAbs[T any] interface { // AbsDifference computes the absolute value of the difference of // a and b, where the absolute value is determined by the Abs method. -func AbsDifference[T NumericAbs](a, b T) T { +func AbsDifference[T NumericAbs[T]](a, b T) T { d := a - b return d.Abs() } -- cgit v1.3