// Map all types with the same underlying type to the same shape.
u := t.Underlying()
+ // All pointers have the same shape.
+ // TODO: Make unsafe.Pointer the same shape as normal pointers.
+ if u.Kind() == types.TPTR {
+ u = types.Types[types.TUINT8].PtrTo()
+ }
+
if s := shaped[u]; s != nil {
return s //TODO: keep?
}
if t1.sym != nil || t2.sym != nil {
if t1.HasShape() || t2.HasShape() {
switch t1.kind {
- case TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64, TUINT64, TINT, TUINT, TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64, TBOOL, TSTRING, TUNSAFEPTR:
+ case TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64, TUINT64, TINT, TUINT, TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64, TBOOL, TSTRING, TPTR, TUNSAFEPTR:
return true
}
// fall through to unnamed type comparison for complex types.
foo() int
}
-// There should be a single instantiation of f in this program.
+// There should be one instantiation of f for both squarer and doubler.
+// Similarly, there should be one instantiation of f for both *incrementer and *decrementer.
func f[T I](x T) int {
return x.foo()
}
return int(2*x)
}
+type incrementer int16
+
+func (x *incrementer) foo() int {
+ return int(*x+1)
+}
+
+type decrementer int32
+
+func (x *decrementer) foo() int{
+ return int(*x-1)
+}
+
func main() {
println(f(squarer(5)))
println(f(doubler(5)))
+ var i incrementer = 5
+ println(f(&i))
+ var d decrementer = 5
+ println(f(&d))
}