Skip to content

Commit eb05ff6

Browse files
authored
Merge pull request #195 from jmattheis/nested-alias
fix: crash with panic: unsupported type any
2 parents 732c090 + 135cfab commit eb05ff6

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ jobs:
3030
files: ./filtered-coverage.txt
3131
env:
3232
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
33+
test_latest_xtools:
34+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name)
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/setup-go@v5
38+
with:
39+
go-version: 1.24.x
40+
- uses: actions/checkout@v4
41+
- run: |
42+
go get -u golang.org/x/tools
43+
go mod tidy
44+
- run: go test ./...
45+
env:
46+
SKIP_VERSION_DEPENDENT: 'true'
3347
test_go122:
3448
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.repository != github.event.pull_request.head.repo.full_name)
3549
runs-on: ubuntu-latest

scenario/nested_alias.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
version_dependent: true
2+
input:
3+
input.go: |
4+
package alias
5+
6+
// goverter:converter
7+
// goverter:extend AnyAny
8+
type Converter interface {
9+
A(source map[string]InputAlias) map[string]OutputAlias
10+
B(source map[string]any) map[string]any
11+
C(source struct{A InputAlias}) struct{A OutputAlias}
12+
D(source []GenAlias[string]) []GenAlias[string]
13+
}
14+
15+
func AnyAny(a any) any {
16+
return a
17+
}
18+
19+
type GenAlias[T any] []T
20+
type InputAlias = string
21+
type OutputAlias = string
22+
success:
23+
- generated/generated.go: |
24+
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
25+
26+
package generated
27+
28+
import execution "github.com/jmattheis/goverter/execution"
29+
30+
type ConverterImpl struct{}
31+
32+
func (c *ConverterImpl) A(source map[string]string) map[string]string {
33+
var mapStringString map[string]string
34+
if source != nil {
35+
mapStringString = make(map[string]string, len(source))
36+
for key, value := range source {
37+
mapStringString[key] = value
38+
}
39+
}
40+
return mapStringString
41+
}
42+
func (c *ConverterImpl) B(source map[string]interface{}) map[string]interface{} {
43+
var mapStringUnknown map[string]interface{}
44+
if source != nil {
45+
mapStringUnknown = make(map[string]interface{}, len(source))
46+
for key, value := range source {
47+
mapStringUnknown[key] = execution.AnyAny(value)
48+
}
49+
}
50+
return mapStringUnknown
51+
}
52+
func (c *ConverterImpl) C(source struct {
53+
A string
54+
}) struct {
55+
A string
56+
} {
57+
var unnamed struct {
58+
A string
59+
}
60+
unnamed.A = source.A
61+
return unnamed
62+
}
63+
func (c *ConverterImpl) D(source []execution.GenAlias[string]) []execution.GenAlias[string] {
64+
var aliasGenAliasList []execution.GenAlias[string]
65+
if source != nil {
66+
aliasGenAliasList = make([]execution.GenAlias[string], len(source))
67+
for i := 0; i < len(source); i++ {
68+
aliasGenAliasList[i] = c.aliasGenAliasToAliasGenAlias(source[i])
69+
}
70+
}
71+
return aliasGenAliasList
72+
}
73+
func (c *ConverterImpl) aliasGenAliasToAliasGenAlias(source execution.GenAlias[string]) execution.GenAlias[string] {
74+
var aliasGenAlias execution.GenAlias[string]
75+
if source != nil {
76+
aliasGenAlias = make(execution.GenAlias[string], len(source))
77+
for i := 0; i < len(source); i++ {
78+
aliasGenAlias[i] = source[i]
79+
}
80+
}
81+
return aliasGenAlias
82+
}

xtype/tocode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
func toCode(t types.Type) *jen.Statement {
11+
t = types.Unalias(t)
1112
switch cast := t.(type) {
1213
case *types.Named:
1314
return toCodeNamed(cast)

0 commit comments

Comments
 (0)