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

Fails to compile simple clang-generated WASM file due to list not empty #34

Open
renatoathaydes opened this issue Nov 24, 2019 · 2 comments

Comments

@renatoathaydes
Copy link

renatoathaydes commented Nov 24, 2019

I've got clang to compile this to WASM:

// Filename: add.c
int add(int a, int b) {
  return a + b;
}

When trying to compile to JVM with asmble, it fails:

Caused by: java.util.NoSuchElementException: List is empty.
        at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:360)
        at asmble.io.BinaryToAst.toModule(BinaryToAst.kt:216)
        at asmble.cli.Translate.inToAst(Translate.kt:70)
        at asmble.cli.Compile.run(Compile.kt:54)

This was working with version 0.3.0 but broke in 0.4.0.

This is the code that fails, where you call customSections.last():

if (sectionId != 0) customSections else {
    // If the last section was custom, use the last custom section's after-ID,
    // otherwise just use the last section ID
    val afterSectionId = if (index == 0) 0 else sections[index - 1].let { (prevSectionId, _) ->
    if (prevSectionId == 0) customSections.last().afterSectionId else prevSectionId
}

This code is hard to follow, but looks like customSection starts off empty, so it's likely the last() call is going to be called on the empty list, as is happening to me. Not sure what afterSectionId should be assigned to in that case though, hope you can help find a solution.

@cretz
Copy link
Owner

cretz commented Nov 24, 2019

I haven't been able to focus on this library in a while so I am not sure when I will be able to look.

@renatoathaydes
Copy link
Author

No problem, but thanks for letting me know.

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

No branches or pull requests

2 participants