goadesign / goa

🌟 Goa: Elevate Go API development! 🚀 Streamlined design, automatic code generation, and seamless HTTP/gRPC support. ✨
https://goa.design
MIT License
5.68k stars 559 forks source link

CopyTo and CreateFrom with sub-structs creates invalid code #1853

Closed dgaedcke closed 6 years ago

dgaedcke commented 6 years ago

Please fill the sections below:

Expected Behavior

Buildable code

Actual Behavior

errors at build are: gen/user/convert.go:74:15: cannot use marshalEmailInfoToEmailInfo(t.EmailInfo) (type EmailInfo) as type user.EmailInfo in assignment gen/user/convert.go:74:46: cannot use t.EmailInfo (type EmailInfo) as type user.EmailInfo in argument to marshalEmailInfoToEmailInfo gen/user/convert.go:77:15: cannot use marshalMobileInfoToPhoneInfo(t.PhoneInfo) (type user.PhoneInfo) as type user.PhoneInfo in assignment gen/user/convert.go:90:17: cannot convert nil to type user.EmailInfo gen/user/convert.go:91:49: cannot use v.EmailInfo (type user.EmailInfo) as type user.EmailInfo in argument to marshalEmailInfoToEmailInfo gen/user/convert.go:93:17: cannot convert nil to type user.PhoneInfo gen/user/convert.go:94:50: cannot use v.PhoneInfo (type user.PhoneInfo) as type user.PhoneInfo in argument to marshalPhoneInfoToMobileInfo gen/user/convert.go:123:54: marshalEmailInfoToEmailInfo redeclared in this block previous declaration at gen/user/convert.go:101:49

Steps to Reproduce the Problem (including complete and simple design if relevant)

Sample design attached Download zip and extract it to: github.com/NewMillennialGames/ run: goa gen github.com/NewMillennialGames/NmgApi/api/design goa example github.com/NewMillennialGames/NmgApi/api/design go build cmd/nmgapi_svc/main.go

you will see the errors above

Specifications

NmgApi.zip

raphael commented 6 years ago

Thank you for the detailed report, the issue is now fixed. Note that there is a limitation where the external type fields that are structs must used pointers. So in the attached code the user model UserInfo and EmailInfo fields must be pointers.

dgaedcke commented 6 years ago

Thanks Raph!!