tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
280 stars 56 forks source link

Message integer headers specified via octal `0o` or binary `0b` literals get compiled to `#00000000` in TL-B/FunC #473

Closed novusnota closed 3 days ago

novusnota commented 4 days ago

Consider the following snippet:

import "@stdlib/deploy";

message(0b101010) Binary {}
message(0o52) Octal {}

contract Example with Deployable {
    receive("just to keep those messages around") {
        let binary = Binary{};
        let octal = Octal{};
    }
}

This will produce (apart from other things) those snippets in tact_Example.storage.fc:

;;
;; Type: Binary
;; Header: 0x00000000
;; TLB: binary#00000000  = Binary
;;

(tuple) $Binary$_constructor_() inline {
    return empty_tuple();
}

;;
;; Type: Octal
;; Header: 0x00000000
;; TLB: octal#00000000  = Octal
;;

(tuple) $Octal$_constructor_() inline {
    return empty_tuple();
}

Meanwhile, specifying the integer header in decimal with or without a leading zero, or in hexadecimal 0x2a works fine — the resulting header in FunC matches the specified value. Notice, that having any fields in those Messages doesn't affect this issue.

anton-trunov commented 3 days ago

This modified contract fails to compile:

message(0b101010) Binary {}
message(0o52) Octal {}

contract Example {
    receive(msg: Binary) { }
    receive(msg: Octal) { }
}

Here is the error message:

Tact compilation failed
Error: Invalid allocation: Binary
novusnota commented 3 days ago

Interesting, so we do recognize that 0b101010 and 0o52 are the same number when it comes to receivers

anton-trunov commented 3 days ago

It was a parsing issue