Sample code:
type Integer interface {
~int | ~uint
}
func Loop[I Integer](n I) {
var i I
for i = 0; i < n; i++ { // for loop can be modernized using range over int
println(i)
}
}
Change the code according to the suggestion and of course get a real error:
func Loop[I Integer](n I) {
var i I
for i = range n { // cannot range over n (variable of type I constrained by Integer): int and uint have different underlying types
println(i)
}
}
Sample code:
Change the code according to the suggestion and of course get a real error: