Skip to content

Commit

Permalink
Fix named types output.
Browse files Browse the repository at this point in the history
  • Loading branch information
lunemec committed Nov 7, 2022
1 parent 060ddc3 commit d1da70b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions as.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func T[To Number](v any) (To, error) {
err error
out To
)

switch any(out).(type) {
switch any(indirect(out)).(type) {
case int:
var n int
n, err = Int(v)
Expand Down
10 changes: 9 additions & 1 deletion as_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ func TestTCustomType(t *testing.T) {
assertNoError(t, as.T[int], aliasedInt(math.MinInt64))
}

func TestTIntoCustomType(t *testing.T) {
type aliasedInt int
type aliasedIntOut int

assertNoError(t, as.T[aliasedIntOut], aliasedInt(math.MaxInt64))
assertNoError(t, as.T[aliasedIntOut], aliasedInt(math.MinInt64))
}

var out int

// BenchmarkT-8 91144112 12.90 ns/op 8 B/op 0 allocs/op
// After changes to indirect:
// BenchmarkT-8 40429498 29.37 ns/op 16 B/op 1 allocs/op
// BenchmarkT-8 24196993 49.55 ns/op 24 B/op 2 allocs/op
func BenchmarkT(b *testing.B) {
var t int
for n := 0; n < b.N; n++ {
Expand Down

0 comments on commit d1da70b

Please sign in to comment.