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

Constant initialization must be moved after typechecking #1655

Open
jeshecdom opened this issue Jan 31, 2025 · 0 comments · May be fixed by #1678
Open

Constant initialization must be moved after typechecking #1655

jeshecdom opened this issue Jan 31, 2025 · 0 comments · May be fixed by #1678
Assignees
Labels
scope: typechecker Implementation of typechecker (src/types)
Milestone

Comments

@jeshecdom
Copy link
Contributor

PR #1652 introduces the ability to execute method calls, but it is now blocked due to the following issue caused by early constant initialization. In the following Tact code:

const A: Int = callIncrement(10);

fun callIncrement(v: Int): Int {
    return v.incr();   // Execution fails here because v does not have yet a type registered in CompilerContext
}                      // and it is required in order to obtain function incr assigned to reference type Int.

extends fun incr(self: Int): Int {
    self += 1;
    return self;
}

Since constant initialization is carried out before function callIncrement is type-checked, the indicated line causes an internal compiler error because variable v still does not have a registered type in CompilerContext:

Error: [INTERNAL COMPILER ERROR]: Expression 1784 not found
Please report at https://github.com/tact-lang/tact/issues
    at throwInternalCompilerError (/home/jesus/tact/tact/src/error/errors.ts:66:11)
    at getExpType (/home/jesus/tact/tact/src/types/resolveExpression.ts:37:35)
    at Interpreter.interpretMethodCall (/home/jesus/tact/tact/src/optimizer/interpreter.ts:943:41)
    at Interpreter.interpretExpression (/home/jesus/tact/tact/src/optimizer/interpreter.ts:851:29)
.....

The same happens if we replace variable v with a number, for example:

fun callIncrement(v: Int): Int {
    return 10.incr();   // Execution fails here because 10 does not have yet a type registered in CompilerContext
}

Constant initialization must be moved after typechecking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: typechecker Implementation of typechecker (src/types)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants