gotranspile / cxgo

Tool for transpiling C to Go.
https://gotranspile.dev
MIT License
328 stars 22 forks source link

calling a function from an array access panics #46

Closed TotallyGamerJet closed 2 years ago

TotallyGamerJet commented 2 years ago

This C code panics:

void foo(void) {}

static void (*functions[1])(void) = {
    foo,
};

void main() {
    functions[0]();
}

with error:

panic: expected type must be set

goroutine 1 [running]:
github.com/gotranspile/cxgo.(*translator).ToFunc(0x1400040ca00, {0x105199000, 0x14000532e10}, 0x0)
        /Users/jarrettkuklis/GolandProjects/cxgo/funcs.go:462 +0x400
github.com/gotranspile/cxgo.(*translator).convertPostfixExpr(0x1400040ca00, 0x1400046edc0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:1013 +0x9a8
github.com/gotranspile/cxgo.(*translator).convertUnaryExpr(0x1400040ca00, 0x14000474540)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:1070 +0x1d4
github.com/gotranspile/cxgo.(*translator).convertCastExpr(0x1400040ca00, 0x14000470bd0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:1052 +0x16c
github.com/gotranspile/cxgo.(*translator).convertMulExpr(0x1400040ca00, 0x14000473880)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:661 +0x18c
github.com/gotranspile/cxgo.(*translator).convertAddExpr(0x1400040ca00, 0x140004738f0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:685 +0x178
github.com/gotranspile/cxgo.(*translator).convertShiftExpr(0x1400040ca00, 0x14000473960)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:707 +0x178
github.com/gotranspile/cxgo.(*translator).convertRelExpr(0x1400040ca00, 0x140004739d0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:729 +0x154
github.com/gotranspile/cxgo.(*translator).convertEqExpr(0x1400040ca00, 0x14000473a40)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:752 +0x118
github.com/gotranspile/cxgo.(*translator).convertAndExpr(0x1400040ca00, 0x14000473ab0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:771 +0x158
github.com/gotranspile/cxgo.(*translator).convertLOrExcExpr(0x1400040ca00, 0x14000473b20)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:787 +0x158
github.com/gotranspile/cxgo.(*translator).convertLOrIncExpr(0x1400040ca00, 0x14000473b90)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:803 +0x158
github.com/gotranspile/cxgo.(*translator).convertLAndExpr(0x1400040ca00, 0x14000459320)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:819 +0x1a4
github.com/gotranspile/cxgo.(*translator).convertLOrExpr(0x1400040ca00, 0x14000459380)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:832 +0x1a4
github.com/gotranspile/cxgo.(*translator).convertCondExpr(0x1400040ca00, 0x14000470c60)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:845 +0x1c4
github.com/gotranspile/cxgo.(*translator).convertAssignExpr(0x1400040ca00, 0x14000470cf0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:1134 +0x218
github.com/gotranspile/cxgo.(*translator).convertExprStmt(0x1400040ca00, 0x14000466740)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:1203 +0x168
github.com/gotranspile/cxgo.(*translator).convertStmt(0x1400040ca00, 0x140004653b0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:1355 +0x54
github.com/gotranspile/cxgo.(*translator).convertCompStmt(0x1400040ca00, 0x14000468270)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:616 +0x90
github.com/gotranspile/cxgo.(*translator).convertCompBlockStmt(0x1400040ca00, 0x14000468270)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:626 +0x30
github.com/gotranspile/cxgo.(*translator).convertFuncDef(0x1400040ca00, 0x140004681a0)
        /Users/jarrettkuklis/GolandProjects/cxgo/convert.go:127 +0x1e8
github.com/gotranspile/cxgo.(*translator).translateC(0x1400040ca00, {0x16b167b4f, 0x2b}, 0x14000460900)
        /Users/jarrettkuklis/GolandProjects/cxgo/translate.go:311 +0x174
github.com/gotranspile/cxgo.(*translator).translate(0x1400040ca00, {0x16b167b4f, 0x2b}, 0x14000460900)
        /Users/jarrettkuklis/GolandProjects/cxgo/translate.go:260 +0x40
github.com/gotranspile/cxgo.TranslateAST({0x16b167b4f, 0x2b}, 0x14000460900, 0x14000246300, {{0x0, 0x0}, {0x105043b8c, 0x4}, {0x14000220120, 0x2c}, ...})
        /Users/jarrettkuklis/GolandProjects/cxgo/translate.go:156 +0x70
github.com/gotranspile/cxgo.Translate({0x0, 0x0}, {0x16b167b4f, 0x2b}, {0x14000220120, 0x24}, 0x14000246300, {{0x0, 0x0}, {0x105043b8c, ...}, ...})
        /Users/jarrettkuklis/GolandProjects/cxgo/translate.go:74 +0x194
main.init.0.func1(0x14000236780, {0x14000210930, 0x1, 0x1})
        /Users/jarrettkuklis/GolandProjects/cxgo/cmd/cxgo/file.go:40 +0x178
github.com/spf13/cobra.(*Command).execute(0x14000236780, {0x14000210900, 0x1, 0x1})
        /Users/jarrettkuklis/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:826 +0x668
github.com/spf13/cobra.(*Command).ExecuteC(0x1053fde40)
        /Users/jarrettkuklis/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/jarrettkuklis/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
main.main()
        /Users/jarrettkuklis/GolandProjects/cxgo/cmd/cxgo/main.go:63 +0x30

Process finished with the exit code 2