@@ -377,6 +377,30 @@ func (g *generator) defineInterface(w *wit.World, dir wit.Direction, i *wit.Inte
377377 return nil
378378}
379379
380+ func (g * generator ) defineAnonymousType (file * gen.File , dir wit.Direction , t wit.Type ) error {
381+ if t .TypeName () != "" {
382+ return nil
383+ }
384+
385+ td , ok := t .(* wit.TypeDef )
386+ if ! ok {
387+ return nil
388+ }
389+
390+ abiFile := g .abiFile (file .Package )
391+
392+ switch td .Kind .(type ) {
393+ case * wit.Result :
394+ println ("!" )
395+ g .declareTypeDef (abiFile , dir , td , g .typeDefGoName (dir , td ))
396+ return g .defineTypeDef (dir , td , "" )
397+ default :
398+ fmt .Printf ("td.Kind.(type) = %T\n " , td .Kind )
399+ }
400+
401+ return nil
402+ }
403+
380404func (g * generator ) defineTypeDef (dir wit.Direction , t * wit.TypeDef , name string ) error {
381405 if ! g .define (dir , t ) {
382406 return nil
@@ -1754,6 +1778,14 @@ func (g *generator) defineImportedFunction(decl *funcDecl) error {
17541778
17551779 file := decl .goFunc .file
17561780
1781+ // Define anonymous types
1782+ for _ , p := range decl .goFunc .params {
1783+ g .defineAnonymousType (file , p .dir , p .typ )
1784+ }
1785+ for _ , p := range decl .goFunc .results {
1786+ g .defineAnonymousType (file , p .dir , p .typ )
1787+ }
1788+
17571789 // Bridging between Go and wasm function
17581790 callParams := slices .Clone (decl .wasmFunc .params )
17591791 for i := range callParams {
@@ -1934,6 +1966,14 @@ func (g *generator) defineExportedFunction(decl *funcDecl) error {
19341966 file := decl .goFunc .file
19351967 scope := g .exportScopes [decl .owner ]
19361968
1969+ // Define anonymous types
1970+ for _ , p := range decl .goFunc .params {
1971+ g .defineAnonymousType (file , p .dir , p .typ )
1972+ }
1973+ for _ , p := range decl .goFunc .results {
1974+ g .defineAnonymousType (file , p .dir , p .typ )
1975+ }
1976+
19371977 // Bridging between wasm and Go function
19381978 callParams := slices .Clone (decl .goFunc .params )
19391979 for i := range callParams {
0 commit comments