Skip to content

Commit 0050491

Browse files
authored
Merge pull request #347 from Jorropo/fix-structural-typing
fix panic when packaged go code relies on structural typing
2 parents be58ca3 + 4f1a712 commit 0050491

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

bind/package.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,15 @@ func (p *Package) process() error {
337337
funcs[name] = fv
338338

339339
case *types.TypeName:
340-
named := obj.Type().(*types.Named)
341-
switch typ := named.Underlying().(type) {
340+
typ := obj.Type()
341+
if named, ok := typ.(*types.Named); ok {
342+
typ = named.Underlying()
343+
} else {
344+
// we are dealing with a type alias to a type literal.
345+
// this is a cursed feature used to do structural typing.
346+
// just pass it as-is.
347+
}
348+
switch typ := typ.(type) {
342349
case *types.Struct:
343350
sv, err := newStruct(p, obj)
344351
if err != nil {

0 commit comments

Comments
 (0)