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

Bug: code with foreach loops doesn't compile #34

Closed
novusnota opened this issue May 5, 2024 · 1 comment
Closed

Bug: code with foreach loops doesn't compile #34

novusnota opened this issue May 5, 2024 · 1 comment

Comments

@novusnota
Copy link

For example, the following:

import "@stdlib/deploy"; // for Deployable trait

fun mapTest(): Int {
    let m: map<Int, Cell> = emptyMap();

    m.set(1, beginCell().storeUint(100, 16).endCell());
    m.set(2, beginCell().storeUint(200, 16).endCell());
    m.set(3, beginCell().storeUint(300, 16).endCell());
    m.set(4, beginCell().storeUint(400, 16).endCell());

    let sum: Int = 0;
    foreach (k, v in m) {
        let s: Slice = v.beginParse(); // convert Cell to Slice
        sum += s.loadUint(16);         // sum the Slice values
    }

    return sum; // 1000
}

contract ForeachExample with Deployable {
    // notice the lack of explicit empty init() -- a feature of Tact 1.3.0
    get fun mapTest(): Int {
        return mapTest();
    }
}

gives non-descriptive error message while building: Error while building. Removing the foreach loop runs the build. Additionally, local compilation of such code works too, with or without foreach.

@anton-trunov
Copy link

Not sure I understand the solution in 09aaa73

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