nujan-io / nujan-ide

Web IDE, powered by Nujan, is your ultimate browser-based IDE designed to simplify the journey of writing, testing, compiling, deploying, and interacting with smart contracts on TON. Write smart contracts from anywhere, No setups, no downloads, just pure convenience and versatility.
https://ide.nujan.io
Other
98 stars 10 forks source link

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

Closed novusnota closed 1 month ago

novusnota commented 1 month ago

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 commented 1 month ago

Not sure I understand the solution in https://github.com/nujan-io/nujan-ide/commit/09aaa734556bb68de9e2fcf1482dbe367132a25b