Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes on enum with full comment #556

Closed
starius opened this issue Jan 11, 2018 · 1 comment
Closed

Crashes on enum with full comment #556

starius opened this issue Jan 11, 2018 · 1 comment

Comments

@starius
Copy link

starius commented Jan 11, 2018

/**
 * Comment
 */
typedef enum foo {
    bar = 1
} foo;

int main() {
}

Problematic piece of AST:

|-EnumDecl 0x5fd8be673708 <1.c:4:9, line:6:1> line:4:14 foo
| |-FullComment 0x5fd8be673ae0 <line:2:3, col:10>
| | `-ParagraphComment 0x5fd8be673ab0 <col:3, col:10>
| |   `-TextComment 0x5fd8be673a80 <col:3, col:10> Text=" Comment"
| `-EnumConstantDecl 0x5fd8be6737e0 <line:5:5, col:11> col:5 bar 'int'
|   `-IntegerLiteral 0x5fd8be6737c0 <col:11> 'int' 1

Error:

panic: interface conversion: ast.Node is *ast.FullComment, not *ast.EnumConstantDecl

goroutine 1 [running]:
github.com/elliotchance/c2go/transpiler.transpileEnumDecl(0xc4200fe000, 0xc4200da500, 0xc420043490, 0xc4200fe000, 0x6dd920, 0xc4200da500, 0x0)
	c2go/transpiler/enum.go:222 +0x20d8
github.com/elliotchance/c2go/transpiler.transpileToNode(0x6dd920, 0xc4200da500, 0xc4200fe000, 0x0, 0x0, 0x0, 0x0, 0x0)
	c2go/transpiler/transpiler.go:487 +0x1fc

Fix:

diff --git a/transpiler/enum.go b/transpiler/enum.go
index 800182a..f812445 100644
--- a/transpiler/enum.go
+++ b/transpiler/enum.go
@@ -219,7 +219,11 @@ func transpileEnumDecl(p *program.Program, n *ast.EnumDecl) (decls []goast.Decl,
        // counter for replace iota
        var counter int
        for i, c := range n.Children() {
-               e, newPre, newPost := transpileEnumConstantDecl(p, c.(*ast.EnumConstantDecl))
+               cd, ok := c.(*ast.EnumConstantDecl)
+               if !ok {
+                       continue
+               }
+               e, newPre, newPost := transpileEnumConstantDecl(p, cd)
                preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, newPre, newPost)
 
                e.Names[0].Obj = goast.NewObj(goast.Con, e.Names[0].Name)
@elliotchance
Copy link
Owner

Thanks for raising this @starius. It look like @Konstantin8105 already has a fix for this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants