| 1 |
// compile |
| 2 |
|
| 3 |
// Copyright 2023 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Issue 57955: ARM assembler fails to handle certain cases. |
| 8 |
|
| 9 |
package main |
| 10 |
|
| 11 |
func main() { |
| 12 |
Decode[int16](nil) |
| 13 |
Decode[uint16](nil) |
| 14 |
Decode[float64](nil) |
| 15 |
} |
| 16 |
|
| 17 |
func DecodeInt16(b []byte) (int16, int) { |
| 18 |
return 0, 0 |
| 19 |
} |
| 20 |
|
| 21 |
func DecodeUint16(b []byte) (uint16, int) { |
| 22 |
return 0, 0 |
| 23 |
} |
| 24 |
|
| 25 |
func DecodeFloat64(b []byte) (float64, int) { |
| 26 |
return 0, 0 |
| 27 |
} |
| 28 |
|
| 29 |
func Decode[T any](b []byte) (T, int) { |
| 30 |
switch any(*new(T)).(type) { |
| 31 |
case int16: |
| 32 |
v, n := DecodeInt16(b) |
| 33 |
return any(v).(T), n |
| 34 |
case uint16: |
| 35 |
v, n := DecodeUint16(b) |
| 36 |
return any(v).(T), n |
| 37 |
case float64: |
| 38 |
v, n := DecodeFloat64(b) |
| 39 |
return any(v).(T), n |
| 40 |
default: |
| 41 |
panic("") |
| 42 |
} |
| 43 |
} |