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

foreach does not work correctly for Int as coins value serialization #1214

Open
Gusarich opened this issue Dec 19, 2024 · 0 comments · May be fixed by #1186
Open

foreach does not work correctly for Int as coins value serialization #1214

Gusarich opened this issue Dec 19, 2024 · 0 comments · May be fixed by #1186
Assignees
Labels
bug Something isn't working or isn't right scope: codegen Code generation, a.k.a. compiler backend scope: maps The map datatype and operations on it
Milestone

Comments

@Gusarich
Copy link
Member

The function below compiles successfully but throws 9 exit code in runtime.

fun f(): Int {
    let m: map<Int, Int as coins> = emptyMap();
    m.set(1, 100);
    m.set(2, 200);

    let sum: Int = 0;
    foreach (k, v in m) {
        sum += k + v;
    }

    return sum;
}

This is due to the fact that there is no coins serialization handling in foreach codegen:

  • if (t.value === "Int") {
    let vBits = 257;
    let vKind = "int";
    if (t.valueAs?.startsWith("int")) {
    vBits = parseInt(t.valueAs.slice(3), 10);
    } else if (t.valueAs?.startsWith("uint")) {
    vBits = parseInt(t.valueAs.slice(4), 10);
    vKind = "uint";
    }
  • if (t.value === "Int") {
    let vBits = 257;
    let vKind = "int";
    if (t.valueAs?.startsWith("int")) {
    vBits = parseInt(t.valueAs.slice(3), 10);
    } else if (t.valueAs?.startsWith("uint")) {
    vBits = parseInt(t.valueAs.slice(4), 10);
    vKind = "uint";
    }
@Gusarich Gusarich added bug Something isn't working or isn't right scope: maps The map datatype and operations on it scope: codegen Code generation, a.k.a. compiler backend labels Dec 19, 2024
@Gusarich Gusarich added this to the v1.6.0 milestone Dec 19, 2024
@Gusarich Gusarich self-assigned this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or isn't right scope: codegen Code generation, a.k.a. compiler backend scope: maps The map datatype and operations on it
Projects
None yet
1 participant