diff --git a/cl/compile.go b/cl/compile.go index 507612745..486d8f4e5 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -832,6 +832,10 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con } parent.tylds = append(parent.tylds, ld) } + + // bugfix: see TestGopxNoFunc + parent.inits = append(parent.inits, ld.load) + ctx.classRecv = &ast.FieldList{List: []*ast.Field{{ Names: []*ast.Ident{ {Name: "this"}, diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go index 3f2e21843..d7ec4bcf4 100644 --- a/cl/compile_spx_test.go +++ b/cl/compile_spx_test.go @@ -239,6 +239,11 @@ func (this *index) onInit() { this.bar() fmt.Println("Hi") } + +type bar struct { + spx.Sprite + *index +} `) } @@ -537,6 +542,11 @@ func (this *Game) MainEntry() { func main() { new(Game).Main() } + +type Kai struct { + spx2.Sprite + *Game +} `, "Game.t2gmx", "Kai.t2spx", "") gopSpxTestExConf(t, "OnlyGmx", &conf, ` var ( @@ -1016,6 +1026,19 @@ func Test_foo(t *testing.T) { `, "main.gox", "foo_xtest.gox", "_test") } +func TestGopxNoFunc(t *testing.T) { + gopClTestFile(t, ` +var ( + a int +) +`, `package main + +type foo struct { + a int +} +`, "foo.gox") +} + func TestClassFileGopx(t *testing.T) { gopClTestFile(t, ` var (