tact-lang/tact

Cannot use `S{}.f` in constant initialization

Closed this issue · 1 comments

i582 commented

Are you using the latest released (or pre-released, a.k.a. "next") version?

  • I'm using the latest Tact version

Tact source code

const MY_CONST: Int = S{}.f

struct S { f: Int = 42 }

Relevant Tact/build system log output

    TactParseError: test/main.tact:3:1: Parse error: expected "}", ";", ".", "!!", "(", "%", "/", "*", ">>", "<<", "-", "+", "==", "!=", "<=", "<", ">=", ">", "^", "&", "&&", "|", "?", or "||"
    
    Line 3, col 1:
      2 | 
    > 3 | struct S { f: Int = 42 }
          ^
      4 | 

What happened?

Compiler cannot parse this code

What did you expect?

This code should work fine

Steps to reproduce

Run code above

How do you run Tact?

From sources

Anything else?

See #879 for a discussion of whether this code should be valid.

struct S { f: Int = 42 }

const MY_CONST: Int = S { }.f;

contract Foo {
    get fun foo(): Int {
        return MY_CONST;
    }
}

this produces the following FunC code:

...
(tuple, int) $Foo$_fun_foo(tuple $self) impure inline_ref {
    var ($self) = $self;
    var $fresh$ret_0 = 42;
    return ($self, $fresh$ret_0);
}
...

Looks like it's been resolved in the new parser