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

**🐞 Describe the bug** #225

Closed
Khaterehnajafi opened this issue Dec 31, 2024 · 1 comment
Closed

**🐞 Describe the bug** #225

Khaterehnajafi opened this issue Dec 31, 2024 · 1 comment

Comments

@Khaterehnajafi
Copy link

🐞 Describe the bug
There's an error when compiling at line counter = counter+1; that says:

./contracts/main.fc:5:15: error: undefined function `counter+1`, defining a global function of unknown type
      counter = counter+1;
                ^
Compilation error
Func compilation error: ./contracts/main.fc:5:24: error: cannot assign an expression of type ??2 -> ??3 to a variable or pattern of type int: cannot unify type int with ??2 -> ??3
      counter = counter+1;

the error can be fixed by adding spaces: counter = counter + 1;
Is this intended behaviour? To me it looks like a bug, because those spaces should not impact the compilation process.

💻 Environment
Node.js v18.16.0 with package "@ton-community/func-js": "^0.7.0",

🔢 Code to reproduce bug
main.fc

() recv_internal(int msg_value, cell in_msg, slice in_msg_body) impure {
    int counter = 1;
    counter = counter+1;
}

compile.ts

import * as fs from "fs";
import process from "process";
import { Cell } from "ton-core";
import { compileFunc } from "@ton-community/func-js";

async function compileScript() {
  console.log("Compile script is running...");
  const compileResult = await compileFunc({
    targets: ["./contracts/main.fc"],
    sources: (x) => fs.readFileSync(x).toString("utf8"),
  });

  if (compileResult.status === "error") {
    console.error("Compilation error");
    console.error(compileResult.message);
    process.exit(1);
  }

  console.error("Compilation successful");

  const hex = Cell.fromBoc(Buffer.from(compileResult.codeBoc, "base64"))[0]
    .toBoc()
    .toString("hex");

  fs.writeFileSync(
    "build/main.compiled.json",
    JSON.stringify({
      hex,
    })
  );
}

compileScript();

Originally posted by @andrewslock in ton-community/func-js#26

@andrewslock
Copy link

I think it's intended behaviour because FunC supports various symbols like +-_:./?!~ in a variable's name. So the compiler interprets counter+1 as a reference to a variable "counter+1" which does not exist, meaning that a code like this should work:

() recv_internal(int msg_value, cell in_msg, slice in_msg_body) impure {
    int counter+1 = 1;
    counter+1 = counter+1 + 1;
}

crazy right?

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