jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
502 stars 47 forks source link

Panic when using type params in extend, map or default #138

Closed jmattheis closed 7 months ago

jmattheis commented 7 months ago
package structs

// goverter:converter
// goverter:extend Extend
type Converter interface {
    Convert(source Input) (Output, error)
}

func Extend[T any](T) int {
    return 0
}
type Input struct { Age string }
type Output struct { Age int }
panic: unknown types.Type T [recovered]
        panic: unknown types.Type T

goroutine 174 [running]:
testing.tRunner.func1.2({0x75f2c0, 0xc00158c6c0})
        /usr/lib/go/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
        /usr/lib/go/src/testing/testing.go:1634 +0x377
panic({0x75f2c0?, 0xc00158c6c0?})
        /usr/lib/go/src/runtime/panic.go:770 +0x132
github.com/jmattheis/goverter/xtype.TypeOf({0x871620, 0xc000f26ae0})
        /home/jm/src/jmattheis/goverter/xtype/type.go:249 +0x4a5
github.com/jmattheis/goverter/method.Parse({0x875a58?, 0xc0010f9020}, 0xc00003d2d8)
        /home/jm/src/jmattheis/goverter/method/parse.go:64 +0x27f
github.com/jmattheis/goverter/pkgload.(*PackageLoader).getOneParsed(0xc00161c1b0?, {0xc00161c1b0?, 0xc00002c252?}, {0xc00002c252?, 0x795340?}, 0xc00003d2d8)
        /home/jm/src/jmattheis/goverter/pkgload/pkgload.go:123 +0x34
github.com/jmattheis/goverter/pkgload.(*PackageLoader).GetOne(0xc00003dad0, {0xc00161c1b0?, 0xc00002c24d?}, {0xc00002c252?, 0xc00003d268?}, 0xc00003d2d8)
        /home/jm/src/jmattheis/goverter/pkgload/pkgload.go:114 +0x65
github.com/jmattheis/goverter/config.parseMethodLine(0xc00003d9c0, 0xc0015230e0, 0xc000000000, {0xc00002c249, 0x12})
        /home/jm/src/jmattheis/goverter/config/method.go:91 +0x2bc
github.com/jmattheis/goverter/config.parseMethod(0xc00003d9c0, 0xc0015230e0, 0xc0010f9380, {{0xc00080e870, 0x49}, {0xc0003c4440, 0x1, 0x1}})
        /home/jm/src/jmattheis/goverter/config/method.go:63 +0x29c
github.com/jmattheis/goverter/config.parseConverter(0xc00003d9c0, 0xc00003d6f0, {{{0x0, 0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, 0x0, ...}, ...})
        /home/jm/src/jmattheis/goverter/config/converter.go:77 +0x3a7
github.com/jmattheis/goverter/config.Parse(0xc00003db40)
        /home/jm/src/jmattheis/goverter/config/config.go:56 +0x374
github.com/jmattheis/goverter.generateConvertersRaw(0xc00003ddc0)
        /home/jm/src/jmattheis/goverter/runner.go:49 +0x185
github.com/jmattheis/goverter.TestScenario.func1(0xc0003bc680)
        /home/jm/src/jmattheis/goverter/runner_test.go:76 +0x7f6
testing.tRunner(0xc0003bc680, 0xc00038d4f0)
        /usr/lib/go/src/testing/testing.go:1689 +0xfb
created by testing.(*T).Run in goroutine 6
        /usr/lib/go/src/testing/testing.go:1742 +0x390