cors icon indicating copy to clipboard operation
cors copied to clipboard

internal/origin: TestMaxUint16 can be replaced with a compile-time assertion

Open dolmen opened this issue 1 year ago • 1 comments

TestMaxUint16 can be replaced by:

// If this doesn't compile we have a mismatch of maxUint16 and math.MaxUint16
var _ = [1]int{}[maxUint16-math.MaxUint16]

Explanation: the difference between maxUint16 and math.MaxUint16 must be 0.

dolmen avatar Jul 02 '24 10:07 dolmen

Promising! I'll try that. Not that the test in question is prohibitively slow (far from it), but if more things can be checked at compile time, I'm all for it.

jub0bs avatar Jul 02 '24 13:07 jub0bs