Skip to content

Commit

Permalink
fix: panic on error type (#103)
Browse files Browse the repository at this point in the history
Types in the universe scope (like error) don't have a package.
  • Loading branch information
jmattheis authored Nov 21, 2023
1 parent 2e56a99 commit 62c847c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
30 changes: 30 additions & 0 deletions scenario/universe_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
input:
input.go: |
package universe
// goverter:converter
// goverter:extend Error
type Converter interface {
Error(source *error) *error
}
func Error(value error) error {
return value
}
success:
- generated/generated.go: |
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
package generated
import execution "github.com/jmattheis/goverter/execution"
type ConverterImpl struct{}
func (c *ConverterImpl) Error(source *error) *error {
var pError *error
if source != nil {
xerror := execution.Error((*source))
pError = &xerror
}
return pError
}
32 changes: 32 additions & 0 deletions scenario/universe_type_error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
input:
input.go: |
package universe
// goverter:converter
type Converter interface {
AToB(A) B
}
type A struct {
Property int
}
type B struct {
Property error
}
error: |-
Error while creating converter method:
func (github.com/jmattheis/goverter/execution.Converter).AToB(github.com/jmattheis/goverter/execution.A) github.com/jmattheis/goverter/execution.B
| github.com/jmattheis/goverter/execution.A
|
| | int
| |
source.Property
target.Property
| |
| | error
|
| github.com/jmattheis/goverter/execution.B
TypeMismatch: Cannot convert int to error
10 changes: 8 additions & 2 deletions xtype/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,14 @@ func (t *Type) UnescapedID() string {

func (t *Type) asID(seeNamed, escapeReserved bool) string {
if seeNamed && t.Named {
pkgName := t.NamedType.Obj().Pkg().Name()
name := pkgName + t.NamedType.Obj().Name()
pkg := t.NamedType.Obj().Pkg()
name := t.NamedType.Obj().Name()
switch {
case pkg != nil:
name = pkg.Name() + name
case escapeReserved:
name = "x" + name
}
return name
}
if t.List {
Expand Down

0 comments on commit 62c847c

Please sign in to comment.