diff --git a/.eslintignore b/.eslintignore index 9a54f6a90..882f7100d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,8 +2,7 @@ node_modules/ dist/ coverage/ **/output/ -./src/test/bugs/output/ -./src/test/features/output/ +src/test/**/output/ src/func/funcfiftlib.js src/grammar/grammar.ohm*.ts src/grammar/grammar.ohm*.js diff --git a/.github/workflows/tact.yml b/.github/workflows/tact.yml index 2d10b2127..136e970f0 100644 --- a/.github/workflows/tact.yml +++ b/.github/workflows/tact.yml @@ -74,26 +74,26 @@ jobs: - name: CLI Test | Check single-contract compilation run: | - tact --check test/tact-cli/success.tact - tact --func test/tact-cli/success.tact - tact test/tact-cli/success.tact + tact --check bin/test/success.tact + tact --func bin/test/success.tact + tact bin/test/success.tact - name: CLI Test | Check compilation via `--config` run: | # should output complete results - tact --config test/tact-cli/success.config.json + tact --config bin/test/success.config.json # should only run the syntax and type checking - tact --config test/tact-cli/success.config.json --check + tact --config bin/test/success.config.json --check - name: CLI Test | Check parsing of a non-existing CLI flag if: runner.os != 'Windows' run: | - ! tact --nonexistentoption test/tact-cli/success.config.json + ! tact --nonexistentoption bin/test/success.config.json - name: CLI Test | tact executable return non-zero exit code if compilation fails if: runner.os != 'Windows' run: | - ! tact --config test/tact-cli/fail.config.json + ! tact --config bin/test/fail.config.json - name: Link Tact compiler run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index b8fede3d2..64b376658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Trailing semicolons in struct and message declarations are optional now: PR [#395](https://github.com/tact-lang/tact/pull/395) +- Tests are refactored and renamed to convey the sense of what is being tested and to reduce the amount of merge conflicts during development: PR [#402](https://github.com/tact-lang/tact/pull/402) ### Fixed diff --git a/test/tact-cli/fail.config.json b/bin/test/fail.config.json similarity index 100% rename from test/tact-cli/fail.config.json rename to bin/test/fail.config.json diff --git a/test/tact-cli/fail.tact b/bin/test/fail.tact similarity index 100% rename from test/tact-cli/fail.tact rename to bin/test/fail.tact diff --git a/test/tact-cli/success.config.json b/bin/test/success.config.json similarity index 100% rename from test/tact-cli/success.config.json rename to bin/test/success.config.json diff --git a/test/tact-cli/success.tact b/bin/test/success.tact similarity index 100% rename from test/tact-cli/success.tact rename to bin/test/success.tact diff --git a/cspell.json b/cspell.json index c1680300a..c8666e42d 100644 --- a/cspell.json +++ b/cspell.json @@ -4,6 +4,7 @@ "language": "en", "words": [ "alnum", + "assgn", "augmentedassign", "blockstore", "bounceable", @@ -16,7 +17,9 @@ "dnsresolve", "Fift", "forall", + "funs", "funcfiftlib", + "initof", "ipfs", "ipld", "jettons", @@ -48,11 +51,13 @@ "stdlib", "struct", "structs", + "subtyping", "testdata", "Topup", "typechecker", "uintptr", "uncons", + "uninit", "unixfs", "workchain", "привет", @@ -72,18 +77,19 @@ "src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap", "src/grammar/grammar.ohm-bundle.d.ts", "src/imports/stdlib.ts", - "src/test/__snapshots__/bugs.spec.ts.snap", - "src/test/__snapshots__/feature-constants.spec.ts.snap", - "src/test/__snapshots__/feature-deep.spec.ts.snap", - "src/test/__snapshots__/feature-implicit-init.spec.ts.snap", - "src/test/__snapshots__/feature-masterchain.spec.ts.snap", - "src/test/__snapshots__/feature-try-catch.spec.ts.snap", - "src/test/feature-address.spec.ts", - "src/test/feature-intrinsics.spec.ts", - "src/test/feature-optionals.spec.ts", - "src/test/feature-strings.spec.ts", - "src/test/features/intrinsics.tact", - "src/test/features/strings.tact", + "/src/test/compilation-failed/const-eval-failed.spec.ts", + "src/test/e2e-emulated/__snapshots__/constants.spec.ts.snap", + "src/test/e2e-emulated/__snapshots__/deep.spec.ts.snap", + "src/test/e2e-emulated/__snapshots__/implicit-init.spec.ts.snap", + "src/test/e2e-emulated/__snapshots__/masterchain.spec.ts.snap", + "src/test/e2e-emulated/__snapshots__/sample-jetton.spec.ts.snap", + "src/test/e2e-emulated/__snapshots__/try-catch.spec.ts.snap", + "src/test/e2e-emulated/address.spec.ts", + "src/test/e2e-emulated/intrinsics.spec.ts", + "src/test/e2e-emulated/optionals.spec.ts", + "src/test/e2e-emulated/strings.spec.ts", + "src/test/e2e-emulated/contracts/intrinsics.tact", + "src/test/e2e-emulated/contracts/strings.tact", "src/test/compilation-fail/fail-const-eval.spec.ts", "stdlib/stdlib.fc" ] diff --git a/jest.teardown.js b/jest.teardown.js index fa59b7190..6e3c204bf 100644 --- a/jest.teardown.js +++ b/jest.teardown.js @@ -9,11 +9,18 @@ module.exports = async () => { __dirname, "src", "test", - "features", + "codegen", + "output", + "*.boc", + ), + path.resolve( + __dirname, + "src", + "test", + "e2e-emulated", "output", "*.boc", ), - path.resolve(__dirname, "src", "test", "bugs", "output", "*.boc"), path.resolve( __dirname, "src", diff --git a/package.json b/package.json index c902d8333..34f8bf96d 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "dist/**/*", "src/**/*", "bin/**/*", - "stdlib/**/*" + "stdlib/**/*", + "!**/test" ], "main": "./dist/main.js", "bin": { diff --git a/scripts/prepare.ts b/scripts/prepare.ts index 185330857..13fed6367 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -1,11 +1,8 @@ import fs from "fs"; import { decompileAll } from "@tact-lang/opcode"; import { run } from "../src/node"; -import { build } from "../src/pipeline/build"; import { FuncCompilationResult, funcCompile } from "../src/func/funcCompile"; import path from "path"; -import { ConfigProject } from "../src/config/parseConfig"; -import { createNodeFileSystem } from "../src/vfs/createNodeFileSystem"; import { glob } from "glob"; import { verify } from "../src/verify"; import { consoleLogger } from "../src/logger"; @@ -35,31 +32,6 @@ import { __DANGER__disableVersionNumber } from "../src/pipeline/version"; } } - // Compile test contracts - for (const p of [ - { path: path.resolve(__dirname, "..", "src", "test", "contracts") }, - ]) { - const recs = fs.readdirSync(p.path); - for (const r of recs) { - if (!r.endsWith(".tact")) { - continue; - } - - const config: ConfigProject = { - name: r.slice(0, r.length - ".tact".length), - path: "./" + r, - output: "./output/", - }; - const stdlib = "@stdlib"; - const project = createNodeFileSystem(p.path, false); - await build({ - config, - stdlib, - project, - }); - } - } - // Compile func files for (const p of [{ path: __dirname + "/../func/" }]) { const recs = fs.readdirSync(p.path); diff --git a/src/grammar/__snapshots__/grammar.spec.ts.snap b/src/grammar/__snapshots__/grammar.spec.ts.snap index 900cb30d4..1bc97413e 100644 --- a/src/grammar/__snapshots__/grammar.spec.ts.snap +++ b/src/grammar/__snapshots__/grammar.spec.ts.snap @@ -1,43 +1,54 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`grammar should fail case-0 1`] = ` -":1:20: Syntax error: expected "{" +exports[`grammar should fail contract-empty-traits-list-with-keyword 1`] = ` +":1:20: Syntax error: expected "_", "A".."Z", or "a".."z" Line 1, col 20: -> 1 | fun testFunc(): Int; +> 1 | contract Name with {} ^ + 2 | " `; -exports[`grammar should fail case-1 1`] = ` -":1:5: Variable name cannot start with "__gen" -Line 1, col 5: -> 1 | fun __gen_hello(): Int { - ^~~~~~~~~~~ - 2 | +exports[`grammar should fail contract-init-trailing-comma-empty-params 1`] = ` +":2:10: Empty parameter list should not have a dangling comma. +Line 2, col 10: + 1 | contract Name { +> 2 | init(,) {} + ^ + 3 | } " `; -exports[`grammar should fail case-2 1`] = ` -":2:9: Variable name cannot start with "__gen" -Line 2, col 9: - 1 | fun hello(): Int { -> 2 | let __gen_a: Int = 0; - ^~~~~~~ - 3 | } +exports[`grammar should fail contract-trailing-comma-empty-traits-list 1`] = ` +":1:19: Syntax error: expected "_", "A".."Z", or "a".."z" +Line 1, col 19: +> 1 | contract Name with, {} + ^ + 2 | " `; -exports[`grammar should fail case-3 1`] = ` -":2:9: Variable name cannot start with "__tact" -Line 2, col 9: - 1 | fun hello(): Int { -> 2 | let __tact_a: Int = 0; - ^~~~~~~~ +exports[`grammar should fail expr-fun-call-trailing-comma-no-args 1`] = ` +":6:14: Empty parameter list should not have a dangling comma. +Line 6, col 14: + 5 | fun b(): Int { +> 6 | return a(,); + ^ + 7 | } +" +`; + +exports[`grammar should fail expr-method-call-trailing-comma-no-args 1`] = ` +":2:24: Empty parameter list should not have a dangling comma. +Line 2, col 24: + 1 | fun another() { +> 2 | return 42.toString(,); + ^ 3 | } " `; -exports[`grammar should fail case-4 1`] = ` +exports[`grammar should fail ident-cannot-be-if-reserved-word 1`] = ` ":2:9: Syntax error: expected not a reservedWord Line 2, col 9: 1 | fun hello(): Int { @@ -47,16 +58,25 @@ Line 2, col 9: " `; -exports[`grammar should fail case-5 1`] = ` -":1:8: Syntax error: expected "A".."Z" -Line 1, col 8: -> 1 | struct __genA { - ^ - 2 | a: Int; +exports[`grammar should fail ident-contract-cannot-start-with-__gen 1`] = ` +":1:10: Variable name cannot start with "__gen" +Line 1, col 10: +> 1 | contract __gen_a { + ^~~~~~~ + 2 | +" +`; + +exports[`grammar should fail ident-fun-cannot-start-with-__gen 1`] = ` +":1:5: Variable name cannot start with "__gen" +Line 1, col 5: +> 1 | fun __gen_hello(): Int { + ^~~~~~~~~~~ + 2 | " `; -exports[`grammar should fail case-6 1`] = ` +exports[`grammar should fail ident-fun-param-cannot-start-with-__gen 1`] = ` ":1:10: Variable name cannot start with "__gen" Line 1, col 10: > 1 | fun main(__gen: Int): Int { @@ -65,16 +85,17 @@ Line 1, col 10: " `; -exports[`grammar should fail case-7 1`] = ` -":1:10: Variable name cannot start with "__gen" -Line 1, col 10: -> 1 | contract __gen_a { - ^~~~~~~ - 2 | +exports[`grammar should fail ident-fun-param-cannot-start-with-__tact 1`] = ` +":2:11: Variable name cannot start with "__tact" +Line 2, col 11: + 1 | contract A { +> 2 | fun b(__tact: Int) { + ^~~~~~ + 3 | " `; -exports[`grammar should fail case-8 1`] = ` +exports[`grammar should fail ident-init-param-cannot-start-with-__tact 1`] = ` ":2:10: Variable name cannot start with "__tact" Line 2, col 10: 1 | contract A { @@ -84,55 +105,80 @@ Line 2, col 10: " `; -exports[`grammar should fail case-9 1`] = ` -":2:11: Variable name cannot start with "__tact" -Line 2, col 11: - 1 | contract A { -> 2 | fun b(__tact: Int) { - ^~~~~~ - 3 | +exports[`grammar should fail ident-let-cannot-start-with-__gen 1`] = ` +":2:9: Variable name cannot start with "__gen" +Line 2, col 9: + 1 | fun hello(): Int { +> 2 | let __gen_a: Int = 0; + ^~~~~~~ + 3 | } +" +`; + +exports[`grammar should fail ident-let-cannot-start-with-__tact 1`] = ` +":2:9: Variable name cannot start with "__tact" +Line 2, col 9: + 1 | fun hello(): Int { +> 2 | let __tact_a: Int = 0; + ^~~~~~~~ + 3 | } " `; -exports[`grammar should fail case-10 1`] = ` +exports[`grammar should fail ident-struct-cannot-start-with-__gen 1`] = ` ":1:8: Syntax error: expected "A".."Z" Line 1, col 8: -> 1 | struct lowercaseIdForType { +> 1 | struct __genA { ^ 2 | a: Int; " `; -exports[`grammar should fail case-11 1`] = ` -":1:14: Syntax error: expected "A".."Z" +exports[`grammar should fail item-fun-non-void-trailing-comma-no-params 1`] = ` +":1:14: Empty parameter list should not have a dangling comma. Line 1, col 14: -> 1 | message(123) foo { +> 1 | fun function(,) : Int { ^ - 2 | signature: Slice; + 2 | return 42; " `; -exports[`grammar should fail case-12 1`] = ` -":2:14: Syntax error: expected "1" or "0" -Line 2, col 14: - 1 | fun test_fun(): Int { -> 2 | return 0b_00101010; +exports[`grammar should fail item-fun-void-trailing-comma-no-params 1`] = ` +":1:14: Empty parameter list should not have a dangling comma. +Line 1, col 14: +> 1 | fun function(,) {} ^ - 3 | } + 2 | " `; -exports[`grammar should fail case-13 1`] = ` -":2:15: Syntax error: expected ";" -Line 2, col 15: - 1 | fun test_fun(): Int { -> 2 | return 0b123; - ^ - 3 | } +exports[`grammar should fail item-fun-without-body 1`] = ` +":1:20: Syntax error: expected "{" +Line 1, col 20: +> 1 | fun testFunc(): Int; + ^ +" +`; + +exports[`grammar should fail item-native-fun-not-void-decl-trailing-comma-no-params.tact 1`] = ` +":2:31: Empty parameter list should not have a dangling comma. +Line 2, col 31: + 1 | @name(native_name_2) +> 2 | native testNativeFuncWithType(,): Int; + ^ +" +`; + +exports[`grammar should fail item-native-fun-void-decl-trailing-comma-no-params 1`] = ` +":2:23: Empty parameter list should not have a dangling comma. +Line 2, col 23: + 1 | @name(native_name_1) +> 2 | native testNativeFunc(,); + ^ " `; -exports[`grammar should fail case-14 1`] = ` +exports[`grammar should fail literal-dec-trailing-underscore 1`] = ` ":2:16: Syntax error: expected a digit Line 2, col 16: 1 | fun test_fun(): Int { @@ -142,37 +188,37 @@ Line 2, col 16: " `; -exports[`grammar should fail case-15 1`] = ` -":2:18: Syntax error: expected a hexadecimal digit -Line 2, col 18: +exports[`grammar should fail literal-double-underscore 1`] = ` +":2:20: Syntax error: expected a digit +Line 2, col 20: 1 | fun test_fun(): Int { -> 2 | return 0x123_; - ^ +> 2 | return 123_123__123; + ^ 3 | } " `; -exports[`grammar should fail case-16 1`] = ` -":2:13: Syntax error: expected ";" -Line 2, col 13: +exports[`grammar should fail literal-hex-trailing-underscore 1`] = ` +":2:18: Syntax error: expected a hexadecimal digit +Line 2, col 18: 1 | fun test_fun(): Int { -> 2 | return 0_123; - ^ +> 2 | return 0x123_; + ^ 3 | } " `; -exports[`grammar should fail case-17 1`] = ` -":2:20: Syntax error: expected a digit -Line 2, col 20: +exports[`grammar should fail literal-no-underscore-after-0b 1`] = ` +":2:14: Syntax error: expected "1" or "0" +Line 2, col 14: 1 | fun test_fun(): Int { -> 2 | return 123_123__123; - ^ +> 2 | return 0b_00101010; + ^ 3 | } " `; -exports[`grammar should fail case-18 1`] = ` +exports[`grammar should fail literal-no-underscores-if-leading-zero 1`] = ` ":2:15: Syntax error: expected ";" Line 2, col 15: 1 | fun test_fun(): Int { @@ -182,64 +228,66 @@ Line 2, col 15: " `; -exports[`grammar should fail case-19 1`] = ` -":1:14: Empty parameter list should not have a dangling comma. -Line 1, col 14: -> 1 | fun function(,) {} - ^ - 2 | +exports[`grammar should fail literal-non-binary-digits 1`] = ` +":2:15: Syntax error: expected ";" +Line 2, col 15: + 1 | fun test_fun(): Int { +> 2 | return 0b123; + ^ + 3 | } " `; -exports[`grammar should fail case-20 1`] = ` -":2:24: Empty parameter list should not have a dangling comma. -Line 2, col 24: - 1 | fun another() { -> 2 | return 42.toString(,); - ^ +exports[`grammar should fail literal-underscore-after-leading-zero 1`] = ` +":2:13: Syntax error: expected ";" +Line 2, col 13: + 1 | fun test_fun(): Int { +> 2 | return 0_123; + ^ 3 | } " `; -exports[`grammar should fail case-21 1`] = ` -":1:14: Empty parameter list should not have a dangling comma. -Line 1, col 14: -> 1 | fun function(,) : Int { - ^ - 2 | return 42; +exports[`grammar should fail struct-double-semicolon 1`] = ` +":2:19: Syntax error: expected "}" +Line 2, col 19: + 1 | // too many semicolons +> 2 | struct A { x: Int;; } + ^ + 3 | " `; -exports[`grammar should fail case-22 1`] = ` -":6:14: Empty parameter list should not have a dangling comma. -Line 6, col 14: - 5 | fun b(): Int { -> 6 | return a(,); - ^ - 7 | } +exports[`grammar should fail struct-missing-semicolon-between-fields 1`] = ` +":2:19: Syntax error: expected "}", ";", "=", "as", or "?" +Line 2, col 19: + 1 | // missing ; between fields +> 2 | struct B { x: Int y: Int } + ^ + 3 | " `; -exports[`grammar should fail case-23 1`] = ` -":2:23: Empty parameter list should not have a dangling comma. -Line 2, col 23: - 1 | @name(native_name_1) -> 2 | native testNativeFunc(,); - ^ +exports[`grammar should fail struct-missing-semicolon-between-fields-with-initializer 1`] = ` +":2:24: Syntax error: expected "}", ";", ".", "!!", "%", "/", "*", ">>", "<<", "-", "+", "==", "!=", "<=", "<", ">=", ">", "^", "&", "&&", "|", "?", or "||" +Line 2, col 24: + 1 | // missing ; between fields +> 2 | struct B { x: Int = 42 y: Int } + ^ + 3 | " `; -exports[`grammar should fail case-24 1`] = ` -":2:31: Empty parameter list should not have a dangling comma. -Line 2, col 31: - 1 | trait Test { -> 2 | abstract fun testAbstract(,); - ^ - 3 | } +exports[`grammar should fail trait-empty-traits-list-with-keyword 1`] = ` +":1:17: Syntax error: expected "_", "A".."Z", or "a".."z" +Line 1, col 17: +> 1 | trait Name with {} + ^ + 2 | " `; -exports[`grammar should fail case-25 1`] = ` +exports[`grammar should fail trait-fun-non-void-trailing-comma-no-params.tact 1`] = ` ":2:39: Empty parameter list should not have a dangling comma. Line 2, col 39: 1 | trait Test { @@ -249,25 +297,17 @@ Line 2, col 39: " `; -exports[`grammar should fail case-26 1`] = ` +exports[`grammar should fail trait-fun-void-trailing-comma-no-params 1`] = ` ":2:31: Empty parameter list should not have a dangling comma. Line 2, col 31: - 1 | @name(native_name_2) -> 2 | native testNativeFuncWithType(,): Int; + 1 | trait Test { +> 2 | abstract fun testAbstract(,); ^ + 3 | } " `; -exports[`grammar should fail case-27 1`] = ` -":1:19: Syntax error: expected "_", "A".."Z", or "a".."z" -Line 1, col 19: -> 1 | contract Name with, {} - ^ - 2 | -" -`; - -exports[`grammar should fail case-28 1`] = ` +exports[`grammar should fail trait-trailing-comma-empty-traits-list 1`] = ` ":1:16: Syntax error: expected "_", "A".."Z", or "a".."z" Line 1, col 16: > 1 | trait Name with, {} @@ -276,97 +316,64 @@ Line 1, col 16: " `; -exports[`grammar should fail case-29 1`] = ` -":2:10: Empty parameter list should not have a dangling comma. -Line 2, col 10: - 1 | contract Name { -> 2 | init(,) {} - ^ - 3 | } +exports[`grammar should fail type-ident-msg-should-be-capitalized 1`] = ` +":1:14: Syntax error: expected "A".."Z" +Line 1, col 14: +> 1 | message(123) foo { + ^ + 2 | signature: Slice; " `; -exports[`grammar should fail case-30 1`] = ` -":1:20: Syntax error: expected "_", "A".."Z", or "a".."z" -Line 1, col 20: -> 1 | contract Name with {} - ^ - 2 | -" -`; - -exports[`grammar should fail case-31 1`] = ` -":1:17: Syntax error: expected "_", "A".."Z", or "a".."z" -Line 1, col 17: -> 1 | trait Name with {} - ^ - 2 | -" -`; - -exports[`grammar should fail case-32 1`] = ` -":2:19: Syntax error: expected "}" -Line 2, col 19: - 1 | // too many semicolons -> 2 | struct A { x: Int;; } - ^ - 3 | -" -`; - -exports[`grammar should fail case-33 1`] = ` -":2:19: Syntax error: expected "}", ";", "=", "as", or "?" -Line 2, col 19: - 1 | // missing ; between fields -> 2 | struct B { x: Int y: Int } - ^ - 3 | -" -`; - -exports[`grammar should fail case-34 1`] = ` -":2:24: Syntax error: expected "}", ";", ".", "!!", "%", "/", "*", ">>", "<<", "-", "+", "==", "!=", "<=", "<", ">=", ">", "^", "&", "&&", "|", "?", or "||" -Line 2, col 24: - 1 | // missing ; between fields -> 2 | struct B { x: Int = 42 y: Int } - ^ - 3 | +exports[`grammar should fail type-ident-struct-should-be-capitalized 1`] = ` +":1:8: Syntax error: expected "A".."Z" +Line 1, col 8: +> 1 | struct lowercaseIdForType { + ^ + 2 | a: Int; " `; -exports[`grammar should parse case-0 1`] = ` +exports[`grammar should parse contract-with-const-override 1`] = ` { "entries": [ { - "args": [], "attributes": [], - "id": 4, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return 0; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "declarations": [ { - "expression": { + "attributes": [ + { + "ref": override, + "type": "overrides", + }, + ], + "id": 3, + "kind": "def_constant", + "name": "Test", + "ref": override const Test: Int = 0;, + "type": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "value": { "id": 2, "kind": "number", "ref": 0, "value": 0n, }, - "id": 3, - "kind": "statement_return", - "ref": return 0;, }, ], + "id": 4, + "kind": "def_contract", + "name": "Contract", + "origin": "user", + "ref": contract Contract { + override const Test: Int = 0; +}, + "traits": [], }, ], "id": 5, @@ -374,592 +381,482 @@ exports[`grammar should parse case-0 1`] = ` } `; -exports[`grammar should parse case-1 1`] = ` +exports[`grammar should parse contract-with-init 1`] = ` { "entries": [ { - "args": [], "attributes": [], - "id": 10, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return (0 + 1) * 10 / 20; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "declarations": [ { - "expression": { - "id": 8, - "kind": "op_binary", - "left": { + "as": null, + "id": 2, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int, + "type": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "as": null, + "id": 4, + "init": null, + "kind": "def_field", + "name": "b", + "ref": b: Int, + "type": { + "id": 3, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "args": [ + { "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "op": "+", - "ref": 0 + 1, - "right": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "op": "*", - "ref": (0 + 1) * 10, - "right": { + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, }, - "op": "/", - "ref": (0 + 1) * 10 / 20, - "right": { - "id": 7, - "kind": "number", - "ref": 20, - "value": 20n, + { + "id": 8, + "kind": "def_argument", + "name": "b", + "ref": b: Int, + "type": { + "id": 7, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, }, - }, - "id": 9, - "kind": "statement_return", - "ref": return (0 + 1) * 10 / 20;, - }, - ], + ], + "id": 17, + "kind": "def_init_function", + "ref": init(a: Int, b: Int) { + self.a = a; + self.b = b; }, - ], - "id": 11, - "kind": "program", -} -`; - -exports[`grammar should parse case-2 1`] = ` -{ - "entries": [ - { - "args": [], - "attributes": [], - "id": 12, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return (0 + 1) * 10 / 20 != 10; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ - { - "expression": { - "id": 10, - "kind": "op_binary", - "left": { - "id": 8, - "kind": "op_binary", - "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "op": "+", - "ref": 0 + 1, - "right": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, + "statements": [ + { + "expression": { + "id": 11, + "kind": "id", + "ref": a, + "value": "a", + }, + "id": 12, + "kind": "statement_assign", + "path": [ + { + "id": 9, + "kind": "lvalue_ref", + "name": "self", + "ref": self., }, - "op": "*", - "ref": (0 + 1) * 10, - "right": { - "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, + { + "id": 10, + "kind": "lvalue_ref", + "name": "a", + "ref": a, }, - }, - "op": "/", - "ref": (0 + 1) * 10 / 20, - "right": { - "id": 7, - "kind": "number", - "ref": 20, - "value": 20n, - }, + ], + "ref": self.a = a;, }, - "op": "!=", - "ref": (0 + 1) * 10 / 20 != 10, - "right": { - "id": 9, - "kind": "number", - "ref": 10, - "value": 10n, + { + "expression": { + "id": 15, + "kind": "id", + "ref": b, + "value": "b", + }, + "id": 16, + "kind": "statement_assign", + "path": [ + { + "id": 13, + "kind": "lvalue_ref", + "name": "self", + "ref": self., + }, + { + "id": 14, + "kind": "lvalue_ref", + "name": "b", + "ref": b, + }, + ], + "ref": self.b = b;, }, - }, - "id": 11, - "kind": "statement_return", - "ref": return (0 + 1) * 10 / 20 != 10;, + ], }, ], + "id": 18, + "kind": "def_contract", + "name": "Sample", + "origin": "user", + "ref": contract Sample { + a: Int; + b: Int; + + init(a: Int, b: Int) { + self.a = a; + self.b = b; + } +}, + "traits": [], }, ], - "id": 13, + "id": 19, "kind": "program", } `; -exports[`grammar should parse case-3 1`] = ` +exports[`grammar should parse contract-with-trait 1`] = ` { "entries": [ { - "args": [], - "attributes": [], - "id": 14, - "kind": "def_function", - "name": "testFunc", + "id": 1, + "kind": "primitive", + "name": "Int", "origin": "user", - "ref": fun testFunc(): Int { - return (0 + 1) * 10 / 20 != 10 * someId; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "ref": primitive Int;, + }, + { + "attributes": [], + "declarations": [ { - "expression": { - "id": 12, - "kind": "op_binary", - "left": { - "id": 8, - "kind": "op_binary", - "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "op": "+", - "ref": 0 + 1, - "right": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "op": "*", - "ref": (0 + 1) * 10, - "right": { - "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, - }, - }, - "op": "/", - "ref": (0 + 1) * 10 / 20, - "right": { - "id": 7, - "kind": "number", - "ref": 20, - "value": 20n, - }, + "as": null, + "id": 3, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int, + "type": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "args": [], + "attributes": [ + { + "ref": virtual, + "type": "virtual", }, - "op": "!=", - "ref": (0 + 1) * 10 / 20 != 10 * someId, - "right": { - "id": 11, - "kind": "op_binary", - "left": { - "id": 9, - "kind": "number", - "ref": 10, - "value": 10n, - }, - "op": "*", - "ref": 10 * someId, - "right": { - "id": 10, + ], + "id": 7, + "kind": "def_function", + "name": "a", + "origin": "user", + "ref": virtual fun a(): Int { + return a; + }, + "return": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ + { + "expression": { + "id": 5, "kind": "id", - "ref": someId, - "value": "someId", + "ref": a, + "value": "a", }, + "id": 6, + "kind": "statement_return", + "ref": return a;, }, - }, - "id": 13, - "kind": "statement_return", - "ref": return (0 + 1) * 10 / 20 != 10 * someId;, + ], }, ], - }, - ], - "id": 15, - "kind": "program", -} -`; + "id": 8, + "kind": "def_trait", + "name": "SomeTrait", + "origin": "user", + "ref": trait SomeTrait { + a: Int; -exports[`grammar should parse case-4 1`] = ` -{ - "entries": [ + virtual fun a(): Int { + return a; + } +}, + "traits": [], + }, { - "args": [], "attributes": [], - "id": 22, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "declarations": [ { - "expression": { - "id": 20, - "kind": "op_binary", - "left": { - "id": 12, - "kind": "op_binary", - "left": { - "id": 8, - "kind": "op_binary", - "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "op": "+", - "ref": 0 + 1, - "right": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "op": "*", - "ref": (0 + 1) * 10, - "right": { - "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, - }, - }, - "op": "/", - "ref": (0 + 1) * 10 / 20, - "right": { - "id": 7, - "kind": "number", - "ref": 20, - "value": 20n, - }, - }, - "op": "!=", - "ref": (0 + 1) * 10 / 20 != 10 * someId, - "right": { - "id": 11, - "kind": "op_binary", - "left": { - "id": 9, - "kind": "number", - "ref": 10, - "value": 10n, - }, - "op": "*", - "ref": 10 * someId, - "right": { - "id": 10, - "kind": "id", - "ref": someId, - "value": "someId", - }, - }, + "as": null, + "id": 10, + "init": null, + "kind": "def_field", + "name": "b", + "ref": b: Int, + "type": { + "id": 9, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "args": [], + "attributes": [ + { + "ref": override, + "type": "overrides", }, - "op": "||", - "ref": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10, - "right": { - "id": 19, - "kind": "op_binary", - "left": { - "id": 15, - "kind": "op_binary", - "left": { - "id": 13, - "kind": "id", - "ref": some2, - "value": "some2", - }, - "op": ">", - "ref": some2 > 10, - "right": { - "id": 14, - "kind": "number", - "ref": 10, - "value": 10n, - }, - }, - "op": "&&", - "ref": some2 > 10 && some3 < 10, - "right": { - "id": 18, - "kind": "op_binary", - "left": { - "id": 16, - "kind": "id", - "ref": some3, - "value": "some3", - }, - "op": "<", - "ref": some3 < 10, - "right": { - "id": 17, - "kind": "number", - "ref": 10, - "value": 10n, - }, + ], + "id": 14, + "kind": "def_function", + "name": "a", + "origin": "user", + "ref": override fun a(): Int { + return b; + }, + "return": { + "id": 11, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ + { + "expression": { + "id": 12, + "kind": "id", + "ref": b, + "value": "b", }, + "id": 13, + "kind": "statement_return", + "ref": return b;, }, - }, - "id": 21, - "kind": "statement_return", - "ref": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10;, + ], + }, + ], + "id": 16, + "kind": "def_contract", + "name": "Main", + "origin": "user", + "ref": contract Main with SomeTrait { + b: Int; + + override fun a(): Int { + return b; + } +}, + "traits": [ + { + "id": 15, + "kind": "id", + "ref": SomeTrait, + "value": "SomeTrait", }, ], }, ], - "id": 23, + "id": 17, "kind": "program", } `; -exports[`grammar should parse case-5 1`] = ` +exports[`grammar should parse contract-with-trait-string-literal 1`] = ` { "entries": [ { - "args": [], - "attributes": [], - "id": 24, - "kind": "def_function", - "name": "testFunc", + "id": 1, + "kind": "primitive", + "name": "Int", "origin": "user", - "ref": fun testFunc(): Int { - return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10); -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "ref": primitive Int;, + }, + { + "attributes": [], + "declarations": [ { - "expression": { - "id": 22, - "kind": "op_binary", - "left": { - "id": 12, - "kind": "op_binary", - "left": { - "id": 8, - "kind": "op_binary", - "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "op": "+", - "ref": 0 + 1, - "right": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "op": "*", - "ref": (0 + 1) * 10, - "right": { - "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, - }, - }, - "op": "/", - "ref": (0 + 1) * 10 / 20, - "right": { - "id": 7, - "kind": "number", - "ref": 20, - "value": 20n, - }, - }, - "op": "!=", - "ref": (0 + 1) * 10 / 20 != 10 * someId, - "right": { - "id": 11, - "kind": "op_binary", - "left": { - "id": 9, - "kind": "number", - "ref": 10, - "value": 10n, - }, - "op": "*", - "ref": 10 * someId, - "right": { - "id": 10, - "kind": "id", - "ref": someId, - "value": "someId", - }, - }, + "as": null, + "id": 3, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int, + "type": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "args": [], + "attributes": [ + { + "ref": virtual, + "type": "virtual", }, - "op": "||", - "ref": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10), - "right": { - "id": 21, - "kind": "op_binary", - "left": { - "id": 15, - "kind": "op_binary", - "left": { - "id": 13, - "kind": "id", - "ref": some2, - "value": "some2", - }, - "op": ">", - "ref": some2 > 10, - "right": { - "id": 14, - "kind": "number", - "ref": 10, - "value": 10n, - }, - }, - "op": "&&", - "ref": some2 > 10 && some3 < 123.add(10), - "right": { - "id": 20, - "kind": "op_binary", - "left": { - "id": 16, - "kind": "id", - "ref": some3, - "value": "some3", - }, - "op": "<", - "ref": some3 < 123.add(10), - "right": { - "args": [ - { - "id": 18, - "kind": "number", - "ref": 10, - "value": 10n, - }, - ], - "id": 19, - "kind": "op_call", - "name": "add", - "ref": 123.add(10), - "src": { - "id": 17, - "kind": "number", - "ref": 123, - "value": 123n, - }, - }, + ], + "id": 7, + "kind": "def_function", + "name": "a", + "origin": "user", + "ref": virtual fun a(): Int { + return a; + }, + "return": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ + { + "expression": { + "id": 5, + "kind": "id", + "ref": a, + "value": "a", }, + "id": 6, + "kind": "statement_return", + "ref": return a;, + }, + ], + }, + ], + "id": 8, + "kind": "def_trait", + "name": "SomeTrait", + "origin": "user", + "ref": trait SomeTrait { + a: Int; + + virtual fun a(): Int { + return a; + } +}, + "traits": [], + }, + { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 10, + "init": null, + "kind": "def_field", + "name": "b", + "ref": b: Int, + "type": { + "id": 9, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "args": [], + "attributes": [ + { + "ref": override, + "type": "overrides", }, + ], + "id": 14, + "kind": "def_function", + "name": "a", + "origin": "user", + "ref": override fun a(): Int { + return "hello world!"; + }, + "return": { + "id": 11, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, - "id": 23, - "kind": "statement_return", - "ref": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10);, + "statements": [ + { + "expression": { + "id": 12, + "kind": "string", + "ref": "hello world!", + "value": "hello world!", + }, + "id": 13, + "kind": "statement_return", + "ref": return "hello world!";, + }, + ], + }, + ], + "id": 16, + "kind": "def_contract", + "name": "Main", + "origin": "user", + "ref": contract Main with SomeTrait { + b: Int; + + override fun a(): Int { + return "hello world!"; + } +}, + "traits": [ + { + "id": 15, + "kind": "id", + "ref": SomeTrait, + "value": "SomeTrait", }, ], }, ], - "id": 25, + "id": 17, "kind": "program", } `; -exports[`grammar should parse case-6 1`] = ` +exports[`grammar should parse expr-arith 1`] = ` { "entries": [ { "args": [], "attributes": [], - "id": 25, + "id": 10, "kind": "def_function", "name": "testFunc", "origin": "user", "ref": fun testFunc(): Int { - return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10)); + return (0 + 1) * 10 / 20; }, "return": { "id": 1, @@ -971,42 +868,206 @@ exports[`grammar should parse case-6 1`] = ` "statements": [ { "expression": { - "id": 23, + "id": 8, "kind": "op_binary", "left": { - "id": 12, + "id": 6, "kind": "op_binary", "left": { - "id": 8, + "id": 4, "kind": "op_binary", "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "op": "+", - "ref": 0 + 1, - "right": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "op": "*", - "ref": (0 + 1) * 10, - "right": { - "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "op": "+", + "ref": 0 + 1, + "right": { + "id": 3, + "kind": "number", + "ref": 1, + "value": 1n, + }, + }, + "op": "*", + "ref": (0 + 1) * 10, + "right": { + "id": 5, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "op": "/", + "ref": (0 + 1) * 10 / 20, + "right": { + "id": 7, + "kind": "number", + "ref": 20, + "value": 20n, + }, + }, + "id": 9, + "kind": "statement_return", + "ref": return (0 + 1) * 10 / 20;, + }, + ], + }, + ], + "id": 11, + "kind": "program", +} +`; + +exports[`grammar should parse expr-arith-and-cmp 1`] = ` +{ + "entries": [ + { + "args": [], + "attributes": [], + "id": 12, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc(): Int { + return (0 + 1) * 10 / 20 != 10; +}, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ + { + "expression": { + "id": 10, + "kind": "op_binary", + "left": { + "id": 8, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "op_binary", + "left": { + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "op": "+", + "ref": 0 + 1, + "right": { + "id": 3, + "kind": "number", + "ref": 1, + "value": 1n, + }, + }, + "op": "*", + "ref": (0 + 1) * 10, + "right": { + "id": 5, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "op": "/", + "ref": (0 + 1) * 10 / 20, + "right": { + "id": 7, + "kind": "number", + "ref": 20, + "value": 20n, + }, + }, + "op": "!=", + "ref": (0 + 1) * 10 / 20 != 10, + "right": { + "id": 9, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "id": 11, + "kind": "statement_return", + "ref": return (0 + 1) * 10 / 20 != 10;, + }, + ], + }, + ], + "id": 13, + "kind": "program", +} +`; + +exports[`grammar should parse expr-arith-bool-cmp-method-call 1`] = ` +{ + "entries": [ + { + "args": [], + "attributes": [], + "id": 24, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc(): Int { + return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10); +}, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ + { + "expression": { + "id": 22, + "kind": "op_binary", + "left": { + "id": 12, + "kind": "op_binary", + "left": { + "id": 8, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "op_binary", + "left": { + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "op": "+", + "ref": 0 + 1, + "right": { + "id": 3, + "kind": "number", + "ref": 1, + "value": 1n, + }, + }, + "op": "*", + "ref": (0 + 1) * 10, + "right": { + "id": 5, + "kind": "number", + "ref": 10, + "value": 10n, }, }, "op": "/", @@ -1040,9 +1101,9 @@ exports[`grammar should parse case-6 1`] = ` }, }, "op": "||", - "ref": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10)), + "ref": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10), "right": { - "id": 22, + "id": 21, "kind": "op_binary", "left": { "id": 15, @@ -1063,9 +1124,9 @@ exports[`grammar should parse case-6 1`] = ` }, }, "op": "&&", - "ref": some2 > 10 && some3 < abs(123.add(10)), + "ref": some2 > 10 && some3 < 123.add(10), "right": { - "id": 21, + "id": 20, "kind": "op_binary", "left": { "id": 16, @@ -1074,218 +1135,295 @@ exports[`grammar should parse case-6 1`] = ` "value": "some3", }, "op": "<", - "ref": some3 < abs(123.add(10)), + "ref": some3 < 123.add(10), "right": { "args": [ { - "args": [ - { - "id": 18, - "kind": "number", - "ref": 10, - "value": 10n, - }, - ], - "id": 19, - "kind": "op_call", - "name": "add", - "ref": 123.add(10), - "src": { - "id": 17, - "kind": "number", - "ref": 123, - "value": 123n, - }, + "id": 18, + "kind": "number", + "ref": 10, + "value": 10n, }, ], - "id": 20, - "kind": "op_static_call", - "name": "abs", - "ref": abs(123.add(10)), + "id": 19, + "kind": "op_call", + "name": "add", + "ref": 123.add(10), + "src": { + "id": 17, + "kind": "number", + "ref": 123, + "value": 123n, + }, }, }, }, }, - "id": 24, + "id": 23, "kind": "statement_return", - "ref": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10));, + "ref": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 123.add(10);, }, ], }, ], - "id": 26, + "id": 25, "kind": "program", } `; -exports[`grammar should parse case-7 1`] = ` +exports[`grammar should parse expr-arith-bool-var 1`] = ` { "entries": [ { "args": [], "attributes": [], - "id": 3, + "id": 22, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc() { - return 0; + "ref": fun testFunc(): Int { + return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10; }, - "return": null, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, "statements": [ { "expression": { - "id": 1, - "kind": "number", - "ref": 0, - "value": 0n, + "id": 20, + "kind": "op_binary", + "left": { + "id": 12, + "kind": "op_binary", + "left": { + "id": 8, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "op_binary", + "left": { + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "op": "+", + "ref": 0 + 1, + "right": { + "id": 3, + "kind": "number", + "ref": 1, + "value": 1n, + }, + }, + "op": "*", + "ref": (0 + 1) * 10, + "right": { + "id": 5, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "op": "/", + "ref": (0 + 1) * 10 / 20, + "right": { + "id": 7, + "kind": "number", + "ref": 20, + "value": 20n, + }, + }, + "op": "!=", + "ref": (0 + 1) * 10 / 20 != 10 * someId, + "right": { + "id": 11, + "kind": "op_binary", + "left": { + "id": 9, + "kind": "number", + "ref": 10, + "value": 10n, + }, + "op": "*", + "ref": 10 * someId, + "right": { + "id": 10, + "kind": "id", + "ref": someId, + "value": "someId", + }, + }, + }, + "op": "||", + "ref": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10, + "right": { + "id": 19, + "kind": "op_binary", + "left": { + "id": 15, + "kind": "op_binary", + "left": { + "id": 13, + "kind": "id", + "ref": some2, + "value": "some2", + }, + "op": ">", + "ref": some2 > 10, + "right": { + "id": 14, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "op": "&&", + "ref": some2 > 10 && some3 < 10, + "right": { + "id": 18, + "kind": "op_binary", + "left": { + "id": 16, + "kind": "id", + "ref": some3, + "value": "some3", + }, + "op": "<", + "ref": some3 < 10, + "right": { + "id": 17, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + }, }, - "id": 2, + "id": 21, "kind": "statement_return", - "ref": return 0;, + "ref": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < 10;, }, ], }, + ], + "id": 23, + "kind": "program", +} +`; + +exports[`grammar should parse expr-chaining-unbox 1`] = ` +{ + "entries": [ { - "args": [], - "attributes": [], - "id": 7, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return 0; -}, - "return": { - "id": 4, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "args": [ { - "expression": { - "id": 5, - "kind": "number", - "ref": 0, - "value": 0n, + "id": 3, + "kind": "def_argument", + "name": "m", + "ref": m: map, + "type": { + "id": 2, + "key": "Int", + "keyAs": null, + "kind": "type_ref_map", + "ref": map, + "value": "Int", + "valueAs": null, }, - "id": 6, - "kind": "statement_return", - "ref": return 0;, }, ], - }, - { - "args": [], "attributes": [], - "id": 11, + "id": 9, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc(): Bool { - return 0; + "ref": fun testFunc(m: map): Int { + return m.asCell()!!.hash(); }, "return": { - "id": 8, + "id": 1, "kind": "type_ref_simple", - "name": "Bool", + "name": "Int", "optional": false, - "ref": Bool, + "ref": Int, }, "statements": [ { "expression": { - "id": 9, - "kind": "number", - "ref": 0, - "value": 0n, + "args": [], + "id": 7, + "kind": "op_call", + "name": "hash", + "ref": m.asCell()!!.hash(), + "src": { + "id": 6, + "kind": "op_unary", + "op": "!!", + "ref": m.asCell()!!, + "right": { + "args": [], + "id": 5, + "kind": "op_call", + "name": "asCell", + "ref": m.asCell(), + "src": { + "id": 4, + "kind": "id", + "ref": m, + "value": "m", + }, + }, + }, }, - "id": 10, + "id": 8, "kind": "statement_return", - "ref": return 0;, + "ref": return m.asCell()!!.hash();, }, ], }, ], - "id": 12, + "id": 10, "kind": "program", } `; -exports[`grammar should parse case-8 1`] = ` +exports[`grammar should parse expr-condition-with-or 1`] = ` { "entries": [ { - "args": [], - "attributes": [], - "id": 1, - "kind": "def_native_function", - "name": "testFunc", - "nativeName": "native_name_1", - "origin": "user", - "ref": @name(native_name_1) -native testFunc();, - "return": null, - }, - { - "args": [], + "args": [ + { + "id": 3, + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], "attributes": [], - "id": 3, - "kind": "def_native_function", + "id": 19, + "kind": "def_function", "name": "testFunc", - "nativeName": "native_name_2", "origin": "user", - "ref": @name(native_name_2) -native testFunc(): Int;, + "ref": fun testFunc(a: Int): Int { + return a == 123 || a == 456 ? a + 1 : a + 2; +}, "return": { - "id": 2, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "args": [], - "attributes": [], - "id": 5, - "kind": "def_native_function", - "name": "testFunc", - "nativeName": "native_name_3", - "origin": "user", - "ref": @name(native_name_3) -native testFunc(): Bool;, - "return": { - "id": 4, - "kind": "type_ref_simple", - "name": "Bool", - "optional": false, - "ref": Bool, - }, - }, - ], - "id": 6, - "kind": "program", -} -`; - -exports[`grammar should parse case-9 1`] = ` -{ - "entries": [ - { - "args": [], - "attributes": [], - "id": 11, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return 1 + 2 + 3!! > 123; -}, - "return": { - "id": 1, + "id": 1, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -1294,77 +1432,126 @@ exports[`grammar should parse case-9 1`] = ` "statements": [ { "expression": { - "id": 9, - "kind": "op_binary", - "left": { - "id": 7, + "condition": { + "id": 10, "kind": "op_binary", "left": { - "id": 4, + "id": 6, "kind": "op_binary", "left": { - "id": 2, - "kind": "number", - "ref": 1, - "value": 1n, + "id": 4, + "kind": "id", + "ref": a, + "value": "a", }, - "op": "+", - "ref": 1 + 2, + "op": "==", + "ref": a == 123, "right": { - "id": 3, + "id": 5, "kind": "number", - "ref": 2, - "value": 2n, + "ref": 123, + "value": 123n, }, }, - "op": "+", - "ref": 1 + 2 + 3!!, + "op": "||", + "ref": a == 123 || a == 456, "right": { - "id": 6, - "kind": "op_unary", - "op": "!!", - "ref": 3!!, + "id": 9, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "==", + "ref": a == 456, "right": { - "id": 5, + "id": 8, "kind": "number", - "ref": 3, - "value": 3n, + "ref": 456, + "value": 456n, }, }, }, - "op": ">", - "ref": 1 + 2 + 3!! > 123, - "right": { - "id": 8, - "kind": "number", - "ref": 123, - "value": 123n, + "elseBranch": { + "id": 16, + "kind": "op_binary", + "left": { + "id": 14, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "+", + "ref": a + 2, + "right": { + "id": 15, + "kind": "number", + "ref": 2, + "value": 2n, + }, + }, + "id": 17, + "kind": "conditional", + "ref": a == 123 || a == 456 ? a + 1 : a + 2, + "thenBranch": { + "id": 13, + "kind": "op_binary", + "left": { + "id": 11, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "+", + "ref": a + 1, + "right": { + "id": 12, + "kind": "number", + "ref": 1, + "value": 1n, + }, }, }, - "id": 10, + "id": 18, "kind": "statement_return", - "ref": return 1 + 2 + 3!! > 123;, + "ref": return a == 123 || a == 456 ? a + 1 : a + 2;, }, ], }, ], - "id": 12, + "id": 20, "kind": "program", } `; -exports[`grammar should parse case-10 1`] = ` +exports[`grammar should parse expr-conditional 1`] = ` { "entries": [ { - "args": [], + "args": [ + { + "id": 3, + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], "attributes": [], - "id": 13, + "id": 11, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc(): Int { - return 1 + 2 + (123 + 3)!! > 123; + "ref": fun testFunc(a: Int): Int { + return a == 123 ? 1 : 2; }, "return": { "id": 1, @@ -1376,78 +1563,53 @@ exports[`grammar should parse case-10 1`] = ` "statements": [ { "expression": { - "id": 11, - "kind": "op_binary", - "left": { - "id": 9, + "condition": { + "id": 6, "kind": "op_binary", "left": { "id": 4, - "kind": "op_binary", - "left": { - "id": 2, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "op": "+", - "ref": 1 + 2, - "right": { - "id": 3, - "kind": "number", - "ref": 2, - "value": 2n, - }, + "kind": "id", + "ref": a, + "value": "a", }, - "op": "+", - "ref": 1 + 2 + (123 + 3)!!, + "op": "==", + "ref": a == 123, "right": { - "id": 8, - "kind": "op_unary", - "op": "!!", - "ref": (123 + 3)!!, - "right": { - "id": 7, - "kind": "op_binary", - "left": { - "id": 5, - "kind": "number", - "ref": 123, - "value": 123n, - }, - "op": "+", - "ref": 123 + 3, - "right": { - "id": 6, - "kind": "number", - "ref": 3, - "value": 3n, - }, - }, + "id": 5, + "kind": "number", + "ref": 123, + "value": 123n, }, }, - "op": ">", - "ref": 1 + 2 + (123 + 3)!! > 123, - "right": { - "id": 10, + "elseBranch": { + "id": 8, "kind": "number", - "ref": 123, - "value": 123n, + "ref": 2, + "value": 2n, + }, + "id": 9, + "kind": "conditional", + "ref": a == 123 ? 1 : 2, + "thenBranch": { + "id": 7, + "kind": "number", + "ref": 1, + "value": 1n, }, }, - "id": 12, + "id": 10, "kind": "statement_return", - "ref": return 1 + 2 + (123 + 3)!! > 123;, + "ref": return a == 123 ? 1 : 2;, }, ], }, ], - "id": 14, + "id": 12, "kind": "program", } `; -exports[`grammar should parse case-11 1`] = ` +exports[`grammar should parse expr-conditional-with-let 1`] = ` { "entries": [ { @@ -1455,24 +1617,25 @@ exports[`grammar should parse case-11 1`] = ` { "id": 3, "kind": "def_argument", - "name": "src", - "ref": src: Int?, + "name": "a", + "ref": a: Int, "type": { "id": 2, "kind": "type_ref_simple", "name": "Int", - "optional": true, - "ref": Int?, + "optional": false, + "ref": Int, }, }, ], "attributes": [], - "id": 15, + "id": 14, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc(src: Int?): Int { - return 1 + 2 + (123 + 3)!! > 123; + "ref": fun testFunc(a: Int): Int { + let b: Int = a == 123 ? 1 : 2; + return b; }, "return": { "id": 1, @@ -1484,203 +1647,83 @@ exports[`grammar should parse case-11 1`] = ` "statements": [ { "expression": { - "id": 13, - "kind": "op_binary", - "left": { - "id": 11, + "condition": { + "id": 7, "kind": "op_binary", "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "op": "+", - "ref": 1 + 2, - "right": { - "id": 5, - "kind": "number", - "ref": 2, - "value": 2n, - }, + "id": 5, + "kind": "id", + "ref": a, + "value": "a", }, - "op": "+", - "ref": 1 + 2 + (123 + 3)!!, + "op": "==", + "ref": a == 123, "right": { - "id": 10, - "kind": "op_unary", - "op": "!!", - "ref": (123 + 3)!!, - "right": { - "id": 9, - "kind": "op_binary", - "left": { - "id": 7, - "kind": "number", - "ref": 123, - "value": 123n, - }, - "op": "+", - "ref": 123 + 3, - "right": { - "id": 8, - "kind": "number", - "ref": 3, - "value": 3n, - }, - }, + "id": 6, + "kind": "number", + "ref": 123, + "value": 123n, }, }, - "op": ">", - "ref": 1 + 2 + (123 + 3)!! > 123, - "right": { - "id": 12, + "elseBranch": { + "id": 9, "kind": "number", - "ref": 123, - "value": 123n, + "ref": 2, + "value": 2n, + }, + "id": 10, + "kind": "conditional", + "ref": a == 123 ? 1 : 2, + "thenBranch": { + "id": 8, + "kind": "number", + "ref": 1, + "value": 1n, }, }, - "id": 14, - "kind": "statement_return", - "ref": return 1 + 2 + (123 + 3)!! > 123;, - }, - ], - }, - ], - "id": 16, - "kind": "program", -} -`; - -exports[`grammar should parse case-12 1`] = ` -{ - "entries": [ - { - "args": [ - { - "id": 3, - "kind": "def_argument", - "name": "src", - "ref": src: Int?, + "id": 11, + "kind": "statement_let", + "name": "b", + "ref": let b: Int = a == 123 ? 1 : 2;, "type": { - "id": 2, + "id": 4, "kind": "type_ref_simple", "name": "Int", - "optional": true, - "ref": Int?, - }, - }, - ], - "attributes": [], - "id": 12, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(src: Int?): Int { - if (src != null) { - return src; - } - return 0; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ - { - "elseif": null, - "expression": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "id", - "ref": src, - "value": "src", - }, - "op": "!=", - "ref": src != null, - "right": { - "id": 5, - "kind": "null", - "ref": null, - }, + "optional": false, + "ref": Int, }, - "falseStatements": null, - "id": 9, - "kind": "statement_condition", - "ref": if (src != null) { - return src; - }, - "trueStatements": [ - { - "expression": { - "id": 7, - "kind": "id", - "ref": src, - "value": "src", - }, - "id": 8, - "kind": "statement_return", - "ref": return src;, - }, - ], }, { "expression": { - "id": 10, - "kind": "number", - "ref": 0, - "value": 0n, + "id": 12, + "kind": "id", + "ref": b, + "value": "b", }, - "id": 11, + "id": 13, "kind": "statement_return", - "ref": return 0;, + "ref": return b;, }, ], }, ], - "id": 13, + "id": 15, "kind": "program", } `; -exports[`grammar should parse case-13 1`] = ` +exports[`grammar should parse expr-fun-call 1`] = ` { "entries": [ { - "args": [ - { - "id": 3, - "kind": "def_argument", - "name": "src", - "ref": src: Int?, - "type": { - "id": 2, - "kind": "type_ref_simple", - "name": "Int", - "optional": true, - "ref": Int?, - }, - }, - ], + "args": [], "attributes": [], - "id": 12, + "id": 25, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc(src: Int?): Int { - if (src != null) { - return src; - } else { - return 10; - } + "ref": fun testFunc(): Int { + return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10)); }, "return": { "id": 1, @@ -1691,686 +1734,642 @@ exports[`grammar should parse case-13 1`] = ` }, "statements": [ { - "elseif": null, "expression": { - "id": 6, + "id": 23, "kind": "op_binary", "left": { - "id": 4, - "kind": "id", - "ref": src, - "value": "src", - }, - "op": "!=", - "ref": src != null, - "right": { - "id": 5, - "kind": "null", - "ref": null, - }, - }, - "falseStatements": [ - { - "expression": { - "id": 9, - "kind": "number", - "ref": 10, - "value": 10n, - }, - "id": 10, - "kind": "statement_return", - "ref": return 10;, - }, - ], - "id": 11, - "kind": "statement_condition", - "ref": if (src != null) { - return src; - } else { - return 10; - }, - "trueStatements": [ - { - "expression": { - "id": 7, - "kind": "id", - "ref": src, - "value": "src", - }, - "id": 8, - "kind": "statement_return", - "ref": return src;, - }, - ], + "id": 12, + "kind": "op_binary", + "left": { + "id": 8, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "op_binary", + "left": { + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "op": "+", + "ref": 0 + 1, + "right": { + "id": 3, + "kind": "number", + "ref": 1, + "value": 1n, + }, + }, + "op": "*", + "ref": (0 + 1) * 10, + "right": { + "id": 5, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "op": "/", + "ref": (0 + 1) * 10 / 20, + "right": { + "id": 7, + "kind": "number", + "ref": 20, + "value": 20n, + }, + }, + "op": "!=", + "ref": (0 + 1) * 10 / 20 != 10 * someId, + "right": { + "id": 11, + "kind": "op_binary", + "left": { + "id": 9, + "kind": "number", + "ref": 10, + "value": 10n, + }, + "op": "*", + "ref": 10 * someId, + "right": { + "id": 10, + "kind": "id", + "ref": someId, + "value": "someId", + }, + }, + }, + "op": "||", + "ref": (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10)), + "right": { + "id": 22, + "kind": "op_binary", + "left": { + "id": 15, + "kind": "op_binary", + "left": { + "id": 13, + "kind": "id", + "ref": some2, + "value": "some2", + }, + "op": ">", + "ref": some2 > 10, + "right": { + "id": 14, + "kind": "number", + "ref": 10, + "value": 10n, + }, + }, + "op": "&&", + "ref": some2 > 10 && some3 < abs(123.add(10)), + "right": { + "id": 21, + "kind": "op_binary", + "left": { + "id": 16, + "kind": "id", + "ref": some3, + "value": "some3", + }, + "op": "<", + "ref": some3 < abs(123.add(10)), + "right": { + "args": [ + { + "args": [ + { + "id": 18, + "kind": "number", + "ref": 10, + "value": 10n, + }, + ], + "id": 19, + "kind": "op_call", + "name": "add", + "ref": 123.add(10), + "src": { + "id": 17, + "kind": "number", + "ref": 123, + "value": 123n, + }, + }, + ], + "id": 20, + "kind": "op_static_call", + "name": "abs", + "ref": abs(123.add(10)), + }, + }, + }, + }, + "id": 24, + "kind": "statement_return", + "ref": return (0 + 1) * 10 / 20 != 10 * someId || some2 > 10 && some3 < abs(123.add(10));, }, ], }, ], - "id": 13, + "id": 26, "kind": "program", } `; -exports[`grammar should parse case-14 1`] = ` +exports[`grammar should parse expr-int-literal 1`] = ` { "entries": [ { + "args": [], "attributes": [], - "declarations": [ + "id": 4, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc(): Int { + return 0; +}, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ { - "as": null, - "id": 2, - "init": null, - "kind": "def_field", - "name": "a", - "ref": a: Int, - "type": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "expression": { + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, }, + "id": 3, + "kind": "statement_return", + "ref": return 0;, }, + ], + }, + ], + "id": 5, + "kind": "program", +} +`; + +exports[`grammar should parse expr-nested-conditional 1`] = ` +{ + "entries": [ + { + "args": [ { - "as": null, - "id": 4, - "init": null, - "kind": "def_field", - "name": "b", - "ref": b: Int, + "id": 3, + "kind": "def_argument", + "name": "a", + "ref": a: Int, "type": { - "id": 3, + "id": 2, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, + ], + "attributes": [], + "id": 24, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc(a: Int): Int { + return a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2; +}, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ { - "args": [ - { - "id": 6, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 5, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "expression": { + "condition": { + "id": 10, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "==", + "ref": a == 123, + "right": { + "id": 5, + "kind": "number", + "ref": 123, + "value": 123n, + }, }, - }, - { - "id": 8, - "kind": "def_argument", - "name": "b", - "ref": b: Int, - "type": { - "id": 7, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "op": "||", + "ref": a == 123 || a == 456, + "right": { + "id": 9, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "==", + "ref": a == 456, + "right": { + "id": 8, + "kind": "number", + "ref": 456, + "value": 456n, + }, }, }, - ], - "id": 17, - "kind": "def_init_function", - "ref": init(a: Int, b: Int) { - self.a = a; - self.b = b; - }, - "statements": [ - { - "expression": { - "id": 11, + "elseBranch": { + "id": 21, + "kind": "op_binary", + "left": { + "id": 19, "kind": "id", "ref": a, "value": "a", }, - "id": 12, - "kind": "statement_assign", - "path": [ - { - "id": 9, - "kind": "lvalue_ref", - "name": "self", - "ref": self., - }, - { - "id": 10, - "kind": "lvalue_ref", - "name": "a", + "op": "+", + "ref": a + 2, + "right": { + "id": 20, + "kind": "number", + "ref": 2, + "value": 2n, + }, + }, + "id": 22, + "kind": "conditional", + "ref": a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2, + "thenBranch": { + "condition": { + "id": 13, + "kind": "op_binary", + "left": { + "id": 11, + "kind": "id", "ref": a, + "value": "a", + }, + "op": "==", + "ref": a == 10, + "right": { + "id": 12, + "kind": "number", + "ref": 10, + "value": 10n, }, - ], - "ref": self.a = a;, - }, - { - "expression": { - "id": 15, - "kind": "id", - "ref": b, - "value": "b", }, - "id": 16, - "kind": "statement_assign", - "path": [ - { - "id": 13, - "kind": "lvalue_ref", - "name": "self", - "ref": self., + "elseBranch": { + "id": 17, + "kind": "op_binary", + "left": { + "id": 15, + "kind": "id", + "ref": a, + "value": "a", }, - { - "id": 14, - "kind": "lvalue_ref", - "name": "b", - "ref": b, + "op": "*", + "ref": a * 2, + "right": { + "id": 16, + "kind": "number", + "ref": 2, + "value": 2n, }, - ], - "ref": self.b = b;, + }, + "id": 18, + "kind": "conditional", + "ref": a == 10 ? a : a * 2, + "thenBranch": { + "id": 14, + "kind": "id", + "ref": a, + "value": "a", + }, }, - ], + }, + "id": 23, + "kind": "statement_return", + "ref": return a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2;, }, ], - "id": 18, - "kind": "def_contract", - "name": "Sample", - "origin": "user", - "ref": contract Sample { - a: Int; - b: Int; - - init(a: Int, b: Int) { - self.a = a; - self.b = b; - } -}, - "traits": [], }, ], - "id": 19, + "id": 25, "kind": "program", } `; -exports[`grammar should parse case-15 1`] = ` +exports[`grammar should parse expr-parens 1`] = ` { "entries": [ { "args": [], "attributes": [], - "id": 25, + "id": 13, "kind": "def_function", - "name": "main", + "name": "testFunc", "origin": "user", - "ref": fun main() { - let i: Int = 1; - while(true) { - i = i + 1; - } - repeat(10) { - i = i * 10; - } - do { - i = i - 1; - } until(false); + "ref": fun testFunc(): Int { + return 1 + 2 + (123 + 3)!! > 123; }, - "return": null, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, "statements": [ { "expression": { - "id": 2, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "id": 3, - "kind": "statement_let", - "name": "i", - "ref": let i: Int = 1;, - "type": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "condition": { - "id": 4, - "kind": "boolean", - "ref": true, - "value": true, - }, - "id": 10, - "kind": "statement_while", - "ref": while(true) { - i = i + 1; - }, - "statements": [ - { - "expression": { - "id": 8, + "id": 11, + "kind": "op_binary", + "left": { + "id": 9, + "kind": "op_binary", + "left": { + "id": 4, "kind": "op_binary", "left": { - "id": 6, - "kind": "id", - "ref": i, - "value": "i", + "id": 2, + "kind": "number", + "ref": 1, + "value": 1n, }, "op": "+", - "ref": i + 1, + "ref": 1 + 2, "right": { - "id": 7, + "id": 3, "kind": "number", - "ref": 1, - "value": 1n, + "ref": 2, + "value": 2n, }, }, - "id": 9, - "kind": "statement_assign", - "path": [ - { - "id": 5, - "kind": "lvalue_ref", - "name": "i", - "ref": i, - }, - ], - "ref": i = i + 1;, - }, - ], - }, - { - "id": 17, - "iterations": { - "id": 11, - "kind": "number", - "ref": 10, - "value": 10n, - }, - "kind": "statement_repeat", - "ref": repeat(10) { - i = i * 10; - }, - "statements": [ - { - "expression": { - "id": 15, - "kind": "op_binary", - "left": { - "id": 13, - "kind": "id", - "ref": i, - "value": "i", - }, - "op": "*", - "ref": i * 10, + "op": "+", + "ref": 1 + 2 + (123 + 3)!!, + "right": { + "id": 8, + "kind": "op_unary", + "op": "!!", + "ref": (123 + 3)!!, "right": { - "id": 14, - "kind": "number", - "ref": 10, - "value": 10n, + "id": 7, + "kind": "op_binary", + "left": { + "id": 5, + "kind": "number", + "ref": 123, + "value": 123n, + }, + "op": "+", + "ref": 123 + 3, + "right": { + "id": 6, + "kind": "number", + "ref": 3, + "value": 3n, + }, }, }, - "id": 16, - "kind": "statement_assign", - "path": [ - { - "id": 12, - "kind": "lvalue_ref", - "name": "i", - "ref": i, - }, - ], - "ref": i = i * 10;, }, - ], - }, - { - "condition": { - "id": 18, - "kind": "boolean", - "ref": false, - "value": false, - }, - "id": 24, - "kind": "statement_until", - "ref": do { - i = i - 1; - } until(false);, - "statements": [ - { - "expression": { - "id": 22, - "kind": "op_binary", - "left": { - "id": 20, - "kind": "id", - "ref": i, - "value": "i", - }, - "op": "-", - "ref": i - 1, - "right": { - "id": 21, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "id": 23, - "kind": "statement_assign", - "path": [ - { - "id": 19, - "kind": "lvalue_ref", - "name": "i", - "ref": i, - }, - ], - "ref": i = i - 1;, + "op": ">", + "ref": 1 + 2 + (123 + 3)!! > 123, + "right": { + "id": 10, + "kind": "number", + "ref": 123, + "value": 123n, }, - ], + }, + "id": 12, + "kind": "statement_return", + "ref": return 1 + 2 + (123 + 3)!! > 123;, }, ], }, ], - "id": 26, + "id": 14, "kind": "program", } `; -exports[`grammar should parse case-16 1`] = ` +exports[`grammar should parse expr-with-unbox 1`] = ` { "entries": [ { "args": [], "attributes": [], - "id": 17, + "id": 11, "kind": "def_function", - "name": "main", + "name": "testFunc", "origin": "user", - "ref": fun main() { - let i: Int = 1; - while(i >= 10 || i <= 100) { - i = i + 1; - } + "ref": fun testFunc(): Int { + return 1 + 2 + 3!! > 123; }, - "return": null, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, "statements": [ { "expression": { - "id": 2, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "id": 3, - "kind": "statement_let", - "name": "i", - "ref": let i: Int = 1;, - "type": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "condition": { - "id": 10, + "id": 9, "kind": "op_binary", "left": { - "id": 6, + "id": 7, "kind": "op_binary", "left": { "id": 4, - "kind": "id", - "ref": i, - "value": "i", - }, - "op": ">=", - "ref": i >= 10, - "right": { - "id": 5, - "kind": "number", - "ref": 10, - "value": 10n, - }, - }, - "op": "||", - "ref": i >= 10 || i <= 100, - "right": { - "id": 9, - "kind": "op_binary", - "left": { - "id": 7, - "kind": "id", - "ref": i, - "value": "i", - }, - "op": "<=", - "ref": i <= 100, - "right": { - "id": 8, - "kind": "number", - "ref": 100, - "value": 100n, - }, - }, - }, - "id": 16, - "kind": "statement_while", - "ref": while(i >= 10 || i <= 100) { - i = i + 1; - }, - "statements": [ - { - "expression": { - "id": 14, "kind": "op_binary", "left": { - "id": 12, - "kind": "id", - "ref": i, - "value": "i", + "id": 2, + "kind": "number", + "ref": 1, + "value": 1n, }, "op": "+", - "ref": i + 1, + "ref": 1 + 2, "right": { - "id": 13, + "id": 3, "kind": "number", - "ref": 1, - "value": 1n, + "ref": 2, + "value": 2n, }, }, - "id": 15, - "kind": "statement_assign", - "path": [ - { - "id": 11, - "kind": "lvalue_ref", - "name": "i", - "ref": i, + "op": "+", + "ref": 1 + 2 + 3!!, + "right": { + "id": 6, + "kind": "op_unary", + "op": "!!", + "ref": 3!!, + "right": { + "id": 5, + "kind": "number", + "ref": 3, + "value": 3n, }, - ], - "ref": i = i + 1;, + }, }, - ], + "op": ">", + "ref": 1 + 2 + 3!! > 123, + "right": { + "id": 8, + "kind": "number", + "ref": 123, + "value": 123n, + }, + }, + "id": 10, + "kind": "statement_return", + "ref": return 1 + 2 + 3!! > 123;, }, ], }, ], - "id": 18, + "id": 12, "kind": "program", } `; -exports[`grammar should parse case-17 1`] = ` +exports[`grammar should parse expr-with-var 1`] = ` { "entries": [ - { - "fields": [ - { - "as": null, - "id": 2, - "init": null, - "kind": "def_field", - "name": "x", - "ref": x: Int, - "type": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "as": null, - "id": 4, - "init": null, - "kind": "def_field", - "name": "y", - "ref": y: Int, - "type": { - "id": 3, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], - "id": 5, - "kind": "def_struct", - "message": false, - "name": "A", - "origin": "user", - "prefix": null, - "ref": struct A { - x: Int; - y: Int; -}, - }, - { - "attributes": [], - "id": 10, - "kind": "def_constant", - "name": "a", - "ref": const a: A = A { x: 1 };, - "type": { - "id": 6, - "kind": "type_ref_simple", - "name": "A", - "optional": false, - "ref": A, - }, - "value": { - "args": [ - { - "exp": { - "id": 7, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "id": 8, - "kind": "new_parameter", - "name": "x", - "ref": x: 1, - }, - ], - "id": 9, - "kind": "op_new", - "ref": A { x: 1 }, - "type": "A", - }, - }, { "args": [], "attributes": [], - "id": 18, + "id": 14, "kind": "def_function", - "name": "getA", + "name": "testFunc", "origin": "user", - "ref": fun getA(): A { - return A { - x: 1, - y: 2, - }; + "ref": fun testFunc(): Int { + return (0 + 1) * 10 / 20 != 10 * someId; }, "return": { - "id": 11, + "id": 1, "kind": "type_ref_simple", - "name": "A", + "name": "Int", "optional": false, - "ref": A, + "ref": Int, }, "statements": [ { "expression": { - "args": [ - { - "exp": { - "id": 12, - "kind": "number", - "ref": 1, - "value": 1n, + "id": 12, + "kind": "op_binary", + "left": { + "id": 8, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "op_binary", + "left": { + "id": 2, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "op": "+", + "ref": 0 + 1, + "right": { + "id": 3, + "kind": "number", + "ref": 1, + "value": 1n, + }, }, - "id": 13, - "kind": "new_parameter", - "name": "x", - "ref": x: 1, - }, - { - "exp": { - "id": 14, + "op": "*", + "ref": (0 + 1) * 10, + "right": { + "id": 5, "kind": "number", - "ref": 2, - "value": 2n, + "ref": 10, + "value": 10n, }, - "id": 15, - "kind": "new_parameter", - "name": "y", - "ref": y: 2, }, - ], - "id": 16, - "kind": "op_new", - "ref": A { - x: 1, - y: 2, - }, - "type": "A", + "op": "/", + "ref": (0 + 1) * 10 / 20, + "right": { + "id": 7, + "kind": "number", + "ref": 20, + "value": 20n, + }, + }, + "op": "!=", + "ref": (0 + 1) * 10 / 20 != 10 * someId, + "right": { + "id": 11, + "kind": "op_binary", + "left": { + "id": 9, + "kind": "number", + "ref": 10, + "value": 10n, + }, + "op": "*", + "ref": 10 * someId, + "right": { + "id": 10, + "kind": "id", + "ref": someId, + "value": "someId", + }, + }, }, - "id": 17, + "id": 13, "kind": "statement_return", - "ref": return A { - x: 1, - y: 2, - };, + "ref": return (0 + 1) * 10 / 20 != 10 * someId;, }, ], }, + ], + "id": 15, + "kind": "program", +} +`; + +exports[`grammar should parse items-method-def-initof-trailing-comma-shifts 1`] = ` +{ + "entries": [ { - "fields": [ + "args": [ { - "as": null, - "id": 20, - "init": null, - "kind": "def_field", - "name": "x", - "ref": x: Int, + "id": 3, + "kind": "def_argument", + "name": "a", + "ref": a: Int, "type": { - "id": 19, + "id": 2, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2378,14 +2377,12 @@ exports[`grammar should parse case-17 1`] = ` }, }, { - "as": null, - "id": 22, - "init": null, - "kind": "def_field", - "name": "y", - "ref": y: Int, + "id": 5, + "kind": "def_argument", + "name": "b", + "ref": b: Int, "type": { - "id": 21, + "id": 4, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2393,174 +2390,227 @@ exports[`grammar should parse case-17 1`] = ` }, }, ], - "id": 23, - "kind": "def_struct", - "message": true, - "name": "B", + "attributes": [], + "id": 16, + "kind": "def_function", + "name": "function", "origin": "user", - "prefix": null, - "ref": message B { - x: Int; - y: Int; + "ref": fun function(a: Int, b: Int): Int { + return (a >> b) || (a << (32 - b)); }, - }, - { - "attributes": [], - "id": 30, - "kind": "def_constant", - "name": "b", - "ref": const b: B = B { - x: 2, - y: 3, -};, - "type": { - "id": 24, + "return": { + "id": 1, "kind": "type_ref_simple", - "name": "B", + "name": "Int", "optional": false, - "ref": B, + "ref": Int, }, - "value": { - "args": [ - { - "exp": { - "id": 25, - "kind": "number", - "ref": 2, - "value": 2n, + "statements": [ + { + "expression": { + "id": 14, + "kind": "op_binary", + "left": { + "id": 8, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": ">>", + "ref": a >> b, + "right": { + "id": 7, + "kind": "id", + "ref": b, + "value": "b", + }, }, - "id": 26, - "kind": "new_parameter", - "name": "x", - "ref": x: 2, - }, - { - "exp": { - "id": 27, - "kind": "number", - "ref": 3, - "value": 3n, + "op": "||", + "ref": (a >> b) || (a << (32 - b)), + "right": { + "id": 13, + "kind": "op_binary", + "left": { + "id": 9, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "<<", + "ref": a << (32 - b), + "right": { + "id": 12, + "kind": "op_binary", + "left": { + "id": 10, + "kind": "number", + "ref": 32, + "value": 32n, + }, + "op": "-", + "ref": 32 - b, + "right": { + "id": 11, + "kind": "id", + "ref": b, + "value": "b", + }, + }, }, - "id": 28, - "kind": "new_parameter", - "name": "y", - "ref": y: 3, }, - ], - "id": 29, - "kind": "op_new", - "ref": B { - x: 2, - y: 3, -}, - "type": "B", - }, + "id": 15, + "kind": "statement_return", + "ref": return (a >> b) || (a << (32 - b));, + }, + ], }, { - "args": [], + "args": [ + { + "id": 19, + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { + "id": 18, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "id": 21, + "kind": "def_argument", + "name": "b", + "ref": b: Int, + "type": { + "id": 20, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], "attributes": [], - "id": 38, + "id": 32, "kind": "def_function", - "name": "getB", + "name": "anotherFunction", "origin": "user", - "ref": fun getB(): B { - return B { x: 1, y: 5, }; + "ref": fun anotherFunction( + a: Int, + b: Int, + ): Int { + return (a >> b) || (a << (32 - b)); }, "return": { - "id": 31, + "id": 17, "kind": "type_ref_simple", - "name": "B", + "name": "Int", "optional": false, - "ref": B, + "ref": Int, }, "statements": [ { "expression": { - "args": [ - { - "exp": { - "id": 32, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "id": 33, - "kind": "new_parameter", - "name": "x", - "ref": x: 1, + "id": 30, + "kind": "op_binary", + "left": { + "id": 24, + "kind": "op_binary", + "left": { + "id": 22, + "kind": "id", + "ref": a, + "value": "a", }, - { - "exp": { - "id": 34, + "op": ">>", + "ref": a >> b, + "right": { + "id": 23, + "kind": "id", + "ref": b, + "value": "b", + }, + }, + "op": "||", + "ref": (a >> b) || (a << (32 - b)), + "right": { + "id": 29, + "kind": "op_binary", + "left": { + "id": 25, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "<<", + "ref": a << (32 - b), + "right": { + "id": 28, + "kind": "op_binary", + "left": { + "id": 26, "kind": "number", - "ref": 5, - "value": 5n, + "ref": 32, + "value": 32n, + }, + "op": "-", + "ref": 32 - b, + "right": { + "id": 27, + "kind": "id", + "ref": b, + "value": "b", }, - "id": 35, - "kind": "new_parameter", - "name": "y", - "ref": y: 5, }, - ], - "id": 36, - "kind": "op_new", - "ref": B { x: 1, y: 5, }, - "type": "B", + }, }, - "id": 37, + "id": 31, "kind": "statement_return", - "ref": return B { x: 1, y: 5, };, + "ref": return (a >> b) || (a << (32 - b));, }, ], }, - ], - "id": 39, - "kind": "program", -} -`; - -exports[`grammar should parse case-18 1`] = ` -{ - "entries": [ { - "fields": [ + "args": [ { - "as": null, - "id": 2, - "init": null, - "kind": "def_field", - "name": "x", - "ref": x: Int, + "id": 34, + "kind": "def_argument", + "name": "self", + "ref": self: Int, "type": { - "id": 1, + "id": 33, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - "id": 3, - "kind": "def_struct", - "message": false, - "name": "A", - "origin": "user", - "prefix": null, - "ref": struct A { - x: Int; -}, - }, - { - "fields": [ { - "as": "coin", - "id": 5, - "init": null, - "kind": "def_field", - "name": "x", - "ref": x: Int as coin, + "id": 36, + "kind": "def_argument", + "name": "c", + "ref": c: Int, "type": { - "id": 4, + "id": 35, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "id": 38, + "kind": "def_argument", + "name": "d", + "ref": d: Int, + "type": { + "id": 37, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2568,41 +2618,80 @@ exports[`grammar should parse case-18 1`] = ` }, }, ], - "id": 6, - "kind": "def_struct", - "message": true, - "name": "B", + "attributes": [ + { + "ref": extends, + "type": "extends", + }, + ], + "id": 45, + "kind": "def_function", + "name": "extension", "origin": "user", - "prefix": null, - "ref": message B { - x: Int as coin; + "ref": extends fun extension(self: Int, c: Int, d: Int) { + return self + c + d; }, + "return": null, + "statements": [ + { + "expression": { + "id": 43, + "kind": "op_binary", + "left": { + "id": 41, + "kind": "op_binary", + "left": { + "id": 39, + "kind": "id", + "ref": self, + "value": "self", + }, + "op": "+", + "ref": self + c, + "right": { + "id": 40, + "kind": "id", + "ref": c, + "value": "c", + }, + }, + "op": "+", + "ref": self + c + d, + "right": { + "id": 42, + "kind": "id", + "ref": d, + "value": "d", + }, + }, + "id": 44, + "kind": "statement_return", + "ref": return self + c + d;, + }, + ], }, - ], - "id": 7, - "kind": "program", -} -`; - -exports[`grammar should parse case-19 1`] = ` -{ - "entries": [ { - "fields": [ + "args": [ { - "as": null, - "id": 3, - "init": { - "id": 2, - "kind": "number", - "ref": 1000, - "value": 1000n, + "id": 47, + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { + "id": 46, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, - "kind": "def_field", - "name": "x", - "ref": x: Int = 1000, + }, + { + "id": 49, + "kind": "def_argument", + "name": "b", + "ref": b: Int, "type": { - "id": 1, + "id": 48, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2610,32 +2699,63 @@ exports[`grammar should parse case-19 1`] = ` }, }, ], - "id": 4, - "kind": "def_struct", - "message": false, - "name": "A", + "attributes": [], + "id": 61, + "kind": "def_function", + "name": "coverage", "origin": "user", - "prefix": null, - "ref": struct A { - x: Int = 1000; + "ref": fun coverage(a: Int, b: Int) { + let k: Int = a.extension( + b, + 4, + ); + + let c: Int = anotherFunction( + a, + b, + ); }, - }, - { - "fields": [ + "return": null, + "statements": [ { - "as": "coins", - "id": 7, - "init": { - "id": 6, - "kind": "number", - "ref": 1000, - "value": 1000n, + "expression": { + "args": [ + { + "id": 52, + "kind": "id", + "ref": b, + "value": "b", + }, + { + "id": 53, + "kind": "number", + "ref": 4, + "value": 4n, + }, + ], + "id": 54, + "kind": "op_call", + "name": "extension", + "ref": a.extension( + b, + 4, + ), + "src": { + "id": 51, + "kind": "id", + "ref": a, + "value": "a", + }, }, - "kind": "def_field", - "name": "x", - "ref": x: Int as coins = 1000, + "id": 55, + "kind": "statement_let", + "name": "k", + "ref": let k: Int = a.extension( + b, + 4, + );, "type": { - "id": 5, + "id": 50, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2643,127 +2763,91 @@ exports[`grammar should parse case-19 1`] = ` }, }, { - "as": null, - "id": 10, - "init": { - "id": 9, - "kind": "boolean", - "ref": true, - "value": true, + "expression": { + "args": [ + { + "id": 57, + "kind": "id", + "ref": a, + "value": "a", + }, + { + "id": 58, + "kind": "id", + "ref": b, + "value": "b", + }, + ], + "id": 59, + "kind": "op_static_call", + "name": "anotherFunction", + "ref": anotherFunction( + a, + b, + ), }, - "kind": "def_field", - "name": "y", - "ref": y: Bool = true, + "id": 60, + "kind": "statement_let", + "name": "c", + "ref": let c: Int = anotherFunction( + a, + b, + );, "type": { - "id": 8, + "id": 56, "kind": "type_ref_simple", - "name": "Bool", + "name": "Int", "optional": false, - "ref": Bool, + "ref": Int, }, }, ], - "id": 11, - "kind": "def_struct", - "message": true, - "name": "B", - "origin": "user", - "prefix": null, - "ref": message B { - x: Int as coins = 1000; - y: Bool = true; -}, }, - ], - "id": 12, - "kind": "program", -} -`; - -exports[`grammar should parse case-20 1`] = ` -{ - "entries": [ { - "fields": [ + "args": [ { - "as": null, - "id": 2, - "init": null, - "kind": "def_field", - "name": "y", - "ref": y: map, + "id": 64, + "kind": "def_argument", + "name": "a", + "ref": a: Int, "type": { - "id": 1, - "key": "Int", - "keyAs": null, - "kind": "type_ref_map", - "ref": map, - "value": "Int", - "valueAs": null, + "id": 63, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, }, - ], - "id": 3, - "kind": "def_struct", - "message": false, - "name": "A", - "origin": "user", - "prefix": null, - "ref": struct A { - y: map; -}, - }, - { - "fields": [ { - "as": null, - "id": 5, - "init": null, - "kind": "def_field", - "name": "x", - "ref": x: map, + "id": 66, + "kind": "def_argument", + "name": "b", + "ref": b: Int, "type": { - "id": 4, - "key": "Int", - "keyAs": null, - "kind": "type_ref_map", - "ref": map, - "value": "Int", - "valueAs": null, + "id": 65, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, }, ], - "id": 6, - "kind": "def_struct", - "message": true, - "name": "B", - "origin": "user", - "prefix": null, - "ref": message B { - x: map; -}, - }, - ], - "id": 7, - "kind": "program", -} -`; - -exports[`grammar should parse case-21 1`] = ` -{ - "entries": [ - { - "args": [], "attributes": [], - "id": 4, + "id": 71, "kind": "def_function", - "name": "main", + "name": "oneMoreFunction", "origin": "user", - "ref": fun main(): Int { - return 1; + "ref": fun oneMoreFunction( + a: Int, + b: Int, + ): Int { + return anotherFunction( + a, + b, + ); }, "return": { - "id": 1, + "id": 62, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2772,159 +2856,319 @@ exports[`grammar should parse case-21 1`] = ` "statements": [ { "expression": { - "id": 2, - "kind": "number", - "ref": 1, - "value": 1n, + "args": [ + { + "id": 67, + "kind": "id", + "ref": a, + "value": "a", + }, + { + "id": 68, + "kind": "id", + "ref": b, + "value": "b", + }, + ], + "id": 69, + "kind": "op_static_call", + "name": "anotherFunction", + "ref": anotherFunction( + a, + b, + ), }, - "id": 3, + "id": 70, "kind": "statement_return", - "ref": return 1;, + "ref": return anotherFunction( + a, + b, + );, }, ], }, - ], - "id": 5, - "kind": "program", -} -`; - -exports[`grammar should parse case-22 1`] = ` -{ - "entries": [ - { - "id": 1, - "kind": "primitive", - "name": "Int", - "origin": "user", - "ref": primitive Int;, - }, { "attributes": [], "declarations": [ { - "as": null, - "id": 3, - "init": null, - "kind": "def_field", - "name": "c", - "ref": c: Int, - "type": { - "id": 2, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, + "args": [ + { + "id": 73, + "kind": "def_argument", + "name": "arg1", + "ref": arg1: Int, + "type": { + "id": 72, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "id": 75, + "kind": "def_argument", + "name": "arg2", + "ref": arg2: Int, + "type": { + "id": 74, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 76, + "kind": "def_init_function", + "ref": init( + arg1: Int, + arg2: Int, + ) {}, + "statements": [], }, ], - "id": 4, - "kind": "def_trait", - "name": "OtherTrait", + "id": 77, + "kind": "def_contract", + "name": "TestContract", "origin": "user", - "ref": trait OtherTrait { - c: Int; + "ref": contract TestContract { + init( + arg1: Int, + arg2: Int, + ) {} }, "traits": [], }, { + "args": [], "attributes": [], - "declarations": [ + "id": 83, + "kind": "def_function", + "name": "test", + "origin": "user", + "ref": fun test() { + let k: StateInit = initOf TestContract( + 2, + 3, + ); +}, + "return": null, + "statements": [ { - "as": null, - "id": 6, - "init": null, - "kind": "def_field", - "name": "a", - "ref": a: Int, + "expression": { + "args": [ + { + "id": 79, + "kind": "number", + "ref": 2, + "value": 2n, + }, + { + "id": 80, + "kind": "number", + "ref": 3, + "value": 3n, + }, + ], + "id": 81, + "kind": "init_of", + "name": "TestContract", + "ref": initOf TestContract( + 2, + 3, + ), + }, + "id": 82, + "kind": "statement_let", + "name": "k", + "ref": let k: StateInit = initOf TestContract( + 2, + 3, + );, "type": { - "id": 5, + "id": 78, "kind": "type_ref_simple", - "name": "Int", + "name": "StateInit", "optional": false, - "ref": Int, + "ref": StateInit, }, }, ], - "id": 8, - "kind": "def_trait", - "name": "SomeTrait", - "origin": "user", - "ref": trait SomeTrait with OtherTrait, { - a: Int; -}, - "traits": [ - { - "id": 7, - "kind": "id", - "ref": OtherTrait, - "value": "OtherTrait", + }, + ], + "id": 84, + "kind": "program", +} +`; + +exports[`grammar should parse items-multi-funs 1`] = ` +{ + "entries": [ + { + "args": [], + "attributes": [], + "id": 3, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc() { + return 0; +}, + "return": null, + "statements": [ + { + "expression": { + "id": 1, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 2, + "kind": "statement_return", + "ref": return 0;, }, ], }, { + "args": [], "attributes": [], - "declarations": [ + "id": 7, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc(): Int { + return 0; +}, + "return": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ { - "as": null, - "id": 10, - "init": null, - "kind": "def_field", - "name": "b", - "ref": b: Int, - "type": { - "id": 9, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "expression": { + "id": 5, + "kind": "number", + "ref": 0, + "value": 0n, }, + "id": 6, + "kind": "statement_return", + "ref": return 0;, }, ], - "id": 12, - "kind": "def_contract", - "name": "Main", + }, + { + "args": [], + "attributes": [], + "id": 11, + "kind": "def_function", + "name": "testFunc", "origin": "user", - "ref": contract Main with SomeTrait, { - b: Int; + "ref": fun testFunc(): Bool { + return 0; }, - "traits": [ + "return": { + "id": 8, + "kind": "type_ref_simple", + "name": "Bool", + "optional": false, + "ref": Bool, + }, + "statements": [ { - "id": 11, - "kind": "id", - "ref": SomeTrait, - "value": "SomeTrait", + "expression": { + "id": 9, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 10, + "kind": "statement_return", + "ref": return 0;, }, ], }, ], - "id": 13, + "id": 12, "kind": "program", } `; -exports[`grammar should parse case-23 1`] = ` +exports[`grammar should parse items-native-fun-decls 1`] = ` { "entries": [ { + "args": [], + "attributes": [], "id": 1, - "kind": "primitive", - "name": "Int", + "kind": "def_native_function", + "name": "testFunc", + "nativeName": "native_name_1", "origin": "user", - "ref": primitive Int;, + "ref": @name(native_name_1) +native testFunc();, + "return": null, }, { + "args": [], "attributes": [], - "declarations": [ + "id": 3, + "kind": "def_native_function", + "name": "testFunc", + "nativeName": "native_name_2", + "origin": "user", + "ref": @name(native_name_2) +native testFunc(): Int;, + "return": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "args": [], + "attributes": [], + "id": 5, + "kind": "def_native_function", + "name": "testFunc", + "nativeName": "native_name_3", + "origin": "user", + "ref": @name(native_name_3) +native testFunc(): Bool;, + "return": { + "id": 4, + "kind": "type_ref_simple", + "name": "Bool", + "optional": false, + "ref": Bool, + }, + }, + ], + "id": 6, + "kind": "program", +} +`; + +exports[`grammar should parse items-struct-msg-fun-const 1`] = ` +{ + "entries": [ + { + "fields": [ { "as": null, - "id": 3, + "id": 2, "init": null, "kind": "def_field", - "name": "a", - "ref": a: Int, + "name": "x", + "ref": x: Int, "type": { - "id": 2, + "id": 1, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2932,158 +3176,143 @@ exports[`grammar should parse case-23 1`] = ` }, }, { - "args": [], - "attributes": [ - { - "ref": virtual, - "type": "virtual", - }, - ], - "id": 7, - "kind": "def_function", - "name": "a", - "origin": "user", - "ref": virtual fun a(): Int { - return a; - }, - "return": { - "id": 4, + "as": null, + "id": 4, + "init": null, + "kind": "def_field", + "name": "y", + "ref": y: Int, + "type": { + "id": 3, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, - "statements": [ - { - "expression": { - "id": 5, - "kind": "id", - "ref": a, - "value": "a", - }, - "id": 6, - "kind": "statement_return", - "ref": return a;, - }, - ], }, ], - "id": 8, - "kind": "def_trait", - "name": "SomeTrait", + "id": 5, + "kind": "def_struct", + "message": false, + "name": "A", "origin": "user", - "ref": trait SomeTrait { - a: Int; - - virtual fun a(): Int { - return a; - } + "prefix": null, + "ref": struct A { + x: Int; + y: Int; }, - "traits": [], }, { "attributes": [], - "declarations": [ - { - "as": null, - "id": 10, - "init": null, - "kind": "def_field", - "name": "b", - "ref": b: Int, - "type": { - "id": 9, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "args": [], - "attributes": [ - { - "ref": override, - "type": "overrides", - }, - ], - "id": 14, - "kind": "def_function", - "name": "a", - "origin": "user", - "ref": override fun a(): Int { - return b; - }, - "return": { - "id": 11, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ - { - "expression": { - "id": 12, - "kind": "id", - "ref": b, - "value": "b", - }, - "id": 13, - "kind": "statement_return", - "ref": return b;, + "id": 10, + "kind": "def_constant", + "name": "a", + "ref": const a: A = A { x: 1 };, + "type": { + "id": 6, + "kind": "type_ref_simple", + "name": "A", + "optional": false, + "ref": A, + }, + "value": { + "args": [ + { + "exp": { + "id": 7, + "kind": "number", + "ref": 1, + "value": 1n, }, - ], - }, - ], - "id": 16, - "kind": "def_contract", - "name": "Main", + "id": 8, + "kind": "new_parameter", + "name": "x", + "ref": x: 1, + }, + ], + "id": 9, + "kind": "op_new", + "ref": A { x: 1 }, + "type": "A", + }, + }, + { + "args": [], + "attributes": [], + "id": 18, + "kind": "def_function", + "name": "getA", "origin": "user", - "ref": contract Main with SomeTrait { - b: Int; - - override fun a(): Int { - return b; - } + "ref": fun getA(): A { + return A { + x: 1, + y: 2, + }; }, - "traits": [ + "return": { + "id": 11, + "kind": "type_ref_simple", + "name": "A", + "optional": false, + "ref": A, + }, + "statements": [ { - "id": 15, - "kind": "id", - "ref": SomeTrait, - "value": "SomeTrait", + "expression": { + "args": [ + { + "exp": { + "id": 12, + "kind": "number", + "ref": 1, + "value": 1n, + }, + "id": 13, + "kind": "new_parameter", + "name": "x", + "ref": x: 1, + }, + { + "exp": { + "id": 14, + "kind": "number", + "ref": 2, + "value": 2n, + }, + "id": 15, + "kind": "new_parameter", + "name": "y", + "ref": y: 2, + }, + ], + "id": 16, + "kind": "op_new", + "ref": A { + x: 1, + y: 2, + }, + "type": "A", + }, + "id": 17, + "kind": "statement_return", + "ref": return A { + x: 1, + y: 2, + };, }, ], }, - ], - "id": 17, - "kind": "program", -} -`; - -exports[`grammar should parse case-24 1`] = ` -{ - "entries": [ - { - "id": 1, - "kind": "primitive", - "name": "Int", - "origin": "user", - "ref": primitive Int;, - }, { - "attributes": [], - "declarations": [ + "fields": [ { "as": null, - "id": 3, + "id": 20, "init": null, "kind": "def_field", - "name": "a", - "ref": a: Int, + "name": "x", + "ref": x: Int, "type": { - "id": 2, + "id": 19, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -3091,175 +3320,171 @@ exports[`grammar should parse case-24 1`] = ` }, }, { - "args": [], - "attributes": [ - { - "ref": virtual, - "type": "virtual", - }, - ], - "id": 7, - "kind": "def_function", - "name": "a", - "origin": "user", - "ref": virtual fun a(): Int { - return a; - }, - "return": { - "id": 4, + "as": null, + "id": 22, + "init": null, + "kind": "def_field", + "name": "y", + "ref": y: Int, + "type": { + "id": 21, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, - "statements": [ - { - "expression": { - "id": 5, - "kind": "id", - "ref": a, - "value": "a", - }, - "id": 6, - "kind": "statement_return", - "ref": return a;, - }, - ], }, ], - "id": 8, - "kind": "def_trait", - "name": "SomeTrait", + "id": 23, + "kind": "def_struct", + "message": true, + "name": "B", "origin": "user", - "ref": trait SomeTrait { - a: Int; - - virtual fun a(): Int { - return a; - } + "prefix": null, + "ref": message B { + x: Int; + y: Int; }, - "traits": [], }, { "attributes": [], - "declarations": [ - { - "as": null, - "id": 10, - "init": null, - "kind": "def_field", - "name": "b", - "ref": b: Int, - "type": { - "id": 9, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "args": [], - "attributes": [ - { - "ref": override, - "type": "overrides", + "id": 30, + "kind": "def_constant", + "name": "b", + "ref": const b: B = B { + x: 2, + y: 3, +};, + "type": { + "id": 24, + "kind": "type_ref_simple", + "name": "B", + "optional": false, + "ref": B, + }, + "value": { + "args": [ + { + "exp": { + "id": 25, + "kind": "number", + "ref": 2, + "value": 2n, }, - ], - "id": 14, - "kind": "def_function", - "name": "a", - "origin": "user", - "ref": override fun a(): Int { - return "hello world!"; - }, - "return": { - "id": 11, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "id": 26, + "kind": "new_parameter", + "name": "x", + "ref": x: 2, }, - "statements": [ - { - "expression": { - "id": 12, - "kind": "string", - "ref": "hello world!", - "value": "hello world!", - }, - "id": 13, - "kind": "statement_return", - "ref": return "hello world!";, + { + "exp": { + "id": 27, + "kind": "number", + "ref": 3, + "value": 3n, }, - ], - }, - ], - "id": 16, - "kind": "def_contract", - "name": "Main", + "id": 28, + "kind": "new_parameter", + "name": "y", + "ref": y: 3, + }, + ], + "id": 29, + "kind": "op_new", + "ref": B { + x: 2, + y: 3, +}, + "type": "B", + }, + }, + { + "args": [], + "attributes": [], + "id": 38, + "kind": "def_function", + "name": "getB", "origin": "user", - "ref": contract Main with SomeTrait { - b: Int; - - override fun a(): Int { - return "hello world!"; - } + "ref": fun getB(): B { + return B { x: 1, y: 5, }; }, - "traits": [ + "return": { + "id": 31, + "kind": "type_ref_simple", + "name": "B", + "optional": false, + "ref": B, + }, + "statements": [ { - "id": 15, - "kind": "id", - "ref": SomeTrait, - "value": "SomeTrait", + "expression": { + "args": [ + { + "exp": { + "id": 32, + "kind": "number", + "ref": 1, + "value": 1n, + }, + "id": 33, + "kind": "new_parameter", + "name": "x", + "ref": x: 1, + }, + { + "exp": { + "id": 34, + "kind": "number", + "ref": 5, + "value": 5n, + }, + "id": 35, + "kind": "new_parameter", + "name": "y", + "ref": y: 5, + }, + ], + "id": 36, + "kind": "op_new", + "ref": B { x: 1, y: 5, }, + "type": "B", + }, + "id": 37, + "kind": "statement_return", + "ref": return B { x: 1, y: 5, };, }, ], }, ], - "id": 17, + "id": 39, "kind": "program", } `; -exports[`grammar should parse case-25 1`] = ` +exports[`grammar should parse literals-int-underscores-bin-dec-hex-oct 1`] = ` { "entries": [ { - "args": [ - { - "id": 3, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 2, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "id": 5, - "kind": "def_argument", - "name": "b", - "ref": b: Int, - "type": { - "id": 4, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], + "args": [], "attributes": [], - "id": 16, + "id": 66, "kind": "def_function", - "name": "function", + "name": "test_fun", "origin": "user", - "ref": fun function(a: Int, b: Int): Int { - return (a >> b) || (a << (32 - b)); + "ref": fun test_fun(): Int { + let a: Int = 123; + let b: Int = -123; + let c: Int = 1_0123_00_000; + let d: Int = 0x123; + let e: Int = -0x123; + let f: Int = 0x1_0123_00_000; + let g: Int = 0b101010; + let h: Int = -0b101010; + let i: Int = 0b1_0101_00_000; + let j: Int = 0o123; + let k: Int = -0o123; + let l: Int = 0o1_0123_00_000; + return a + b + c + d + e + f + g + h + i + j + k + l; }, "return": { "id": 1, @@ -3271,74 +3496,17 @@ exports[`grammar should parse case-25 1`] = ` "statements": [ { "expression": { - "id": 14, - "kind": "op_binary", - "left": { - "id": 8, - "kind": "op_binary", - "left": { - "id": 6, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": ">>", - "ref": a >> b, - "right": { - "id": 7, - "kind": "id", - "ref": b, - "value": "b", - }, - }, - "op": "||", - "ref": (a >> b) || (a << (32 - b)), - "right": { - "id": 13, - "kind": "op_binary", - "left": { - "id": 9, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "<<", - "ref": a << (32 - b), - "right": { - "id": 12, - "kind": "op_binary", - "left": { - "id": 10, - "kind": "number", - "ref": 32, - "value": 32n, - }, - "op": "-", - "ref": 32 - b, - "right": { - "id": 11, - "kind": "id", - "ref": b, - "value": "b", - }, - }, - }, + "id": 3, + "kind": "number", + "ref": 123, + "value": 123n, }, - "id": 15, - "kind": "statement_return", - "ref": return (a >> b) || (a << (32 - b));, - }, - ], - }, - { - "args": [ - { - "id": 19, - "kind": "def_argument", + "id": 4, + "kind": "statement_let", "name": "a", - "ref": a: Int, + "ref": let a: Int = 123;, "type": { - "id": 18, + "id": 2, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -3346,108 +3514,62 @@ exports[`grammar should parse case-25 1`] = ` }, }, { - "id": 21, - "kind": "def_argument", + "expression": { + "id": 7, + "kind": "op_unary", + "op": "-", + "ref": -123, + "right": { + "id": 6, + "kind": "number", + "ref": 123, + "value": 123n, + }, + }, + "id": 8, + "kind": "statement_let", "name": "b", - "ref": b: Int, + "ref": let b: Int = -123;, "type": { - "id": 20, + "id": 5, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - "attributes": [], - "id": 32, - "kind": "def_function", - "name": "anotherFunction", - "origin": "user", - "ref": fun anotherFunction( - a: Int, - b: Int, - ): Int { - return (a >> b) || (a << (32 - b)); -}, - "return": { - "id": 17, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ { "expression": { - "id": 30, - "kind": "op_binary", - "left": { - "id": 24, - "kind": "op_binary", - "left": { - "id": 22, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": ">>", - "ref": a >> b, - "right": { - "id": 23, - "kind": "id", - "ref": b, - "value": "b", - }, - }, - "op": "||", - "ref": (a >> b) || (a << (32 - b)), - "right": { - "id": 29, - "kind": "op_binary", - "left": { - "id": 25, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "<<", - "ref": a << (32 - b), - "right": { - "id": 28, - "kind": "op_binary", - "left": { - "id": 26, - "kind": "number", - "ref": 32, - "value": 32n, - }, - "op": "-", - "ref": 32 - b, - "right": { - "id": 27, - "kind": "id", - "ref": b, - "value": "b", - }, - }, - }, + "id": 10, + "kind": "number", + "ref": 1_0123_00_000, + "value": 1012300000n, + }, + "id": 11, + "kind": "statement_let", + "name": "c", + "ref": let c: Int = 1_0123_00_000;, + "type": { + "id": 9, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, - "id": 31, - "kind": "statement_return", - "ref": return (a >> b) || (a << (32 - b));, }, - ], - }, - { - "args": [ { - "id": 34, - "kind": "def_argument", - "name": "self", - "ref": self: Int, + "expression": { + "id": 13, + "kind": "number", + "ref": 0x123, + "value": 291n, + }, + "id": 14, + "kind": "statement_let", + "name": "d", + "ref": let d: Int = 0x123;, "type": { - "id": 33, + "id": 12, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -3455,12 +3577,24 @@ exports[`grammar should parse case-25 1`] = ` }, }, { - "id": 36, - "kind": "def_argument", - "name": "c", - "ref": c: Int, + "expression": { + "id": 17, + "kind": "op_unary", + "op": "-", + "ref": -0x123, + "right": { + "id": 16, + "kind": "number", + "ref": 0x123, + "value": 291n, + }, + }, + "id": 18, + "kind": "statement_let", + "name": "e", + "ref": let e: Int = -0x123;, "type": { - "id": 35, + "id": 15, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -3468,80 +3602,62 @@ exports[`grammar should parse case-25 1`] = ` }, }, { - "id": 38, - "kind": "def_argument", - "name": "d", - "ref": d: Int, + "expression": { + "id": 20, + "kind": "number", + "ref": 0x1_0123_00_000, + "value": 69024612352n, + }, + "id": 21, + "kind": "statement_let", + "name": "f", + "ref": let f: Int = 0x1_0123_00_000;, "type": { - "id": 37, + "id": 19, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - "attributes": [ { - "ref": extends, - "type": "extends", + "expression": { + "id": 23, + "kind": "number", + "ref": 0b101010, + "value": 42n, + }, + "id": 24, + "kind": "statement_let", + "name": "g", + "ref": let g: Int = 0b101010;, + "type": { + "id": 22, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, }, - ], - "id": 45, - "kind": "def_function", - "name": "extension", - "origin": "user", - "ref": extends fun extension(self: Int, c: Int, d: Int) { - return self + c + d; -}, - "return": null, - "statements": [ { "expression": { - "id": 43, - "kind": "op_binary", - "left": { - "id": 41, - "kind": "op_binary", - "left": { - "id": 39, - "kind": "id", - "ref": self, - "value": "self", - }, - "op": "+", - "ref": self + c, - "right": { - "id": 40, - "kind": "id", - "ref": c, - "value": "c", - }, - }, - "op": "+", - "ref": self + c + d, + "id": 27, + "kind": "op_unary", + "op": "-", + "ref": -0b101010, "right": { - "id": 42, - "kind": "id", - "ref": d, - "value": "d", + "id": 26, + "kind": "number", + "ref": 0b101010, + "value": 42n, }, }, - "id": 44, - "kind": "statement_return", - "ref": return self + c + d;, - }, - ], - }, - { - "args": [ - { - "id": 47, - "kind": "def_argument", - "name": "a", - "ref": a: Int, + "id": 28, + "kind": "statement_let", + "name": "h", + "ref": let h: Int = -0b101010;, "type": { - "id": 46, + "id": 25, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -3549,76 +3665,37 @@ exports[`grammar should parse case-25 1`] = ` }, }, { - "id": 49, - "kind": "def_argument", - "name": "b", - "ref": b: Int, + "expression": { + "id": 30, + "kind": "number", + "ref": 0b1_0101_00_000, + "value": 672n, + }, + "id": 31, + "kind": "statement_let", + "name": "i", + "ref": let i: Int = 0b1_0101_00_000;, "type": { - "id": 48, + "id": 29, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - "attributes": [], - "id": 61, - "kind": "def_function", - "name": "coverage", - "origin": "user", - "ref": fun coverage(a: Int, b: Int) { - let k: Int = a.extension( - b, - 4, - ); - - let c: Int = anotherFunction( - a, - b, - ); -}, - "return": null, - "statements": [ { "expression": { - "args": [ - { - "id": 52, - "kind": "id", - "ref": b, - "value": "b", - }, - { - "id": 53, - "kind": "number", - "ref": 4, - "value": 4n, - }, - ], - "id": 54, - "kind": "op_call", - "name": "extension", - "ref": a.extension( - b, - 4, - ), - "src": { - "id": 51, - "kind": "id", - "ref": a, - "value": "a", - }, + "id": 33, + "kind": "number", + "ref": 0o123, + "value": 83n, }, - "id": 55, + "id": 34, "kind": "statement_let", - "name": "k", - "ref": let k: Int = a.extension( - b, - 4, - );, + "name": "j", + "ref": let j: Int = 0o123;, "type": { - "id": 50, + "id": 32, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -3627,292 +3704,200 @@ exports[`grammar should parse case-25 1`] = ` }, { "expression": { - "args": [ - { - "id": 57, - "kind": "id", - "ref": a, - "value": "a", - }, - { - "id": 58, - "kind": "id", - "ref": b, - "value": "b", - }, - ], - "id": 59, - "kind": "op_static_call", - "name": "anotherFunction", - "ref": anotherFunction( - a, - b, - ), + "id": 37, + "kind": "op_unary", + "op": "-", + "ref": -0o123, + "right": { + "id": 36, + "kind": "number", + "ref": 0o123, + "value": 83n, + }, }, - "id": 60, + "id": 38, "kind": "statement_let", - "name": "c", - "ref": let c: Int = anotherFunction( - a, - b, - );, + "name": "k", + "ref": let k: Int = -0o123;, "type": { - "id": 56, + "id": 35, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - }, - { - "args": [ { - "id": 64, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 63, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "expression": { + "id": 40, + "kind": "number", + "ref": 0o1_0123_00_000, + "value": 136937472n, }, - }, - { - "id": 66, - "kind": "def_argument", - "name": "b", - "ref": b: Int, + "id": 41, + "kind": "statement_let", + "name": "l", + "ref": let l: Int = 0o1_0123_00_000;, "type": { - "id": 65, + "id": 39, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - "attributes": [], - "id": 71, - "kind": "def_function", - "name": "oneMoreFunction", - "origin": "user", - "ref": fun oneMoreFunction( - a: Int, - b: Int, - ): Int { - return anotherFunction( - a, - b, - ); -}, - "return": { - "id": 62, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ - { - "expression": { - "args": [ - { - "id": 67, - "kind": "id", - "ref": a, - "value": "a", - }, - { - "id": 68, - "kind": "id", - "ref": b, - "value": "b", - }, - ], - "id": 69, - "kind": "op_static_call", - "name": "anotherFunction", - "ref": anotherFunction( - a, - b, - ), - }, - "id": 70, - "kind": "statement_return", - "ref": return anotherFunction( - a, - b, - );, - }, - ], - }, - { - "attributes": [], - "declarations": [ - { - "args": [ - { - "id": 73, - "kind": "def_argument", - "name": "arg1", - "ref": arg1: Int, - "type": { - "id": 72, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "id": 75, - "kind": "def_argument", - "name": "arg2", - "ref": arg2: Int, - "type": { - "id": 74, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], - "id": 76, - "kind": "def_init_function", - "ref": init( - arg1: Int, - arg2: Int, - ) {}, - "statements": [], - }, - ], - "id": 77, - "kind": "def_contract", - "name": "TestContract", - "origin": "user", - "ref": contract TestContract { - init( - arg1: Int, - arg2: Int, - ) {} -}, - "traits": [], - }, - { - "args": [], - "attributes": [], - "id": 83, - "kind": "def_function", - "name": "test", - "origin": "user", - "ref": fun test() { - let k: StateInit = initOf TestContract( - 2, - 3, - ); -}, - "return": null, - "statements": [ { "expression": { - "args": [ - { - "id": 79, - "kind": "number", - "ref": 2, - "value": 2n, + "id": 64, + "kind": "op_binary", + "left": { + "id": 62, + "kind": "op_binary", + "left": { + "id": 60, + "kind": "op_binary", + "left": { + "id": 58, + "kind": "op_binary", + "left": { + "id": 56, + "kind": "op_binary", + "left": { + "id": 54, + "kind": "op_binary", + "left": { + "id": 52, + "kind": "op_binary", + "left": { + "id": 50, + "kind": "op_binary", + "left": { + "id": 48, + "kind": "op_binary", + "left": { + "id": 46, + "kind": "op_binary", + "left": { + "id": 44, + "kind": "op_binary", + "left": { + "id": 42, + "kind": "id", + "ref": a, + "value": "a", + }, + "op": "+", + "ref": a + b, + "right": { + "id": 43, + "kind": "id", + "ref": b, + "value": "b", + }, + }, + "op": "+", + "ref": a + b + c, + "right": { + "id": 45, + "kind": "id", + "ref": c, + "value": "c", + }, + }, + "op": "+", + "ref": a + b + c + d, + "right": { + "id": 47, + "kind": "id", + "ref": d, + "value": "d", + }, + }, + "op": "+", + "ref": a + b + c + d + e, + "right": { + "id": 49, + "kind": "id", + "ref": e, + "value": "e", + }, + }, + "op": "+", + "ref": a + b + c + d + e + f, + "right": { + "id": 51, + "kind": "id", + "ref": f, + "value": "f", + }, + }, + "op": "+", + "ref": a + b + c + d + e + f + g, + "right": { + "id": 53, + "kind": "id", + "ref": g, + "value": "g", + }, + }, + "op": "+", + "ref": a + b + c + d + e + f + g + h, + "right": { + "id": 55, + "kind": "id", + "ref": h, + "value": "h", + }, + }, + "op": "+", + "ref": a + b + c + d + e + f + g + h + i, + "right": { + "id": 57, + "kind": "id", + "ref": i, + "value": "i", + }, + }, + "op": "+", + "ref": a + b + c + d + e + f + g + h + i + j, + "right": { + "id": 59, + "kind": "id", + "ref": j, + "value": "j", + }, }, - { - "id": 80, - "kind": "number", - "ref": 3, - "value": 3n, + "op": "+", + "ref": a + b + c + d + e + f + g + h + i + j + k, + "right": { + "id": 61, + "kind": "id", + "ref": k, + "value": "k", }, - ], - "id": 81, - "kind": "init_of", - "name": "TestContract", - "ref": initOf TestContract( - 2, - 3, - ), - }, - "id": 82, - "kind": "statement_let", - "name": "k", - "ref": let k: StateInit = initOf TestContract( - 2, - 3, - );, - "type": { - "id": 78, - "kind": "type_ref_simple", - "name": "StateInit", - "optional": false, - "ref": StateInit, - }, - }, - ], - }, - ], - "id": 84, - "kind": "program", -} -`; - -exports[`grammar should parse case-26 1`] = ` -{ - "entries": [ - { - "attributes": [], - "declarations": [ - { - "attributes": [ - { - "ref": override, - "type": "overrides", }, - ], - "id": 3, - "kind": "def_constant", - "name": "Test", - "ref": override const Test: Int = 0;, - "type": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "value": { - "id": 2, - "kind": "number", - "ref": 0, - "value": 0n, + "op": "+", + "ref": a + b + c + d + e + f + g + h + i + j + k + l, + "right": { + "id": 63, + "kind": "id", + "ref": l, + "value": "l", + }, }, + "id": 65, + "kind": "statement_return", + "ref": return a + b + c + d + e + f + g + h + i + j + k + l;, }, ], - "id": 4, - "kind": "def_contract", - "name": "Contract", - "origin": "user", - "ref": contract Contract { - override const Test: Int = 0; -}, - "traits": [], }, ], - "id": 5, + "id": 67, "kind": "program", } `; -exports[`grammar should parse case-27 1`] = ` +exports[`grammar should parse stmt-augmented-assign-arith 1`] = ` { "entries": [ { @@ -4388,30 +4373,32 @@ exports[`grammar should parse case-27 1`] = ` } `; -exports[`grammar should parse case-28 1`] = ` +exports[`grammar should parse stmt-augmented-assign-bitwise 1`] = ` { "entries": [ { "args": [], "attributes": [], - "id": 66, + "id": 52, "kind": "def_function", - "name": "test_fun", + "name": "testFunc", "origin": "user", - "ref": fun test_fun(): Int { - let a: Int = 123; - let b: Int = -123; - let c: Int = 1_0123_00_000; - let d: Int = 0x123; - let e: Int = -0x123; - let f: Int = 0x1_0123_00_000; - let g: Int = 0b101010; - let h: Int = -0b101010; - let i: Int = 0b1_0101_00_000; - let j: Int = 0o123; - let k: Int = -0o123; - let l: Int = 0o1_0123_00_000; - return a + b + c + d + e + f + g + h + i + j + k + l; + "ref": fun testFunc(): Int { + let a: Int = 1; + let b: Int = 2; + a |= b; + b |= a; + a |= 3; + a |= b | 4; + b &= 1; + a &= b; + b &= a; + a &= b & 1; + b ^= 2; + a ^= b; + b ^= a; + a ^= b ^ 2; + return a; }, "return": { "id": 1, @@ -4425,13 +4412,13 @@ exports[`grammar should parse case-28 1`] = ` "expression": { "id": 3, "kind": "number", - "ref": 123, - "value": 123n, + "ref": 1, + "value": 1n, }, "id": 4, "kind": "statement_let", "name": "a", - "ref": let a: Int = 123;, + "ref": let a: Int = 1;, "type": { "id": 2, "kind": "type_ref_simple", @@ -4442,21 +4429,15 @@ exports[`grammar should parse case-28 1`] = ` }, { "expression": { - "id": 7, - "kind": "op_unary", - "op": "-", - "ref": -123, - "right": { - "id": 6, - "kind": "number", - "ref": 123, - "value": 123n, - }, + "id": 6, + "kind": "number", + "ref": 2, + "value": 2n, }, - "id": 8, + "id": 7, "kind": "statement_let", "name": "b", - "ref": let b: Int = -123;, + "ref": let b: Int = 2;, "type": { "id": 5, "kind": "type_ref_simple", @@ -4467,364 +4448,300 @@ exports[`grammar should parse case-28 1`] = ` }, { "expression": { - "id": 10, - "kind": "number", - "ref": 1_0123_00_000, - "value": 1012300000n, - }, - "id": 11, - "kind": "statement_let", - "name": "c", - "ref": let c: Int = 1_0123_00_000;, - "type": { "id": 9, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "kind": "id", + "ref": b, + "value": "b", }, + "id": 10, + "kind": "statement_augmentedassign", + "op": "|", + "path": [ + { + "id": 8, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a |= b;, }, { "expression": { - "id": 13, - "kind": "number", - "ref": 0x123, - "value": 291n, - }, - "id": 14, - "kind": "statement_let", - "name": "d", - "ref": let d: Int = 0x123;, - "type": { "id": 12, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "kind": "id", + "ref": a, + "value": "a", }, + "id": 13, + "kind": "statement_augmentedassign", + "op": "|", + "path": [ + { + "id": 11, + "kind": "lvalue_ref", + "name": "b", + "ref": b, + }, + ], + "ref": b |= a;, }, { "expression": { - "id": 17, - "kind": "op_unary", - "op": "-", - "ref": -0x123, - "right": { - "id": 16, - "kind": "number", - "ref": 0x123, - "value": 291n, - }, - }, - "id": 18, - "kind": "statement_let", - "name": "e", - "ref": let e: Int = -0x123;, - "type": { "id": 15, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "kind": "number", + "ref": 3, + "value": 3n, }, + "id": 16, + "kind": "statement_augmentedassign", + "op": "|", + "path": [ + { + "id": 14, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a |= 3;, }, { "expression": { "id": 20, - "kind": "number", - "ref": 0x1_0123_00_000, - "value": 69024612352n, + "kind": "op_binary", + "left": { + "id": 18, + "kind": "id", + "ref": b, + "value": "b", + }, + "op": "|", + "ref": b | 4, + "right": { + "id": 19, + "kind": "number", + "ref": 4, + "value": 4n, + }, }, "id": 21, - "kind": "statement_let", - "name": "f", - "ref": let f: Int = 0x1_0123_00_000;, - "type": { - "id": 19, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, + "kind": "statement_augmentedassign", + "op": "|", + "path": [ + { + "id": 17, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a |= b | 4;, }, { "expression": { "id": 23, "kind": "number", - "ref": 0b101010, - "value": 42n, + "ref": 1, + "value": 1n, }, "id": 24, - "kind": "statement_let", - "name": "g", - "ref": let g: Int = 0b101010;, - "type": { - "id": 22, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "expression": { - "id": 27, - "kind": "op_unary", - "op": "-", - "ref": -0b101010, - "right": { - "id": 26, - "kind": "number", - "ref": 0b101010, - "value": 42n, + "kind": "statement_augmentedassign", + "op": "&", + "path": [ + { + "id": 22, + "kind": "lvalue_ref", + "name": "b", + "ref": b, }, - }, - "id": 28, - "kind": "statement_let", - "name": "h", - "ref": let h: Int = -0b101010;, - "type": { - "id": 25, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, + ], + "ref": b &= 1;, }, { "expression": { - "id": 30, - "kind": "number", - "ref": 0b1_0101_00_000, - "value": 672n, - }, - "id": 31, - "kind": "statement_let", - "name": "i", - "ref": let i: Int = 0b1_0101_00_000;, - "type": { - "id": 29, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "id": 26, + "kind": "id", + "ref": b, + "value": "b", }, + "id": 27, + "kind": "statement_augmentedassign", + "op": "&", + "path": [ + { + "id": 25, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a &= b;, }, { "expression": { - "id": 33, - "kind": "number", - "ref": 0o123, - "value": 83n, - }, - "id": 34, - "kind": "statement_let", - "name": "j", - "ref": let j: Int = 0o123;, - "type": { - "id": 32, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "id": 29, + "kind": "id", + "ref": a, + "value": "a", }, + "id": 30, + "kind": "statement_augmentedassign", + "op": "&", + "path": [ + { + "id": 28, + "kind": "lvalue_ref", + "name": "b", + "ref": b, + }, + ], + "ref": b &= a;, }, { "expression": { - "id": 37, - "kind": "op_unary", - "op": "-", - "ref": -0o123, + "id": 34, + "kind": "op_binary", + "left": { + "id": 32, + "kind": "id", + "ref": b, + "value": "b", + }, + "op": "&", + "ref": b & 1, "right": { - "id": 36, + "id": 33, "kind": "number", - "ref": 0o123, - "value": 83n, + "ref": 1, + "value": 1n, }, }, - "id": 38, - "kind": "statement_let", - "name": "k", - "ref": let k: Int = -0o123;, - "type": { - "id": 35, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "id": 35, + "kind": "statement_augmentedassign", + "op": "&", + "path": [ + { + "id": 31, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a &= b & 1;, + }, + { + "expression": { + "id": 37, + "kind": "number", + "ref": 2, + "value": 2n, }, + "id": 38, + "kind": "statement_augmentedassign", + "op": "^", + "path": [ + { + "id": 36, + "kind": "lvalue_ref", + "name": "b", + "ref": b, + }, + ], + "ref": b ^= 2;, }, { "expression": { "id": 40, - "kind": "number", - "ref": 0o1_0123_00_000, - "value": 136937472n, + "kind": "id", + "ref": b, + "value": "b", }, "id": 41, - "kind": "statement_let", - "name": "l", - "ref": let l: Int = 0o1_0123_00_000;, - "type": { - "id": 39, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "kind": "statement_augmentedassign", + "op": "^", + "path": [ + { + "id": 39, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a ^= b;, + }, + { + "expression": { + "id": 43, + "kind": "id", + "ref": a, + "value": "a", }, + "id": 44, + "kind": "statement_augmentedassign", + "op": "^", + "path": [ + { + "id": 42, + "kind": "lvalue_ref", + "name": "b", + "ref": b, + }, + ], + "ref": b ^= a;, }, { "expression": { - "id": 64, + "id": 48, "kind": "op_binary", "left": { - "id": 62, - "kind": "op_binary", - "left": { - "id": 60, - "kind": "op_binary", - "left": { - "id": 58, - "kind": "op_binary", - "left": { - "id": 56, - "kind": "op_binary", - "left": { - "id": 54, - "kind": "op_binary", - "left": { - "id": 52, - "kind": "op_binary", - "left": { - "id": 50, - "kind": "op_binary", - "left": { - "id": 48, - "kind": "op_binary", - "left": { - "id": 46, - "kind": "op_binary", - "left": { - "id": 44, - "kind": "op_binary", - "left": { - "id": 42, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "+", - "ref": a + b, - "right": { - "id": 43, - "kind": "id", - "ref": b, - "value": "b", - }, - }, - "op": "+", - "ref": a + b + c, - "right": { - "id": 45, - "kind": "id", - "ref": c, - "value": "c", - }, - }, - "op": "+", - "ref": a + b + c + d, - "right": { - "id": 47, - "kind": "id", - "ref": d, - "value": "d", - }, - }, - "op": "+", - "ref": a + b + c + d + e, - "right": { - "id": 49, - "kind": "id", - "ref": e, - "value": "e", - }, - }, - "op": "+", - "ref": a + b + c + d + e + f, - "right": { - "id": 51, - "kind": "id", - "ref": f, - "value": "f", - }, - }, - "op": "+", - "ref": a + b + c + d + e + f + g, - "right": { - "id": 53, - "kind": "id", - "ref": g, - "value": "g", - }, - }, - "op": "+", - "ref": a + b + c + d + e + f + g + h, - "right": { - "id": 55, - "kind": "id", - "ref": h, - "value": "h", - }, - }, - "op": "+", - "ref": a + b + c + d + e + f + g + h + i, - "right": { - "id": 57, - "kind": "id", - "ref": i, - "value": "i", - }, - }, - "op": "+", - "ref": a + b + c + d + e + f + g + h + i + j, - "right": { - "id": 59, - "kind": "id", - "ref": j, - "value": "j", - }, - }, - "op": "+", - "ref": a + b + c + d + e + f + g + h + i + j + k, - "right": { - "id": 61, - "kind": "id", - "ref": k, - "value": "k", - }, + "id": 46, + "kind": "id", + "ref": b, + "value": "b", }, - "op": "+", - "ref": a + b + c + d + e + f + g + h + i + j + k + l, + "op": "^", + "ref": b ^ 2, "right": { - "id": 63, - "kind": "id", - "ref": l, - "value": "l", + "id": 47, + "kind": "number", + "ref": 2, + "value": 2n, }, }, - "id": 65, - "kind": "statement_return", - "ref": return a + b + c + d + e + f + g + h + i + j + k + l;, - }, - ], - }, - ], - "id": 67, + "id": 49, + "kind": "statement_augmentedassign", + "op": "^", + "path": [ + { + "id": 45, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": a ^= b ^ 2;, + }, + { + "expression": { + "id": 50, + "kind": "id", + "ref": a, + "value": "a", + }, + "id": 51, + "kind": "statement_return", + "ref": return a;, + }, + ], + }, + ], + "id": 53, "kind": "program", } `; -exports[`grammar should parse case-29 1`] = ` +exports[`grammar should parse stmt-if 1`] = ` { "entries": [ { @@ -4832,25 +4749,27 @@ exports[`grammar should parse case-29 1`] = ` { "id": 3, "kind": "def_argument", - "name": "a", - "ref": a: Int, + "name": "src", + "ref": src: Int?, "type": { "id": 2, "kind": "type_ref_simple", "name": "Int", - "optional": false, - "ref": Int, + "optional": true, + "ref": Int?, }, }, ], "attributes": [], - "id": 14, + "id": 12, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc(a: Int): Int { - let b: Int = a == 123 ? 1 : 2; - return b; + "ref": fun testFunc(src: Int?): Int { + if (src != null) { + return src; + } + return 0; }, "return": { "id": 1, @@ -4861,73 +4780,64 @@ exports[`grammar should parse case-29 1`] = ` }, "statements": [ { + "elseif": null, "expression": { - "condition": { - "id": 7, - "kind": "op_binary", - "left": { - "id": 5, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "==", - "ref": a == 123, - "right": { - "id": 6, - "kind": "number", - "ref": 123, - "value": 123n, - }, + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "id", + "ref": src, + "value": "src", }, - "elseBranch": { - "id": 9, - "kind": "number", - "ref": 2, - "value": 2n, + "op": "!=", + "ref": src != null, + "right": { + "id": 5, + "kind": "null", + "ref": null, }, - "id": 10, - "kind": "conditional", - "ref": a == 123 ? 1 : 2, - "thenBranch": { + }, + "falseStatements": null, + "id": 9, + "kind": "statement_condition", + "ref": if (src != null) { + return src; + }, + "trueStatements": [ + { + "expression": { + "id": 7, + "kind": "id", + "ref": src, + "value": "src", + }, "id": 8, - "kind": "number", - "ref": 1, - "value": 1n, + "kind": "statement_return", + "ref": return src;, }, - }, - "id": 11, - "kind": "statement_let", - "name": "b", - "ref": let b: Int = a == 123 ? 1 : 2;, - "type": { - "id": 4, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, + ], }, { "expression": { - "id": 12, - "kind": "id", - "ref": b, - "value": "b", + "id": 10, + "kind": "number", + "ref": 0, + "value": 0n, }, - "id": 13, + "id": 11, "kind": "statement_return", - "ref": return b;, + "ref": return 0;, }, ], }, ], - "id": 15, + "id": 13, "kind": "program", } `; -exports[`grammar should parse case-30 1`] = ` +exports[`grammar should parse stmt-if-else 1`] = ` { "entries": [ { @@ -4935,24 +4845,28 @@ exports[`grammar should parse case-30 1`] = ` { "id": 3, "kind": "def_argument", - "name": "a", - "ref": a: Int, + "name": "src", + "ref": src: Int?, "type": { "id": 2, "kind": "type_ref_simple", "name": "Int", - "optional": false, - "ref": Int, + "optional": true, + "ref": Int?, }, }, ], "attributes": [], - "id": 11, + "id": 12, "kind": "def_function", "name": "testFunc", "origin": "user", - "ref": fun testFunc(a: Int): Int { - return a == 123 ? 1 : 2; + "ref": fun testFunc(src: Int?): Int { + if (src != null) { + return src; + } else { + return 10; + } }, "return": { "id": 1, @@ -4963,421 +4877,383 @@ exports[`grammar should parse case-30 1`] = ` }, "statements": [ { + "elseif": null, "expression": { - "condition": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "==", - "ref": a == 123, - "right": { - "id": 5, + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "id", + "ref": src, + "value": "src", + }, + "op": "!=", + "ref": src != null, + "right": { + "id": 5, + "kind": "null", + "ref": null, + }, + }, + "falseStatements": [ + { + "expression": { + "id": 9, "kind": "number", - "ref": 123, - "value": 123n, + "ref": 10, + "value": 10n, }, + "id": 10, + "kind": "statement_return", + "ref": return 10;, }, - "elseBranch": { + ], + "id": 11, + "kind": "statement_condition", + "ref": if (src != null) { + return src; + } else { + return 10; + }, + "trueStatements": [ + { + "expression": { + "id": 7, + "kind": "id", + "ref": src, + "value": "src", + }, "id": 8, - "kind": "number", - "ref": 2, - "value": 2n, - }, - "id": 9, - "kind": "conditional", - "ref": a == 123 ? 1 : 2, - "thenBranch": { - "id": 7, - "kind": "number", - "ref": 1, - "value": 1n, + "kind": "statement_return", + "ref": return src;, }, - }, - "id": 10, - "kind": "statement_return", - "ref": return a == 123 ? 1 : 2;, + ], }, ], }, ], - "id": 12, + "id": 13, "kind": "program", } `; -exports[`grammar should parse case-31 1`] = ` +exports[`grammar should parse stmt-while-loop 1`] = ` { "entries": [ { - "args": [ - { - "id": 3, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 2, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], + "args": [], "attributes": [], - "id": 19, + "id": 17, "kind": "def_function", - "name": "testFunc", + "name": "main", "origin": "user", - "ref": fun testFunc(a: Int): Int { - return a == 123 || a == 456 ? a + 1 : a + 2; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, + "ref": fun main() { + let i: Int = 1; + while(i >= 10 || i <= 100) { + i = i + 1; + } +}, + "return": null, "statements": [ { "expression": { - "condition": { - "id": 10, - "kind": "op_binary", - "left": { - "id": 6, - "kind": "op_binary", - "left": { - "id": 4, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "==", - "ref": a == 123, - "right": { - "id": 5, - "kind": "number", - "ref": 123, - "value": 123n, - }, - }, - "op": "||", - "ref": a == 123 || a == 456, - "right": { - "id": 9, - "kind": "op_binary", - "left": { - "id": 7, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "==", - "ref": a == 456, - "right": { - "id": 8, - "kind": "number", - "ref": 456, - "value": 456n, - }, - }, - }, - "elseBranch": { - "id": 16, + "id": 2, + "kind": "number", + "ref": 1, + "value": 1n, + }, + "id": 3, + "kind": "statement_let", + "name": "i", + "ref": let i: Int = 1;, + "type": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "condition": { + "id": 10, + "kind": "op_binary", + "left": { + "id": 6, "kind": "op_binary", "left": { - "id": 14, + "id": 4, "kind": "id", - "ref": a, - "value": "a", + "ref": i, + "value": "i", }, - "op": "+", - "ref": a + 2, + "op": ">=", + "ref": i >= 10, "right": { - "id": 15, + "id": 5, "kind": "number", - "ref": 2, - "value": 2n, + "ref": 10, + "value": 10n, }, }, - "id": 17, - "kind": "conditional", - "ref": a == 123 || a == 456 ? a + 1 : a + 2, - "thenBranch": { - "id": 13, + "op": "||", + "ref": i >= 10 || i <= 100, + "right": { + "id": 9, "kind": "op_binary", "left": { - "id": 11, + "id": 7, "kind": "id", - "ref": a, - "value": "a", + "ref": i, + "value": "i", }, - "op": "+", - "ref": a + 1, + "op": "<=", + "ref": i <= 100, "right": { - "id": 12, + "id": 8, "kind": "number", - "ref": 1, - "value": 1n, + "ref": 100, + "value": 100n, }, }, }, - "id": 18, - "kind": "statement_return", - "ref": return a == 123 || a == 456 ? a + 1 : a + 2;, + "id": 16, + "kind": "statement_while", + "ref": while(i >= 10 || i <= 100) { + i = i + 1; + }, + "statements": [ + { + "expression": { + "id": 14, + "kind": "op_binary", + "left": { + "id": 12, + "kind": "id", + "ref": i, + "value": "i", + }, + "op": "+", + "ref": i + 1, + "right": { + "id": 13, + "kind": "number", + "ref": 1, + "value": 1n, + }, + }, + "id": 15, + "kind": "statement_assign", + "path": [ + { + "id": 11, + "kind": "lvalue_ref", + "name": "i", + "ref": i, + }, + ], + "ref": i = i + 1;, + }, + ], }, ], }, ], - "id": 20, + "id": 18, "kind": "program", } `; -exports[`grammar should parse case-32 1`] = ` +exports[`grammar should parse stmt-while-repeat-do-loops 1`] = ` { "entries": [ { - "args": [ + "args": [], + "attributes": [], + "id": 25, + "kind": "def_function", + "name": "main", + "origin": "user", + "ref": fun main() { + let i: Int = 1; + while(true) { + i = i + 1; + } + repeat(10) { + i = i * 10; + } + do { + i = i - 1; + } until(false); +}, + "return": null, + "statements": [ { + "expression": { + "id": 2, + "kind": "number", + "ref": 1, + "value": 1n, + }, "id": 3, - "kind": "def_argument", - "name": "a", - "ref": a: Int, + "kind": "statement_let", + "name": "i", + "ref": let i: Int = 1;, "type": { - "id": 2, + "id": 1, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, - ], - "attributes": [], - "id": 24, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(a: Int): Int { - return a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2; -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ { - "expression": { - "condition": { - "id": 10, - "kind": "op_binary", - "left": { - "id": 6, + "condition": { + "id": 4, + "kind": "boolean", + "ref": true, + "value": true, + }, + "id": 10, + "kind": "statement_while", + "ref": while(true) { + i = i + 1; + }, + "statements": [ + { + "expression": { + "id": 8, "kind": "op_binary", "left": { - "id": 4, + "id": 6, "kind": "id", - "ref": a, - "value": "a", + "ref": i, + "value": "i", }, - "op": "==", - "ref": a == 123, + "op": "+", + "ref": i + 1, "right": { - "id": 5, + "id": 7, "kind": "number", - "ref": 123, - "value": 123n, + "ref": 1, + "value": 1n, }, }, - "op": "||", - "ref": a == 123 || a == 456, - "right": { - "id": 9, - "kind": "op_binary", - "left": { - "id": 7, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "==", - "ref": a == 456, - "right": { - "id": 8, - "kind": "number", - "ref": 456, - "value": 456n, + "id": 9, + "kind": "statement_assign", + "path": [ + { + "id": 5, + "kind": "lvalue_ref", + "name": "i", + "ref": i, }, - }, - }, - "elseBranch": { - "id": 21, - "kind": "op_binary", - "left": { - "id": 19, - "kind": "id", - "ref": a, - "value": "a", - }, - "op": "+", - "ref": a + 2, - "right": { - "id": 20, - "kind": "number", - "ref": 2, - "value": 2n, - }, + ], + "ref": i = i + 1;, }, - "id": 22, - "kind": "conditional", - "ref": a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2, - "thenBranch": { - "condition": { - "id": 13, + ], + }, + { + "id": 17, + "iterations": { + "id": 11, + "kind": "number", + "ref": 10, + "value": 10n, + }, + "kind": "statement_repeat", + "ref": repeat(10) { + i = i * 10; + }, + "statements": [ + { + "expression": { + "id": 15, "kind": "op_binary", "left": { - "id": 11, + "id": 13, "kind": "id", - "ref": a, - "value": "a", + "ref": i, + "value": "i", }, - "op": "==", - "ref": a == 10, + "op": "*", + "ref": i * 10, "right": { - "id": 12, + "id": 14, "kind": "number", "ref": 10, "value": 10n, }, }, - "elseBranch": { - "id": 17, + "id": 16, + "kind": "statement_assign", + "path": [ + { + "id": 12, + "kind": "lvalue_ref", + "name": "i", + "ref": i, + }, + ], + "ref": i = i * 10;, + }, + ], + }, + { + "condition": { + "id": 18, + "kind": "boolean", + "ref": false, + "value": false, + }, + "id": 24, + "kind": "statement_until", + "ref": do { + i = i - 1; + } until(false);, + "statements": [ + { + "expression": { + "id": 22, "kind": "op_binary", "left": { - "id": 15, + "id": 20, "kind": "id", - "ref": a, - "value": "a", + "ref": i, + "value": "i", }, - "op": "*", - "ref": a * 2, + "op": "-", + "ref": i - 1, "right": { - "id": 16, + "id": 21, "kind": "number", - "ref": 2, - "value": 2n, + "ref": 1, + "value": 1n, }, }, - "id": 18, - "kind": "conditional", - "ref": a == 10 ? a : a * 2, - "thenBranch": { - "id": 14, - "kind": "id", - "ref": a, - "value": "a", - }, - }, - }, - "id": 23, - "kind": "statement_return", - "ref": return a == 123 || a == 456 ? (a == 10 ? a : a * 2) : a + 2;, - }, - ], - }, - ], - "id": 25, - "kind": "program", -} -`; - -exports[`grammar should parse case-33 1`] = ` -{ - "entries": [ - { - "args": [ - { - "id": 3, - "kind": "def_argument", - "name": "m", - "ref": m: map, - "type": { - "id": 2, - "key": "Int", - "keyAs": null, - "kind": "type_ref_map", - "ref": map, - "value": "Int", - "valueAs": null, - }, - }, - ], - "attributes": [], - "id": 9, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(m: map): Int { - return m.asCell()!!.hash(); -}, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ - { - "expression": { - "args": [], - "id": 7, - "kind": "op_call", - "name": "hash", - "ref": m.asCell()!!.hash(), - "src": { - "id": 6, - "kind": "op_unary", - "op": "!!", - "ref": m.asCell()!!, - "right": { - "args": [], - "id": 5, - "kind": "op_call", - "name": "asCell", - "ref": m.asCell(), - "src": { - "id": 4, - "kind": "id", - "ref": m, - "value": "m", + "id": 23, + "kind": "statement_assign", + "path": [ + { + "id": 19, + "kind": "lvalue_ref", + "name": "i", + "ref": i, }, - }, + ], + "ref": i = i - 1;, }, - }, - "id": 8, - "kind": "statement_return", - "ref": return m.asCell()!!.hash();, + ], }, ], }, ], - "id": 10, + "id": 26, "kind": "program", } `; -exports[`grammar should parse case-34 1`] = ` +exports[`grammar should parse struct-field-punning 1`] = ` { "entries": [ { @@ -5516,375 +5392,168 @@ exports[`grammar should parse case-34 1`] = ` } `; -exports[`grammar should parse case-35 1`] = ` +exports[`grammar should parse struct-msg-as 1`] = ` { "entries": [ { - "args": [], - "attributes": [], - "id": 52, - "kind": "def_function", - "name": "testFunc", + "fields": [ + { + "as": null, + "id": 2, + "init": null, + "kind": "def_field", + "name": "x", + "ref": x: Int, + "type": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 3, + "kind": "def_struct", + "message": false, + "name": "A", "origin": "user", - "ref": fun testFunc(): Int { - let a: Int = 1; - let b: Int = 2; - a |= b; - b |= a; - a |= 3; - a |= b | 4; - b &= 1; - a &= b; - b &= a; - a &= b & 1; - b ^= 2; - a ^= b; - b ^= a; - a ^= b ^ 2; - return a; + "prefix": null, + "ref": struct A { + x: Int; }, - "return": { - "id": 1, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + }, + { + "fields": [ { - "expression": { - "id": 3, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "id": 4, - "kind": "statement_let", - "name": "a", - "ref": let a: Int = 1;, + "as": "coin", + "id": 5, + "init": null, + "kind": "def_field", + "name": "x", + "ref": x: Int as coin, "type": { - "id": 2, + "id": 4, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, + ], + "id": 6, + "kind": "def_struct", + "message": true, + "name": "B", + "origin": "user", + "prefix": null, + "ref": message B { + x: Int as coin; +}, + }, + ], + "id": 7, + "kind": "program", +} +`; + +exports[`grammar should parse struct-msg-initializers 1`] = ` +{ + "entries": [ + { + "fields": [ { - "expression": { - "id": 6, + "as": null, + "id": 3, + "init": { + "id": 2, "kind": "number", - "ref": 2, - "value": 2n, + "ref": 1000, + "value": 1000n, }, - "id": 7, - "kind": "statement_let", - "name": "b", - "ref": let b: Int = 2;, + "kind": "def_field", + "name": "x", + "ref": x: Int = 1000, "type": { - "id": 5, + "id": 1, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, }, + ], + "id": 4, + "kind": "def_struct", + "message": false, + "name": "A", + "origin": "user", + "prefix": null, + "ref": struct A { + x: Int = 1000; +}, + }, + { + "fields": [ { - "expression": { - "id": 9, - "kind": "id", - "ref": b, - "value": "b", - }, - "id": 10, - "kind": "statement_augmentedassign", - "op": "|", - "path": [ - { - "id": 8, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a |= b;, - }, - { - "expression": { - "id": 12, - "kind": "id", - "ref": a, - "value": "a", - }, - "id": 13, - "kind": "statement_augmentedassign", - "op": "|", - "path": [ - { - "id": 11, - "kind": "lvalue_ref", - "name": "b", - "ref": b, - }, - ], - "ref": b |= a;, - }, - { - "expression": { - "id": 15, - "kind": "number", - "ref": 3, - "value": 3n, - }, - "id": 16, - "kind": "statement_augmentedassign", - "op": "|", - "path": [ - { - "id": 14, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a |= 3;, - }, - { - "expression": { - "id": 20, - "kind": "op_binary", - "left": { - "id": 18, - "kind": "id", - "ref": b, - "value": "b", - }, - "op": "|", - "ref": b | 4, - "right": { - "id": 19, - "kind": "number", - "ref": 4, - "value": 4n, - }, - }, - "id": 21, - "kind": "statement_augmentedassign", - "op": "|", - "path": [ - { - "id": 17, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a |= b | 4;, - }, - { - "expression": { - "id": 23, - "kind": "number", - "ref": 1, - "value": 1n, - }, - "id": 24, - "kind": "statement_augmentedassign", - "op": "&", - "path": [ - { - "id": 22, - "kind": "lvalue_ref", - "name": "b", - "ref": b, - }, - ], - "ref": b &= 1;, - }, - { - "expression": { - "id": 26, - "kind": "id", - "ref": b, - "value": "b", - }, - "id": 27, - "kind": "statement_augmentedassign", - "op": "&", - "path": [ - { - "id": 25, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a &= b;, - }, - { - "expression": { - "id": 29, - "kind": "id", - "ref": a, - "value": "a", - }, - "id": 30, - "kind": "statement_augmentedassign", - "op": "&", - "path": [ - { - "id": 28, - "kind": "lvalue_ref", - "name": "b", - "ref": b, - }, - ], - "ref": b &= a;, - }, - { - "expression": { - "id": 34, - "kind": "op_binary", - "left": { - "id": 32, - "kind": "id", - "ref": b, - "value": "b", - }, - "op": "&", - "ref": b & 1, - "right": { - "id": 33, - "kind": "number", - "ref": 1, - "value": 1n, - }, - }, - "id": 35, - "kind": "statement_augmentedassign", - "op": "&", - "path": [ - { - "id": 31, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a &= b & 1;, - }, - { - "expression": { - "id": 37, + "as": "coins", + "id": 7, + "init": { + "id": 6, "kind": "number", - "ref": 2, - "value": 2n, - }, - "id": 38, - "kind": "statement_augmentedassign", - "op": "^", - "path": [ - { - "id": 36, - "kind": "lvalue_ref", - "name": "b", - "ref": b, - }, - ], - "ref": b ^= 2;, - }, - { - "expression": { - "id": 40, - "kind": "id", - "ref": b, - "value": "b", + "ref": 1000, + "value": 1000n, }, - "id": 41, - "kind": "statement_augmentedassign", - "op": "^", - "path": [ - { - "id": 39, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a ^= b;, - }, - { - "expression": { - "id": 43, - "kind": "id", - "ref": a, - "value": "a", + "kind": "def_field", + "name": "x", + "ref": x: Int as coins = 1000, + "type": { + "id": 5, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, - "id": 44, - "kind": "statement_augmentedassign", - "op": "^", - "path": [ - { - "id": 42, - "kind": "lvalue_ref", - "name": "b", - "ref": b, - }, - ], - "ref": b ^= a;, }, { - "expression": { - "id": 48, - "kind": "op_binary", - "left": { - "id": 46, - "kind": "id", - "ref": b, - "value": "b", - }, - "op": "^", - "ref": b ^ 2, - "right": { - "id": 47, - "kind": "number", - "ref": 2, - "value": 2n, - }, + "as": null, + "id": 10, + "init": { + "id": 9, + "kind": "boolean", + "ref": true, + "value": true, }, - "id": 49, - "kind": "statement_augmentedassign", - "op": "^", - "path": [ - { - "id": 45, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": a ^= b ^ 2;, - }, - { - "expression": { - "id": 50, - "kind": "id", - "ref": a, - "value": "a", + "kind": "def_field", + "name": "y", + "ref": y: Bool = true, + "type": { + "id": 8, + "kind": "type_ref_simple", + "name": "Bool", + "optional": false, + "ref": Bool, }, - "id": 51, - "kind": "statement_return", - "ref": return a;, }, ], + "id": 11, + "kind": "def_struct", + "message": true, + "name": "B", + "origin": "user", + "prefix": null, + "ref": message B { + x: Int as coins = 1000; + y: Bool = true; +}, }, ], - "id": 53, + "id": 12, "kind": "program", } `; -exports[`grammar should parse case-36 1`] = ` +exports[`grammar should parse struct-msg-trailing-semicolon 1`] = ` { "entries": [ { @@ -6047,16 +5716,255 @@ exports[`grammar should parse case-36 1`] = ` "ref": struct D { x: Int = 42; y: Int }, }, { - "fields": [ + "fields": [ + { + "as": null, + "id": 22, + "init": null, + "kind": "def_field", + "name": "x", + "ref": x: Int, + "type": { + "id": 21, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 23, + "kind": "def_struct", + "message": true, + "name": "E", + "origin": "user", + "prefix": null, + "ref": message E { x: Int }, + }, + { + "fields": [ + { + "as": null, + "id": 25, + "init": null, + "kind": "def_field", + "name": "x", + "ref": x: Int, + "type": { + "id": 24, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "as": null, + "id": 27, + "init": null, + "kind": "def_field", + "name": "y", + "ref": y: Int, + "type": { + "id": 26, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 28, + "kind": "def_struct", + "message": true, + "name": "F", + "origin": "user", + "prefix": null, + "ref": message F { x: Int; y: Int }, + }, + { + "fields": [ + { + "as": null, + "id": 30, + "init": null, + "kind": "def_field", + "name": "x", + "ref": x: Int, + "type": { + "id": 29, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "as": null, + "id": 33, + "init": { + "id": 32, + "kind": "number", + "ref": 42, + "value": 42n, + }, + "kind": "def_field", + "name": "y", + "ref": y: Int = 42, + "type": { + "id": 31, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 34, + "kind": "def_struct", + "message": true, + "name": "G", + "origin": "user", + "prefix": null, + "ref": message G { x: Int; y: Int = 42 }, + }, + { + "fields": [ + { + "as": null, + "id": 37, + "init": { + "id": 36, + "kind": "number", + "ref": 42, + "value": 42n, + }, + "kind": "def_field", + "name": "x", + "ref": x: Int = 42, + "type": { + "id": 35, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "as": null, + "id": 39, + "init": null, + "kind": "def_field", + "name": "y", + "ref": y: Int, + "type": { + "id": 38, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 40, + "kind": "def_struct", + "message": true, + "name": "G", + "origin": "user", + "prefix": null, + "ref": message G { x: Int = 42; y: Int }, + }, + ], + "id": 41, + "kind": "program", +} +`; + +exports[`grammar should parse traits-inheritance-trailing-comma 1`] = ` +{ + "entries": [ + { + "id": 1, + "kind": "primitive", + "name": "Int", + "origin": "user", + "ref": primitive Int;, + }, + { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 3, + "init": null, + "kind": "def_field", + "name": "c", + "ref": c: Int, + "type": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 4, + "kind": "def_trait", + "name": "OtherTrait", + "origin": "user", + "ref": trait OtherTrait { + c: Int; +}, + "traits": [], + }, + { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 6, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int, + "type": { + "id": 5, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 8, + "kind": "def_trait", + "name": "SomeTrait", + "origin": "user", + "ref": trait SomeTrait with OtherTrait, { + a: Int; +}, + "traits": [ + { + "id": 7, + "kind": "id", + "ref": OtherTrait, + "value": "OtherTrait", + }, + ], + }, + { + "attributes": [], + "declarations": [ { "as": null, - "id": 22, + "id": 10, "init": null, "kind": "def_field", - "name": "x", - "ref": x: Int, + "name": "b", + "ref": b: Int, "type": { - "id": 21, + "id": 9, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -6064,149 +5972,201 @@ exports[`grammar should parse case-36 1`] = ` }, }, ], - "id": 23, - "kind": "def_struct", - "message": true, - "name": "E", + "id": 12, + "kind": "def_contract", + "name": "Main", "origin": "user", - "prefix": null, - "ref": message E { x: Int }, + "ref": contract Main with SomeTrait, { + b: Int; +}, + "traits": [ + { + "id": 11, + "kind": "id", + "ref": SomeTrait, + "value": "SomeTrait", + }, + ], }, + ], + "id": 13, + "kind": "program", +} +`; + +exports[`grammar should parse type-struct-with-map 1`] = ` +{ + "entries": [ { "fields": [ { "as": null, - "id": 25, - "init": null, - "kind": "def_field", - "name": "x", - "ref": x: Int, - "type": { - "id": 24, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "as": null, - "id": 27, + "id": 2, "init": null, "kind": "def_field", "name": "y", - "ref": y: Int, + "ref": y: map, "type": { - "id": 26, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "id": 1, + "key": "Int", + "keyAs": null, + "kind": "type_ref_map", + "ref": map, + "value": "Int", + "valueAs": null, }, }, ], - "id": 28, + "id": 3, "kind": "def_struct", - "message": true, - "name": "F", + "message": false, + "name": "A", "origin": "user", "prefix": null, - "ref": message F { x: Int; y: Int }, + "ref": struct A { + y: map; +}, }, { "fields": [ { "as": null, - "id": 30, + "id": 5, "init": null, "kind": "def_field", "name": "x", - "ref": x: Int, - "type": { - "id": 29, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { - "as": null, - "id": 33, - "init": { - "id": 32, - "kind": "number", - "ref": 42, - "value": 42n, - }, - "kind": "def_field", - "name": "y", - "ref": y: Int = 42, + "ref": x: map, "type": { - "id": 31, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "id": 4, + "key": "Int", + "keyAs": null, + "kind": "type_ref_map", + "ref": map, + "value": "Int", + "valueAs": null, }, }, ], - "id": 34, + "id": 6, "kind": "def_struct", "message": true, - "name": "G", + "name": "B", "origin": "user", "prefix": null, - "ref": message G { x: Int; y: Int = 42 }, + "ref": message B { + x: map; +}, }, + ], + "id": 7, + "kind": "program", +} +`; + +exports[`grammar should parse types-optional 1`] = ` +{ + "entries": [ { - "fields": [ + "args": [ { - "as": null, - "id": 37, - "init": { - "id": 36, - "kind": "number", - "ref": 42, - "value": 42n, - }, - "kind": "def_field", - "name": "x", - "ref": x: Int = 42, + "id": 3, + "kind": "def_argument", + "name": "src", + "ref": src: Int?, "type": { - "id": 35, + "id": 2, "kind": "type_ref_simple", "name": "Int", - "optional": false, - "ref": Int, + "optional": true, + "ref": Int?, }, }, + ], + "attributes": [], + "id": 15, + "kind": "def_function", + "name": "testFunc", + "origin": "user", + "ref": fun testFunc(src: Int?): Int { + return 1 + 2 + (123 + 3)!! > 123; +}, + "return": { + "id": 1, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + "statements": [ { - "as": null, - "id": 39, - "init": null, - "kind": "def_field", - "name": "y", - "ref": y: Int, - "type": { - "id": 38, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "expression": { + "id": 13, + "kind": "op_binary", + "left": { + "id": 11, + "kind": "op_binary", + "left": { + "id": 6, + "kind": "op_binary", + "left": { + "id": 4, + "kind": "number", + "ref": 1, + "value": 1n, + }, + "op": "+", + "ref": 1 + 2, + "right": { + "id": 5, + "kind": "number", + "ref": 2, + "value": 2n, + }, + }, + "op": "+", + "ref": 1 + 2 + (123 + 3)!!, + "right": { + "id": 10, + "kind": "op_unary", + "op": "!!", + "ref": (123 + 3)!!, + "right": { + "id": 9, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "number", + "ref": 123, + "value": 123n, + }, + "op": "+", + "ref": 123 + 3, + "right": { + "id": 8, + "kind": "number", + "ref": 3, + "value": 3n, + }, + }, + }, + }, + "op": ">", + "ref": 1 + 2 + (123 + 3)!! > 123, + "right": { + "id": 12, + "kind": "number", + "ref": 123, + "value": 123n, + }, }, + "id": 14, + "kind": "statement_return", + "ref": return 1 + 2 + (123 + 3)!! > 123;, }, ], - "id": 40, - "kind": "def_struct", - "message": true, - "name": "G", - "origin": "user", - "prefix": null, - "ref": message G { x: Int = 42; y: Int }, }, ], - "id": 41, + "id": 16, "kind": "program", } `; diff --git a/src/grammar/test-failed/case-30.tact b/src/grammar/test-failed/contract-empty-traits-list-with-keyword.tact similarity index 100% rename from src/grammar/test-failed/case-30.tact rename to src/grammar/test-failed/contract-empty-traits-list-with-keyword.tact diff --git a/src/grammar/test-failed/case-29.tact b/src/grammar/test-failed/contract-init-trailing-comma-empty-params.tact similarity index 100% rename from src/grammar/test-failed/case-29.tact rename to src/grammar/test-failed/contract-init-trailing-comma-empty-params.tact diff --git a/src/grammar/test-failed/case-27.tact b/src/grammar/test-failed/contract-trailing-comma-empty-traits-list.tact similarity index 100% rename from src/grammar/test-failed/case-27.tact rename to src/grammar/test-failed/contract-trailing-comma-empty-traits-list.tact diff --git a/src/grammar/test-failed/case-22.tact b/src/grammar/test-failed/expr-fun-call-trailing-comma-no-args.tact similarity index 100% rename from src/grammar/test-failed/case-22.tact rename to src/grammar/test-failed/expr-fun-call-trailing-comma-no-args.tact diff --git a/src/grammar/test-failed/case-20.tact b/src/grammar/test-failed/expr-method-call-trailing-comma-no-args.tact similarity index 100% rename from src/grammar/test-failed/case-20.tact rename to src/grammar/test-failed/expr-method-call-trailing-comma-no-args.tact diff --git a/src/grammar/test-failed/case-4.tact b/src/grammar/test-failed/ident-cannot-be-if-reserved-word.tact similarity index 100% rename from src/grammar/test-failed/case-4.tact rename to src/grammar/test-failed/ident-cannot-be-if-reserved-word.tact diff --git a/src/grammar/test-failed/case-7.tact b/src/grammar/test-failed/ident-contract-cannot-start-with-__gen.tact similarity index 100% rename from src/grammar/test-failed/case-7.tact rename to src/grammar/test-failed/ident-contract-cannot-start-with-__gen.tact diff --git a/src/grammar/test-failed/case-1.tact b/src/grammar/test-failed/ident-fun-cannot-start-with-__gen.tact similarity index 100% rename from src/grammar/test-failed/case-1.tact rename to src/grammar/test-failed/ident-fun-cannot-start-with-__gen.tact diff --git a/src/grammar/test-failed/case-6.tact b/src/grammar/test-failed/ident-fun-param-cannot-start-with-__gen.tact similarity index 100% rename from src/grammar/test-failed/case-6.tact rename to src/grammar/test-failed/ident-fun-param-cannot-start-with-__gen.tact diff --git a/src/grammar/test-failed/case-9.tact b/src/grammar/test-failed/ident-fun-param-cannot-start-with-__tact.tact similarity index 100% rename from src/grammar/test-failed/case-9.tact rename to src/grammar/test-failed/ident-fun-param-cannot-start-with-__tact.tact diff --git a/src/grammar/test-failed/case-8.tact b/src/grammar/test-failed/ident-init-param-cannot-start-with-__tact.tact similarity index 100% rename from src/grammar/test-failed/case-8.tact rename to src/grammar/test-failed/ident-init-param-cannot-start-with-__tact.tact diff --git a/src/grammar/test-failed/case-2.tact b/src/grammar/test-failed/ident-let-cannot-start-with-__gen.tact similarity index 100% rename from src/grammar/test-failed/case-2.tact rename to src/grammar/test-failed/ident-let-cannot-start-with-__gen.tact diff --git a/src/grammar/test-failed/case-3.tact b/src/grammar/test-failed/ident-let-cannot-start-with-__tact.tact similarity index 100% rename from src/grammar/test-failed/case-3.tact rename to src/grammar/test-failed/ident-let-cannot-start-with-__tact.tact diff --git a/src/grammar/test-failed/case-5.tact b/src/grammar/test-failed/ident-struct-cannot-start-with-__gen.tact similarity index 100% rename from src/grammar/test-failed/case-5.tact rename to src/grammar/test-failed/ident-struct-cannot-start-with-__gen.tact diff --git a/src/grammar/test-failed/case-21.tact b/src/grammar/test-failed/item-fun-non-void-trailing-comma-no-params.tact similarity index 100% rename from src/grammar/test-failed/case-21.tact rename to src/grammar/test-failed/item-fun-non-void-trailing-comma-no-params.tact diff --git a/src/grammar/test-failed/case-19.tact b/src/grammar/test-failed/item-fun-void-trailing-comma-no-params.tact similarity index 100% rename from src/grammar/test-failed/case-19.tact rename to src/grammar/test-failed/item-fun-void-trailing-comma-no-params.tact diff --git a/src/grammar/test-failed/case-0.tact b/src/grammar/test-failed/item-fun-without-body.tact similarity index 100% rename from src/grammar/test-failed/case-0.tact rename to src/grammar/test-failed/item-fun-without-body.tact diff --git a/src/grammar/test-failed/case-26.tact b/src/grammar/test-failed/item-native-fun-not-void-decl-trailing-comma-no-params.tact.tact similarity index 100% rename from src/grammar/test-failed/case-26.tact rename to src/grammar/test-failed/item-native-fun-not-void-decl-trailing-comma-no-params.tact.tact diff --git a/src/grammar/test-failed/case-23.tact b/src/grammar/test-failed/item-native-fun-void-decl-trailing-comma-no-params.tact similarity index 100% rename from src/grammar/test-failed/case-23.tact rename to src/grammar/test-failed/item-native-fun-void-decl-trailing-comma-no-params.tact diff --git a/src/grammar/test-failed/case-14.tact b/src/grammar/test-failed/literal-dec-trailing-underscore.tact similarity index 100% rename from src/grammar/test-failed/case-14.tact rename to src/grammar/test-failed/literal-dec-trailing-underscore.tact diff --git a/src/grammar/test-failed/case-17.tact b/src/grammar/test-failed/literal-double-underscore.tact similarity index 100% rename from src/grammar/test-failed/case-17.tact rename to src/grammar/test-failed/literal-double-underscore.tact diff --git a/src/grammar/test-failed/case-15.tact b/src/grammar/test-failed/literal-hex-trailing-underscore.tact similarity index 100% rename from src/grammar/test-failed/case-15.tact rename to src/grammar/test-failed/literal-hex-trailing-underscore.tact diff --git a/src/grammar/test-failed/case-12.tact b/src/grammar/test-failed/literal-no-underscore-after-0b.tact similarity index 100% rename from src/grammar/test-failed/case-12.tact rename to src/grammar/test-failed/literal-no-underscore-after-0b.tact diff --git a/src/grammar/test-failed/case-18.tact b/src/grammar/test-failed/literal-no-underscores-if-leading-zero.tact similarity index 100% rename from src/grammar/test-failed/case-18.tact rename to src/grammar/test-failed/literal-no-underscores-if-leading-zero.tact diff --git a/src/grammar/test-failed/case-13.tact b/src/grammar/test-failed/literal-non-binary-digits.tact similarity index 100% rename from src/grammar/test-failed/case-13.tact rename to src/grammar/test-failed/literal-non-binary-digits.tact diff --git a/src/grammar/test-failed/case-16.tact b/src/grammar/test-failed/literal-underscore-after-leading-zero.tact similarity index 100% rename from src/grammar/test-failed/case-16.tact rename to src/grammar/test-failed/literal-underscore-after-leading-zero.tact diff --git a/src/grammar/test-failed/case-32.tact b/src/grammar/test-failed/struct-double-semicolon.tact similarity index 100% rename from src/grammar/test-failed/case-32.tact rename to src/grammar/test-failed/struct-double-semicolon.tact diff --git a/src/grammar/test-failed/case-34.tact b/src/grammar/test-failed/struct-missing-semicolon-between-fields-with-initializer.tact similarity index 100% rename from src/grammar/test-failed/case-34.tact rename to src/grammar/test-failed/struct-missing-semicolon-between-fields-with-initializer.tact diff --git a/src/grammar/test-failed/case-33.tact b/src/grammar/test-failed/struct-missing-semicolon-between-fields.tact similarity index 100% rename from src/grammar/test-failed/case-33.tact rename to src/grammar/test-failed/struct-missing-semicolon-between-fields.tact diff --git a/src/grammar/test-failed/case-31.tact b/src/grammar/test-failed/trait-empty-traits-list-with-keyword.tact similarity index 100% rename from src/grammar/test-failed/case-31.tact rename to src/grammar/test-failed/trait-empty-traits-list-with-keyword.tact diff --git a/src/grammar/test-failed/case-25.tact b/src/grammar/test-failed/trait-fun-non-void-trailing-comma-no-params.tact.tact similarity index 100% rename from src/grammar/test-failed/case-25.tact rename to src/grammar/test-failed/trait-fun-non-void-trailing-comma-no-params.tact.tact diff --git a/src/grammar/test-failed/case-24.tact b/src/grammar/test-failed/trait-fun-void-trailing-comma-no-params.tact similarity index 100% rename from src/grammar/test-failed/case-24.tact rename to src/grammar/test-failed/trait-fun-void-trailing-comma-no-params.tact diff --git a/src/grammar/test-failed/case-28.tact b/src/grammar/test-failed/trait-trailing-comma-empty-traits-list.tact similarity index 100% rename from src/grammar/test-failed/case-28.tact rename to src/grammar/test-failed/trait-trailing-comma-empty-traits-list.tact diff --git a/src/grammar/test-failed/case-11.tact b/src/grammar/test-failed/type-ident-msg-should-be-capitalized.tact similarity index 100% rename from src/grammar/test-failed/case-11.tact rename to src/grammar/test-failed/type-ident-msg-should-be-capitalized.tact diff --git a/src/grammar/test-failed/case-10.tact b/src/grammar/test-failed/type-ident-struct-should-be-capitalized.tact similarity index 100% rename from src/grammar/test-failed/case-10.tact rename to src/grammar/test-failed/type-ident-struct-should-be-capitalized.tact diff --git a/src/grammar/test/case-21.tact b/src/grammar/test/case-21.tact deleted file mode 100644 index 034f12f4d..000000000 --- a/src/grammar/test/case-21.tact +++ /dev/null @@ -1,3 +0,0 @@ -fun main(): Int { - return 1; -} \ No newline at end of file diff --git a/src/grammar/test/case-26.tact b/src/grammar/test/contract-with-const-override.tact similarity index 100% rename from src/grammar/test/case-26.tact rename to src/grammar/test/contract-with-const-override.tact diff --git a/src/grammar/test/case-14.tact b/src/grammar/test/contract-with-init.tact similarity index 100% rename from src/grammar/test/case-14.tact rename to src/grammar/test/contract-with-init.tact diff --git a/src/grammar/test/case-24.tact b/src/grammar/test/contract-with-trait-string-literal.tact similarity index 100% rename from src/grammar/test/case-24.tact rename to src/grammar/test/contract-with-trait-string-literal.tact diff --git a/src/grammar/test/case-23.tact b/src/grammar/test/contract-with-trait.tact similarity index 100% rename from src/grammar/test/case-23.tact rename to src/grammar/test/contract-with-trait.tact diff --git a/src/grammar/test/case-2.tact b/src/grammar/test/expr-arith-and-cmp.tact similarity index 100% rename from src/grammar/test/case-2.tact rename to src/grammar/test/expr-arith-and-cmp.tact diff --git a/src/grammar/test/case-5.tact b/src/grammar/test/expr-arith-bool-cmp-method-call.tact similarity index 100% rename from src/grammar/test/case-5.tact rename to src/grammar/test/expr-arith-bool-cmp-method-call.tact diff --git a/src/grammar/test/case-4.tact b/src/grammar/test/expr-arith-bool-var.tact similarity index 100% rename from src/grammar/test/case-4.tact rename to src/grammar/test/expr-arith-bool-var.tact diff --git a/src/grammar/test/case-1.tact b/src/grammar/test/expr-arith.tact similarity index 100% rename from src/grammar/test/case-1.tact rename to src/grammar/test/expr-arith.tact diff --git a/src/grammar/test/case-33.tact b/src/grammar/test/expr-chaining-unbox.tact similarity index 100% rename from src/grammar/test/case-33.tact rename to src/grammar/test/expr-chaining-unbox.tact diff --git a/src/grammar/test/case-31.tact b/src/grammar/test/expr-condition-with-or.tact similarity index 100% rename from src/grammar/test/case-31.tact rename to src/grammar/test/expr-condition-with-or.tact diff --git a/src/grammar/test/case-29.tact b/src/grammar/test/expr-conditional-with-let.tact similarity index 100% rename from src/grammar/test/case-29.tact rename to src/grammar/test/expr-conditional-with-let.tact diff --git a/src/grammar/test/case-30.tact b/src/grammar/test/expr-conditional.tact similarity index 100% rename from src/grammar/test/case-30.tact rename to src/grammar/test/expr-conditional.tact diff --git a/src/grammar/test/case-6.tact b/src/grammar/test/expr-fun-call.tact similarity index 100% rename from src/grammar/test/case-6.tact rename to src/grammar/test/expr-fun-call.tact diff --git a/src/grammar/test/case-0.tact b/src/grammar/test/expr-int-literal.tact similarity index 100% rename from src/grammar/test/case-0.tact rename to src/grammar/test/expr-int-literal.tact diff --git a/src/grammar/test/case-32.tact b/src/grammar/test/expr-nested-conditional.tact similarity index 100% rename from src/grammar/test/case-32.tact rename to src/grammar/test/expr-nested-conditional.tact diff --git a/src/grammar/test/case-10.tact b/src/grammar/test/expr-parens.tact similarity index 100% rename from src/grammar/test/case-10.tact rename to src/grammar/test/expr-parens.tact diff --git a/src/grammar/test/case-9.tact b/src/grammar/test/expr-with-unbox.tact similarity index 100% rename from src/grammar/test/case-9.tact rename to src/grammar/test/expr-with-unbox.tact diff --git a/src/grammar/test/case-3.tact b/src/grammar/test/expr-with-var.tact similarity index 100% rename from src/grammar/test/case-3.tact rename to src/grammar/test/expr-with-var.tact diff --git a/src/grammar/test/case-25.tact b/src/grammar/test/items-method-def-initof-trailing-comma-shifts.tact similarity index 100% rename from src/grammar/test/case-25.tact rename to src/grammar/test/items-method-def-initof-trailing-comma-shifts.tact diff --git a/src/grammar/test/case-7.tact b/src/grammar/test/items-multi-funs.tact similarity index 100% rename from src/grammar/test/case-7.tact rename to src/grammar/test/items-multi-funs.tact diff --git a/src/grammar/test/case-8.tact b/src/grammar/test/items-native-fun-decls.tact similarity index 100% rename from src/grammar/test/case-8.tact rename to src/grammar/test/items-native-fun-decls.tact diff --git a/src/grammar/test/case-17.tact b/src/grammar/test/items-struct-msg-fun-const.tact similarity index 100% rename from src/grammar/test/case-17.tact rename to src/grammar/test/items-struct-msg-fun-const.tact diff --git a/src/grammar/test/case-28.tact b/src/grammar/test/literals-int-underscores-bin-dec-hex-oct.tact similarity index 100% rename from src/grammar/test/case-28.tact rename to src/grammar/test/literals-int-underscores-bin-dec-hex-oct.tact diff --git a/src/grammar/test/case-27.tact b/src/grammar/test/stmt-augmented-assign-arith.tact similarity index 100% rename from src/grammar/test/case-27.tact rename to src/grammar/test/stmt-augmented-assign-arith.tact diff --git a/src/grammar/test/case-35.tact b/src/grammar/test/stmt-augmented-assign-bitwise.tact similarity index 100% rename from src/grammar/test/case-35.tact rename to src/grammar/test/stmt-augmented-assign-bitwise.tact diff --git a/src/grammar/test/case-13.tact b/src/grammar/test/stmt-if-else.tact similarity index 100% rename from src/grammar/test/case-13.tact rename to src/grammar/test/stmt-if-else.tact diff --git a/src/grammar/test/case-12.tact b/src/grammar/test/stmt-if.tact similarity index 100% rename from src/grammar/test/case-12.tact rename to src/grammar/test/stmt-if.tact diff --git a/src/grammar/test/case-16.tact b/src/grammar/test/stmt-while-loop.tact similarity index 100% rename from src/grammar/test/case-16.tact rename to src/grammar/test/stmt-while-loop.tact diff --git a/src/grammar/test/case-15.tact b/src/grammar/test/stmt-while-repeat-do-loops.tact similarity index 100% rename from src/grammar/test/case-15.tact rename to src/grammar/test/stmt-while-repeat-do-loops.tact diff --git a/src/grammar/test/case-34.tact b/src/grammar/test/struct-field-punning.tact similarity index 100% rename from src/grammar/test/case-34.tact rename to src/grammar/test/struct-field-punning.tact diff --git a/src/grammar/test/case-18.tact b/src/grammar/test/struct-msg-as.tact similarity index 100% rename from src/grammar/test/case-18.tact rename to src/grammar/test/struct-msg-as.tact diff --git a/src/grammar/test/case-19.tact b/src/grammar/test/struct-msg-initializers.tact similarity index 100% rename from src/grammar/test/case-19.tact rename to src/grammar/test/struct-msg-initializers.tact diff --git a/src/grammar/test/case-36.tact b/src/grammar/test/struct-msg-trailing-semicolon.tact similarity index 100% rename from src/grammar/test/case-36.tact rename to src/grammar/test/struct-msg-trailing-semicolon.tact diff --git a/src/grammar/test/case-22.tact b/src/grammar/test/traits-inheritance-trailing-comma.tact similarity index 100% rename from src/grammar/test/case-22.tact rename to src/grammar/test/traits-inheritance-trailing-comma.tact diff --git a/src/grammar/test/case-20.tact b/src/grammar/test/type-struct-with-map.tact similarity index 100% rename from src/grammar/test/case-20.tact rename to src/grammar/test/type-struct-with-map.tact diff --git a/src/grammar/test/case-11.tact b/src/grammar/test/types-optional.tact similarity index 100% rename from src/grammar/test/case-11.tact rename to src/grammar/test/types-optional.tact diff --git a/src/test/bugs.spec.ts b/src/test/bugs.spec.ts deleted file mode 100644 index 7fcfff463..000000000 --- a/src/test/bugs.spec.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { beginCell, toNano } from "@ton/core"; -import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { SampleJetton } from "./bugs/output/bugs_SampleJetton"; -import { JettonDefaultWallet } from "./bugs/output/bugs_JettonDefaultWallet"; -import { Issue211 } from "./bugs/output/bugs_Issue211"; - -describe("bugs", () => { - beforeEach(() => { - __DANGER_resetNodeId(); - }); - it("should deploy sample jetton correctly", async () => { - // Init - const system = await ContractSystem.create(); - const treasure = system.treasure("treasure"); - const contract = system.open( - await SampleJetton.fromInit( - treasure.address, - beginCell().endCell(), - toNano("100"), - ), - ); - const target = system.open( - await JettonDefaultWallet.fromInit( - contract.address, - treasure.address, - ), - ); - const tracker = system.track(target.address); - await contract.send( - treasure, - { value: toNano("10") }, - { - $$type: "Mint", - receiver: treasure.address, - amount: toNano("10"), - }, - ); - await system.run(); - - expect(contract.abi.errors!["31733"].message).toStrictEqual( - "condition can`t be...", - ); - - expect(tracker.collect()).toMatchSnapshot(); - }); - it("should deploy issue211 correctly", async () => { - // Init - const system = await ContractSystem.create(); - const treasure = system.treasure("treasure"); - const contract = system.open(await Issue211.fromInit()); - const tracker = system.track(contract.address); - await contract.send(treasure, { value: toNano("10") }, null); - await system.run(); - - expect(tracker.collect()).toMatchSnapshot(); - - expect(await contract.getTest1()).toBe(0n); - expect(await contract.getTest2()).toBe(0n); - expect(await contract.getTest3()).toBe(6n); - expect(await contract.getTest4()).toBe(24n); - expect(await contract.getTest5()).toBe(97n); - expect(await contract.getTest7()).toBe(42n); - expect(await contract.getTest8()).toBe(5n); - expect(await contract.getTest9()).toBe(5n); - }); -}); diff --git a/src/test/bugs/bugs.tact b/src/test/bugs/bugs.tact deleted file mode 100644 index 51a0110e2..000000000 --- a/src/test/bugs/bugs.tact +++ /dev/null @@ -1,7 +0,0 @@ -import "./issue42.tact"; -import "./issue43.tact"; -import "./issue53.tact"; -import "./issue74.tact"; -import "./issue117.tact"; -import "./issue211.tact"; -import "./large-contract.tact"; \ No newline at end of file diff --git a/src/test/bugs/issue53.tact b/src/test/bugs/issue53.tact deleted file mode 100644 index fdc3a13f4..000000000 --- a/src/test/bugs/issue53.tact +++ /dev/null @@ -1,6 +0,0 @@ -contract Issue53 { - init() {} - receive() { - require(1 == 2, "condition can`t be..."); - } -} \ No newline at end of file diff --git a/src/test/codegen/all-contracts.tact b/src/test/codegen/all-contracts.tact new file mode 100644 index 000000000..1dc1102a9 --- /dev/null +++ b/src/test/codegen/all-contracts.tact @@ -0,0 +1,3 @@ +import "./empty-message.tact"; +import "./large-contract.tact"; +import "./struct-field-storage-annotation.tact"; \ No newline at end of file diff --git a/src/test/bugs/issue74.tact b/src/test/codegen/empty-message.tact similarity index 100% rename from src/test/bugs/issue74.tact rename to src/test/codegen/empty-message.tact diff --git a/src/test/bugs/large-contract.tact b/src/test/codegen/large-contract.tact similarity index 100% rename from src/test/bugs/large-contract.tact rename to src/test/codegen/large-contract.tact diff --git a/src/test/bugs/issue42.tact b/src/test/codegen/struct-field-storage-annotation.tact similarity index 96% rename from src/test/bugs/issue42.tact rename to src/test/codegen/struct-field-storage-annotation.tact index 4b201969e..1efd37abf 100644 --- a/src/test/bugs/issue42.tact +++ b/src/test/codegen/struct-field-storage-annotation.tact @@ -2,7 +2,7 @@ import "@stdlib/deploy"; struct TokenInfo { ticker: String; - decimals: Int; // as uint8; // <------ ISSUE HERE, IF WE REMOVE "as uint8", THE CODE COMPILES WITHOUT PROBLEM + decimals: Int as uint8; // <------ ISSUE HERE, IF WE REMOVE "as uint8", THE CODE COMPILES WITHOUT PROBLEM } // messages can contain maps diff --git a/src/test/compilation-fail/fail-const-eval.spec.ts b/src/test/compilation-fail/fail-const-eval.spec.ts deleted file mode 100644 index f8fb640c0..000000000 --- a/src/test/compilation-fail/fail-const-eval.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { __DANGER_resetNodeId } from "../../grammar/ast"; -import { run } from "../../node"; -import { consoleLogger } from "../../logger"; - -describe("fail-const-eval", () => { - beforeAll(() => { - jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); - }); - - beforeEach(() => { - __DANGER_resetNodeId(); - }); - - afterAll(() => { - (consoleLogger.error as jest.Mock).mockRestore(); - }); - - afterEach(() => { - (consoleLogger.error as jest.Mock).mockClear(); - }); - - it("should not compile with division by zero", async () => { - const result = await run({ - configPath: __dirname + "/tact.config.json", - projectNames: ["const-eval"], - }); - expect(result).toBe(false); - expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain( - "Cannot divide by zero", - ); - }); - - it("should not compile with invalid address", async () => { - const result = await run({ - configPath: __dirname + "/tact.config.json", - projectNames: ["invalid-address"], - }); - expect(result).toBe(false); - expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain( - "FQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N is not a valid address", - ); - }); -}); diff --git a/src/test/compilation-fail/fail-implicit-init.spec.ts b/src/test/compilation-fail/fail-implicit-init.spec.ts deleted file mode 100644 index 89b65b0bc..000000000 --- a/src/test/compilation-fail/fail-implicit-init.spec.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { __DANGER_resetNodeId } from "../../grammar/ast"; -import { run } from "../../node"; -import { consoleLogger } from "../../logger"; - -describe("fail-implicit-init", () => { - beforeAll(() => { - jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); - }); - - beforeEach(() => { - __DANGER_resetNodeId(); - }); - - afterAll(() => { - (consoleLogger.error as jest.Mock).mockRestore(); - }); - - afterEach(() => { - (consoleLogger.error as jest.Mock).mockClear(); - }); - - it("should not compile with uninitialized storage fields", async () => { - const result = await run({ - configPath: __dirname + "/tact.config.json", - projectNames: ["implicit-init"], - }); - expect(result).toBe(false); - expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain( - 'Field "test_field" is not set', - ); - }); -}); diff --git a/src/test/compilation-fail/tact.config.json b/src/test/compilation-fail/tact.config.json deleted file mode 100644 index afd554853..000000000 --- a/src/test/compilation-fail/tact.config.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json", - "projects": [ - { - "name": "implicit-init", - "path": "./contracts/implicit-init.tact", - "output": "./contracts/output" - }, - { - "name": "invalid-address", - "path": "./contracts/invalid-address.tact", - "output": "./contracts/output" - }, - { - "name": "const-eval", - "path": "./contracts/const-eval.tact", - "output": "./contracts/output" - }, - { - "name": "issue349", - "path": "./contracts/issue349.tact", - "output": "./contracts/output" - } - ] -} diff --git a/src/test/compilation-fail/bugs.spec.ts b/src/test/compilation-failed/const-eval-failed.spec.ts similarity index 50% rename from src/test/compilation-fail/bugs.spec.ts rename to src/test/compilation-failed/const-eval-failed.spec.ts index 727e9fac0..790c92894 100644 --- a/src/test/compilation-fail/bugs.spec.ts +++ b/src/test/compilation-failed/const-eval-failed.spec.ts @@ -1,8 +1,8 @@ import { __DANGER_resetNodeId } from "../../grammar/ast"; -import { run } from "../../node"; import { consoleLogger } from "../../logger"; +import { itShouldNotCompile } from "./util"; -describe("fail-bugs", () => { +describe("fail-const-eval", () => { beforeAll(() => { jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); }); @@ -19,14 +19,13 @@ describe("fail-bugs", () => { (consoleLogger.error as jest.Mock).mockClear(); }); - it("should not compile issue 349", async () => { - const result = await run({ - configPath: __dirname + "/tact.config.json", - projectNames: ["issue349"], - }); - expect(result).toBe(false); - expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain( - 'Type mismatch: "" is not assignable to "Slice"', - ); + itShouldNotCompile({ + testName: "const-eval-div-by-zero", + errorMessage: "Cannot divide by zero", + }); + itShouldNotCompile({ + testName: "const-eval-invalid-address", + errorMessage: + "FQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N is not a valid address", }); }); diff --git a/src/test/compilation-fail/contracts/const-eval.tact b/src/test/compilation-failed/contracts/const-eval-div-by-zero.tact similarity index 82% rename from src/test/compilation-fail/contracts/const-eval.tact rename to src/test/compilation-failed/contracts/const-eval-div-by-zero.tact index 8bf2233c6..a69753364 100644 --- a/src/test/compilation-fail/contracts/const-eval.tact +++ b/src/test/compilation-failed/contracts/const-eval-div-by-zero.tact @@ -1,4 +1,4 @@ -contract ConstantTester { +contract ConstEvalDivByZero { init() { } diff --git a/src/test/compilation-fail/contracts/invalid-address.tact b/src/test/compilation-failed/contracts/const-eval-invalid-address.tact similarity index 79% rename from src/test/compilation-fail/contracts/invalid-address.tact rename to src/test/compilation-failed/contracts/const-eval-invalid-address.tact index b3f860897..42aa8a76e 100644 --- a/src/test/compilation-fail/contracts/invalid-address.tact +++ b/src/test/compilation-failed/contracts/const-eval-invalid-address.tact @@ -1,6 +1,6 @@ import "@stdlib/deploy"; -contract SampleTactContract with Deployable { +contract ConstEvalInvalidAddress with Deployable { init() { } get fun test_address(): Address { diff --git a/src/test/compilation-fail/contracts/issue349.tact b/src/test/compilation-failed/contracts/stdlib-skipBits.tact similarity index 88% rename from src/test/compilation-fail/contracts/issue349.tact rename to src/test/compilation-failed/contracts/stdlib-skipBits.tact index 38bda49f2..b5ebb91e8 100644 --- a/src/test/compilation-fail/contracts/issue349.tact +++ b/src/test/compilation-failed/contracts/stdlib-skipBits.tact @@ -1,4 +1,4 @@ -contract MyContract { +contract StdlibSkipBits { receive() { let s: Slice = beginCell().storeUint(123, 64).endCell().asSlice(); let r: Int = s.loadUint(1); diff --git a/src/test/compilation-failed/stdlib-bugs.spec.ts b/src/test/compilation-failed/stdlib-bugs.spec.ts new file mode 100644 index 000000000..83a476344 --- /dev/null +++ b/src/test/compilation-failed/stdlib-bugs.spec.ts @@ -0,0 +1,26 @@ +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { consoleLogger } from "../../logger"; +import { itShouldNotCompile } from "./util"; + +describe("stdlib-bugs", () => { + beforeAll(() => { + jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); + }); + + beforeEach(() => { + __DANGER_resetNodeId(); + }); + + afterAll(() => { + (consoleLogger.error as jest.Mock).mockRestore(); + }); + + afterEach(() => { + (consoleLogger.error as jest.Mock).mockClear(); + }); + + itShouldNotCompile({ + testName: "stdlib-skipBits", + errorMessage: 'Type mismatch: "" is not assignable to "Slice"', + }); +}); diff --git a/src/test/compilation-failed/tact.config.json b/src/test/compilation-failed/tact.config.json new file mode 100644 index 000000000..826aaa385 --- /dev/null +++ b/src/test/compilation-failed/tact.config.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json", + "projects": [ + { + "name": "const-eval-invalid-address", + "path": "./contracts/const-eval-invalid-address.tact", + "output": "./contracts/output" + }, + { + "name": "const-eval-div-by-zero", + "path": "./contracts/const-eval-div-by-zero.tact", + "output": "./contracts/output" + }, + { + "name": "stdlib-skipBits", + "path": "./contracts/stdlib-skipBits.tact", + "output": "./contracts/output" + } + ] +} diff --git a/src/test/compilation-failed/util.ts b/src/test/compilation-failed/util.ts new file mode 100644 index 000000000..9c91d5067 --- /dev/null +++ b/src/test/compilation-failed/util.ts @@ -0,0 +1,19 @@ +import { run } from "../../node"; +import { consoleLogger } from "../../logger"; + +// helper to reduce boilerplate +export function itShouldNotCompile(params: { + testName: string; + errorMessage: string; +}) { + it(`should not compile ${params.testName}`, async () => { + const result = await run({ + configPath: __dirname + "/tact.config.json", + projectNames: [`${params.testName}`], + }); + expect(result).toBe(false); + expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain( + params.errorMessage, + ); + }); +} diff --git a/src/test/contracts/case-1.tact b/src/test/contracts/case-1.tact deleted file mode 100644 index a6bd67d75..000000000 --- a/src/test/contracts/case-1.tact +++ /dev/null @@ -1,24 +0,0 @@ -struct Source { - a: Int; - b: Int; - c: Int; - d: Int; -} - -fun isZero(x: Int, y: Int, z: Bool, m: Source): Bool { - let b: Int = x + y; - b = b + 1 + m.a + m.b; - let c: Int = (y >> 123); - let d: Int = (x << 10); - return b > 0 && z && c == 0 && d == 0; -} - -contract Empty { - - init() { - } - - get fun a(x: Int, y: Int, z: Bool, m: Source): Bool { - return isZero(x, y, z, m); - } -} \ No newline at end of file diff --git a/src/test/contracts/case-2.tact b/src/test/contracts/case-2.tact deleted file mode 100644 index 8ced9aed2..000000000 --- a/src/test/contracts/case-2.tact +++ /dev/null @@ -1,15 +0,0 @@ -struct Source { - a: Int; - b: Int; -} - -fun isZero(x: Int, y: Int, z: Bool, m: Source): Bool { - m.b = 10; - return (x + m.b) > 0 && z; -} - -contract Empty { - init() { - - } -} \ No newline at end of file diff --git a/src/test/contracts/case-3.tact b/src/test/contracts/case-3.tact deleted file mode 100644 index 1faa7c71e..000000000 --- a/src/test/contracts/case-3.tact +++ /dev/null @@ -1,31 +0,0 @@ -struct Source { - a: Int; - b: Int; -} - -fun isZero(x: Int, y: Int, z: Bool, m: Source): Bool { - m.b = 10; - return (x + m.b) > 0 && z; -} - -contract SampleContract { - a: Int; - b: Int; - c: Source; - - init() { - self.a = 0; - self.b = 0; - self.c = Source{a: 0, b: 0}; - } - - fun addStake() { - self.a = 10; - self.b = -20; - self.c = Source{a: 10, b: 20}; - } - - get fun stake(): Int { - return self.a; - } -} \ No newline at end of file diff --git a/src/test/contracts/case-4.tact b/src/test/contracts/case-4.tact deleted file mode 100644 index ed6d8e798..000000000 --- a/src/test/contracts/case-4.tact +++ /dev/null @@ -1,32 +0,0 @@ -struct Source { - a: Int; - b: Int; -} - -fun isZero(x: Int, y: Int, z: Bool, m: Source): Bool { - m.b = 10; - return (x + m.b) > 0 && z; -} - -contract SampleContract { - a: Int; - b: Int; - c: Source; - d: map; - - init() { - self.a = 0; - self.b = 0; - self.c = Source{a: 0, b: 0}; - } - - fun addStake() { - self.a = 10; - self.b = -20; - self.c = Source{a: 10, b: 20}; - } - - get fun stake(): Int { - return self.a; - } -} \ No newline at end of file diff --git a/src/test/__snapshots__/feature-constants.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/constants.spec.ts.snap similarity index 99% rename from src/test/__snapshots__/feature-constants.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/constants.spec.ts.snap index 4eb3077ca..d88e8b253 100644 --- a/src/test/__snapshots__/feature-constants.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/constants.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-constants should implement constants correctly 1`] = ` +exports[`constants should implement constants correctly 1`] = ` ConstantTester { "abi": { "errors": { diff --git a/src/test/__snapshots__/feature-deep.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/deep.spec.ts.snap similarity index 85% rename from src/test/__snapshots__/feature-deep.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/deep.spec.ts.snap index 7c52d9c74..fb813903b 100644 --- a/src/test/__snapshots__/feature-deep.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/deep.spec.ts.snap @@ -1,12 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-random should chain deep sequences correctly 1`] = `"kQDrBeBEkP7QP4-M2-FUSzRoUQK_AxvhYOKkIGSEHqmmjUqW"`; +exports[`random should chain deep sequences correctly 1`] = `"kQDrBeBEkP7QP4-M2-FUSzRoUQK_AxvhYOKkIGSEHqmmjUqW"`; -exports[`feature-random should chain deep sequences correctly 2`] = `"kQD4CriC3RmScKPAhCkviu-kHj1peUa71rGD7gERLfT6h7rP"`; +exports[`random should chain deep sequences correctly 2`] = `"kQD4CriC3RmScKPAhCkviu-kHj1peUa71rGD7gERLfT6h7rP"`; -exports[`feature-random should chain deep sequences correctly 3`] = `"kQBGt4TP7qlVmFk8HoqKcbfHRMJXPx9wiCGqz20U3RjpIZGF"`; +exports[`random should chain deep sequences correctly 3`] = `"kQBGt4TP7qlVmFk8HoqKcbfHRMJXPx9wiCGqz20U3RjpIZGF"`; -exports[`feature-random should chain deep sequences correctly 4`] = ` +exports[`random should chain deep sequences correctly 4`] = ` [ { "$seq": 0, @@ -53,7 +53,7 @@ exports[`feature-random should chain deep sequences correctly 4`] = ` ] `; -exports[`feature-random should chain deep sequences correctly 5`] = ` +exports[`random should chain deep sequences correctly 5`] = ` [ { "$seq": 0, @@ -100,7 +100,7 @@ exports[`feature-random should chain deep sequences correctly 5`] = ` ] `; -exports[`feature-random should chain deep sequences correctly 6`] = ` +exports[`random should chain deep sequences correctly 6`] = ` [ { "$seq": 0, diff --git a/src/test/__snapshots__/feature-implicit-init.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/implicit-init.spec.ts.snap similarity index 94% rename from src/test/__snapshots__/feature-implicit-init.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/implicit-init.spec.ts.snap index 0e9701228..bf7c496bb 100644 --- a/src/test/__snapshots__/feature-implicit-init.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/implicit-init.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-implicit-init should deploy 1`] = ` +exports[`implicit-init should deploy 1`] = ` [ { "$seq": 0, @@ -53,7 +53,7 @@ exports[`feature-implicit-init should deploy 1`] = ` ] `; -exports[`feature-implicit-init should increment counter 1`] = ` +exports[`implicit-init should increment counter 1`] = ` [ { "$seq": 1, diff --git a/src/test/__snapshots__/feature-intrinsics.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/intrinsics.spec.ts.snap similarity index 91% rename from src/test/__snapshots__/feature-intrinsics.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/intrinsics.spec.ts.snap index a7e7be938..39469aed6 100644 --- a/src/test/__snapshots__/feature-intrinsics.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/intrinsics.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-intrinsics should return correct intrinsic results 1`] = ` +exports[`intrinsics should return correct intrinsic results 1`] = ` [ { "$seq": 1, diff --git a/src/test/__snapshots__/feature-masterchain.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/masterchain.spec.ts.snap similarity index 87% rename from src/test/__snapshots__/feature-masterchain.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/masterchain.spec.ts.snap index 2138d8665..f6f0b3e90 100644 --- a/src/test/__snapshots__/feature-masterchain.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/masterchain.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-masterchain should deploy to the workchain 1`] = ` +exports[`masterchain should deploy to the workchain 1`] = ` [ { "$seq": 0, @@ -31,7 +31,7 @@ exports[`feature-masterchain should deploy to the workchain 1`] = ` ] `; -exports[`feature-masterchain should deploy to the workchain from masterchain when masterchain enabled 1`] = ` +exports[`masterchain should deploy to the workchain from masterchain when masterchain enabled 1`] = ` [ { "$seq": 0, @@ -62,7 +62,7 @@ exports[`feature-masterchain should deploy to the workchain from masterchain whe ] `; -exports[`feature-masterchain should deploy to the workchain when masterchain enabled 1`] = ` +exports[`masterchain should deploy to the workchain when masterchain enabled 1`] = ` [ { "$seq": 0, @@ -93,7 +93,7 @@ exports[`feature-masterchain should deploy to the workchain when masterchain ena ] `; -exports[`feature-masterchain should not deploy to the workchain from masterchain 1`] = ` +exports[`masterchain should not deploy to the workchain from masterchain 1`] = ` [ { "$seq": 0, diff --git a/src/test/e2e-emulated/__snapshots__/mutating-method-chaining.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/mutating-method-chaining.spec.ts.snap new file mode 100644 index 000000000..a43d11593 --- /dev/null +++ b/src/test/e2e-emulated/__snapshots__/mutating-method-chaining.spec.ts.snap @@ -0,0 +1,31 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`bugs should implement mutating method chaining correctly 1`] = ` +[ + { + "$seq": 0, + "events": [ + { + "$type": "deploy", + }, + { + "$type": "received", + "message": { + "body": { + "type": "empty", + }, + "bounce": true, + "from": "@treasure(treasure)", + "to": "kQCGg-qsZbZ6ObsEGqnPA1Q2Ma7bpCHVkJNXu0LvqWZSmD8C", + "type": "internal", + "value": "10", + }, + }, + { + "$type": "processed", + "gasUsed": 4443n, + }, + ], + }, +] +`; diff --git a/src/test/__snapshots__/bugs.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/sample-jetton.spec.ts.snap similarity index 52% rename from src/test/__snapshots__/bugs.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/sample-jetton.spec.ts.snap index f7ae697c7..e3e35ed60 100644 --- a/src/test/__snapshots__/bugs.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/sample-jetton.spec.ts.snap @@ -1,35 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`bugs should deploy issue211 correctly 1`] = ` -[ - { - "$seq": 0, - "events": [ - { - "$type": "deploy", - }, - { - "$type": "received", - "message": { - "body": { - "type": "empty", - }, - "bounce": true, - "from": "@treasure(treasure)", - "to": "kQBncu_8bax1NEtWT7cS_3eaVzOjwV9h8HKLc0WaLCjYVYOZ", - "type": "internal", - "value": "10", - }, - }, - { - "$type": "processed", - "gasUsed": 4443n, - }, - ], - }, -] -`; - exports[`bugs should deploy sample jetton correctly 1`] = ` [ { @@ -42,12 +12,12 @@ exports[`bugs should deploy sample jetton correctly 1`] = ` "$type": "received", "message": { "body": { - "cell": "x{178D45190000000000000000502540BE40080027C3708748BD50B16DCBEDCEB67B6240822BF1AD316970B4B6A3B5D2B4EDB84B0016E3A425A4E75B646191AC9A34FE5D050BD101A5C490F87D01C66D885D09BC1082_}", + "cell": "x{178D45190000000000000000502540BE400801AA83CBBCA5263F67EAA1559AD9E623E62E67A29FA27E595CC8FE11388F31EDEF0016E3A425A4E75B646191AC9A34FE5D050BD101A5C490F87D01C66D885D09BC1082_}", "type": "cell", }, "bounce": false, - "from": "kQAT4bhDpF6oWLbl9udbPbEgQRX41pi0uFpbUdrpWnbcJU9m", - "to": "kQCwq4sK9qMKTt8uLncSjmOaELt6efxGmovlS4h7CamhbRAn", + "from": "kQDVQeXeUpMfs_VQqs1s8xHzFzPRT9E_LK5kfwicR5j297b1", + "to": "kQB0KL6E6fdGDVrtJBp7LpazUNhD-ZyguSjmHr4riyDbX6NG", "type": "internal", "value": "9.959886", }, @@ -68,7 +38,7 @@ exports[`bugs should deploy sample jetton correctly 1`] = ` }, }, "bounce": false, - "from": "kQCwq4sK9qMKTt8uLncSjmOaELt6efxGmovlS4h7CamhbRAn", + "from": "kQB0KL6E6fdGDVrtJBp7LpazUNhD-ZyguSjmHr4riyDbX6NG", "to": "@treasure(treasure)", "type": "internal", "value": "9.916924834", diff --git a/src/test/__snapshots__/feature-send.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/send.spec.ts.snap similarity index 94% rename from src/test/__snapshots__/feature-send.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/send.spec.ts.snap index 4c659197f..72b94a865 100644 --- a/src/test/__snapshots__/feature-send.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/send.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-send should bounce on unknown message 1`] = ` +exports[`send should bounce on unknown message 1`] = ` [ { "$seq": 1, @@ -47,7 +47,7 @@ exports[`feature-send should bounce on unknown message 1`] = ` ] `; -exports[`feature-send should send reply correctly 1`] = ` +exports[`send should send reply correctly 1`] = ` [ { "$seq": 0, @@ -94,7 +94,7 @@ exports[`feature-send should send reply correctly 1`] = ` ] `; -exports[`feature-send should send reply correctly 2`] = ` +exports[`send should send reply correctly 2`] = ` [ { "$seq": 1, diff --git a/src/test/__snapshots__/feature-try-catch.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/try-catch.spec.ts.snap similarity index 96% rename from src/test/__snapshots__/feature-try-catch.spec.ts.snap rename to src/test/e2e-emulated/__snapshots__/try-catch.spec.ts.snap index b2a918506..b56cd29d7 100644 --- a/src/test/__snapshots__/feature-try-catch.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/try-catch.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`feature-ternary should implement try-catch statements correctly 1`] = ` +exports[`ternary should implement try-catch statements correctly 1`] = ` [ { "$seq": 1, diff --git a/src/test/feature-address.spec.ts b/src/test/e2e-emulated/address.spec.ts similarity index 86% rename from src/test/feature-address.spec.ts rename to src/test/e2e-emulated/address.spec.ts index bbd61f77a..dc19a42f0 100644 --- a/src/test/feature-address.spec.ts +++ b/src/test/e2e-emulated/address.spec.ts @@ -1,10 +1,10 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { AddressTester } from "./features/output/address_AddressTester"; -import { consoleLogger } from "../logger"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { AddressTester } from "./contracts/output/address_AddressTester"; +import { consoleLogger } from "../../logger"; -describe("feature-address", () => { +describe("address", () => { beforeAll(() => { jest.spyOn(consoleLogger, "error").mockImplementation(() => {}); }); diff --git a/src/test/feature-bounced-routing.spec.ts b/src/test/e2e-emulated/bounced-routing.spec.ts similarity index 84% rename from src/test/feature-bounced-routing.spec.ts rename to src/test/e2e-emulated/bounced-routing.spec.ts index 943a2fdc8..69a5eca1e 100644 --- a/src/test/feature-bounced-routing.spec.ts +++ b/src/test/e2e-emulated/bounced-routing.spec.ts @@ -1,10 +1,10 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { SampleContract2 } from "./features/output/bounced-routing_SampleContract2"; -import { SampleContract } from "./features/output/bounced-routing_SampleContract"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { SampleContract2 } from "./contracts/output/bounced-routing_SampleContract2"; +import { SampleContract } from "./contracts/output/bounced-routing_SampleContract"; -describe("feature-strings", () => { +describe("strings", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-constants.spec.ts b/src/test/e2e-emulated/constants.spec.ts similarity index 94% rename from src/test/feature-constants.spec.ts rename to src/test/e2e-emulated/constants.spec.ts index 5b58ab5a7..bddab973e 100644 --- a/src/test/feature-constants.spec.ts +++ b/src/test/e2e-emulated/constants.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { ConstantTester } from "./features/output/constants_ConstantTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { ConstantTester } from "./contracts/output/constants_ConstantTester"; -describe("feature-constants", () => { +describe("constants", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/features/address.tact b/src/test/e2e-emulated/contracts/address.tact similarity index 100% rename from src/test/features/address.tact rename to src/test/e2e-emulated/contracts/address.tact diff --git a/src/test/features/bounced-routing.tact b/src/test/e2e-emulated/contracts/bounced-routing.tact similarity index 100% rename from src/test/features/bounced-routing.tact rename to src/test/e2e-emulated/contracts/bounced-routing.tact diff --git a/src/test/features/constants.tact b/src/test/e2e-emulated/contracts/constants.tact similarity index 100% rename from src/test/features/constants.tact rename to src/test/e2e-emulated/contracts/constants.tact diff --git a/src/test/features/debug.tact b/src/test/e2e-emulated/contracts/debug.tact similarity index 100% rename from src/test/features/debug.tact rename to src/test/e2e-emulated/contracts/debug.tact diff --git a/src/test/features/deep-sequence.tact b/src/test/e2e-emulated/contracts/deep-sequence.tact similarity index 100% rename from src/test/features/deep-sequence.tact rename to src/test/e2e-emulated/contracts/deep-sequence.tact diff --git a/src/test/features/dns.tact b/src/test/e2e-emulated/contracts/dns.tact similarity index 100% rename from src/test/features/dns.tact rename to src/test/e2e-emulated/contracts/dns.tact diff --git a/src/test/features/implicit-init.tact b/src/test/e2e-emulated/contracts/implicit-init.tact similarity index 100% rename from src/test/features/implicit-init.tact rename to src/test/e2e-emulated/contracts/implicit-init.tact diff --git a/src/test/features/integer-literals.tact b/src/test/e2e-emulated/contracts/integer-literals.tact similarity index 100% rename from src/test/features/integer-literals.tact rename to src/test/e2e-emulated/contracts/integer-literals.tact diff --git a/src/test/features/intrinsics.tact b/src/test/e2e-emulated/contracts/intrinsics.tact similarity index 100% rename from src/test/features/intrinsics.tact rename to src/test/e2e-emulated/contracts/intrinsics.tact diff --git a/src/test/features/map-traverse.tact b/src/test/e2e-emulated/contracts/map-traverse.tact similarity index 100% rename from src/test/features/map-traverse.tact rename to src/test/e2e-emulated/contracts/map-traverse.tact diff --git a/src/test/features/maps.tact b/src/test/e2e-emulated/contracts/maps.tact similarity index 100% rename from src/test/features/maps.tact rename to src/test/e2e-emulated/contracts/maps.tact diff --git a/src/test/features/masterchain.tact b/src/test/e2e-emulated/contracts/masterchain.tact similarity index 100% rename from src/test/features/masterchain.tact rename to src/test/e2e-emulated/contracts/masterchain.tact diff --git a/src/test/features/math.tact b/src/test/e2e-emulated/contracts/math.tact similarity index 100% rename from src/test/features/math.tact rename to src/test/e2e-emulated/contracts/math.tact diff --git a/src/test/bugs/issue211.tact b/src/test/e2e-emulated/contracts/mutating-method-chaining.tact similarity index 98% rename from src/test/bugs/issue211.tact rename to src/test/e2e-emulated/contracts/mutating-method-chaining.tact index 6b8012435..d7e8b2627 100644 --- a/src/test/bugs/issue211.tact +++ b/src/test/e2e-emulated/contracts/mutating-method-chaining.tact @@ -7,7 +7,7 @@ struct Foo { s: Slice; } -contract Issue211 { +contract Tester { s: Slice; init() { diff --git a/src/test/features/optionals-2.tact b/src/test/e2e-emulated/contracts/optionals-2.tact similarity index 100% rename from src/test/features/optionals-2.tact rename to src/test/e2e-emulated/contracts/optionals-2.tact diff --git a/src/test/features/optionals.tact b/src/test/e2e-emulated/contracts/optionals.tact similarity index 100% rename from src/test/features/optionals.tact rename to src/test/e2e-emulated/contracts/optionals.tact diff --git a/src/test/features/ordering.tact b/src/test/e2e-emulated/contracts/ordering.tact similarity index 100% rename from src/test/features/ordering.tact rename to src/test/e2e-emulated/contracts/ordering.tact diff --git a/src/test/features/random.tact b/src/test/e2e-emulated/contracts/random.tact similarity index 100% rename from src/test/features/random.tact rename to src/test/e2e-emulated/contracts/random.tact diff --git a/src/test/features/recursion.tact b/src/test/e2e-emulated/contracts/recursion.tact similarity index 100% rename from src/test/features/recursion.tact rename to src/test/e2e-emulated/contracts/recursion.tact diff --git a/src/test/bugs/issue43.tact b/src/test/e2e-emulated/contracts/sample-jetton.tact similarity index 100% rename from src/test/bugs/issue43.tact rename to src/test/e2e-emulated/contracts/sample-jetton.tact diff --git a/src/test/features/send.tact b/src/test/e2e-emulated/contracts/send.tact similarity index 100% rename from src/test/features/send.tact rename to src/test/e2e-emulated/contracts/send.tact diff --git a/src/test/features/serialization-2.tact b/src/test/e2e-emulated/contracts/serialization-2.tact similarity index 100% rename from src/test/features/serialization-2.tact rename to src/test/e2e-emulated/contracts/serialization-2.tact diff --git a/src/test/features/serialization-3.tact b/src/test/e2e-emulated/contracts/serialization-3.tact similarity index 100% rename from src/test/features/serialization-3.tact rename to src/test/e2e-emulated/contracts/serialization-3.tact diff --git a/src/test/features/serialization.tact b/src/test/e2e-emulated/contracts/serialization.tact similarity index 100% rename from src/test/features/serialization.tact rename to src/test/e2e-emulated/contracts/serialization.tact diff --git a/src/test/contracts/stdlib.tact b/src/test/e2e-emulated/contracts/stdlib.tact similarity index 100% rename from src/test/contracts/stdlib.tact rename to src/test/e2e-emulated/contracts/stdlib.tact diff --git a/src/test/features/strings.tact b/src/test/e2e-emulated/contracts/strings.tact similarity index 98% rename from src/test/features/strings.tact rename to src/test/e2e-emulated/contracts/strings.tact index a39377b80..5a03f9236 100644 --- a/src/test/features/strings.tact +++ b/src/test/e2e-emulated/contracts/strings.tact @@ -7,6 +7,10 @@ contract StringsTester { // Deploy } + receive("backtick-test") { + require(1 == 2, "condition can`t be..."); + } + get fun constantString(): String { return "test string"; } diff --git a/src/test/features/ternary.tact b/src/test/e2e-emulated/contracts/ternary.tact similarity index 100% rename from src/test/features/ternary.tact rename to src/test/e2e-emulated/contracts/ternary.tact diff --git a/src/test/features/try-catch.tact b/src/test/e2e-emulated/contracts/try-catch.tact similarity index 100% rename from src/test/features/try-catch.tact rename to src/test/e2e-emulated/contracts/try-catch.tact diff --git a/src/test/feature-debug.spec.ts b/src/test/e2e-emulated/debug.spec.ts similarity index 85% rename from src/test/feature-debug.spec.ts rename to src/test/e2e-emulated/debug.spec.ts index aff048c68..e18e51602 100644 --- a/src/test/feature-debug.spec.ts +++ b/src/test/e2e-emulated/debug.spec.ts @@ -1,10 +1,10 @@ import { Address, toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { Debug } from "./features/output/debug_Debug"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { Debug } from "./contracts/output/debug_Debug"; import path from "path"; -describe("feature-debug", () => { +describe("debug", () => { beforeEach(() => { __DANGER_resetNodeId(); }); @@ -31,7 +31,9 @@ describe("feature-debug", () => { res.indexOf("=== VM LOGS ===") - 2, ); - const filePath = path.normalize("src/test/features/debug.tact"); + const filePath = path.normalize( + "src/test/e2e-emulated/contracts/debug.tact", + ); expect(debugLogs).toStrictEqual(`[DEBUG] File ${filePath}:10:9 stack(2 values) : 10000000000 () diff --git a/src/test/feature-deep.spec.ts b/src/test/e2e-emulated/deep.spec.ts similarity index 87% rename from src/test/feature-deep.spec.ts rename to src/test/e2e-emulated/deep.spec.ts index 5a4d4d6af..99404355d 100644 --- a/src/test/feature-deep.spec.ts +++ b/src/test/e2e-emulated/deep.spec.ts @@ -1,11 +1,11 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { A } from "./features/output/deep_A"; -import { B } from "./features/output/deep_B"; -import { C } from "./features/output/deep_C"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { A } from "./contracts/output/deep_A"; +import { B } from "./contracts/output/deep_B"; +import { C } from "./contracts/output/deep_C"; -describe("feature-random", () => { +describe("random", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-dns.spec.ts b/src/test/e2e-emulated/dns.spec.ts similarity index 98% rename from src/test/feature-dns.spec.ts rename to src/test/e2e-emulated/dns.spec.ts index 90538cffd..171dd8838 100644 --- a/src/test/feature-dns.spec.ts +++ b/src/test/e2e-emulated/dns.spec.ts @@ -1,7 +1,7 @@ import { OpenedContract, beginCell, toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { DNSTester } from "./features/output/dns_DNSTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { DNSTester } from "./contracts/output/dns_DNSTester"; function convertToInternal(src: string) { if (src === ".") { @@ -31,7 +31,7 @@ function convertToInternal(src: string) { // return res; } -describe("feature-dns", () => { +describe("dns", () => { let contract: OpenedContract; beforeEach(async () => { diff --git a/src/test/feature-implicit-init.spec.ts b/src/test/e2e-emulated/implicit-init.spec.ts similarity index 90% rename from src/test/feature-implicit-init.spec.ts rename to src/test/e2e-emulated/implicit-init.spec.ts index 7379c588e..0b4734337 100644 --- a/src/test/feature-implicit-init.spec.ts +++ b/src/test/e2e-emulated/implicit-init.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { MyContract } from "./features/output/implicit-init_MyContract"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { MyContract } from "./contracts/output/implicit-init_MyContract"; -describe("feature-implicit-init", () => { +describe("implicit-init", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-integer-literals.spec.ts b/src/test/e2e-emulated/integer-literals.spec.ts similarity index 87% rename from src/test/feature-integer-literals.spec.ts rename to src/test/e2e-emulated/integer-literals.spec.ts index e9285479d..7ce257716 100644 --- a/src/test/feature-integer-literals.spec.ts +++ b/src/test/e2e-emulated/integer-literals.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { IntegerLiteralsTester } from "./features/output/integer-literals_IntegerLiteralsTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { IntegerLiteralsTester } from "./contracts/output/integer-literals_IntegerLiteralsTester"; -describe("feature-integer-literals", () => { +describe("integer-literals", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-intrinsics.spec.ts b/src/test/e2e-emulated/intrinsics.spec.ts similarity index 94% rename from src/test/feature-intrinsics.spec.ts rename to src/test/e2e-emulated/intrinsics.spec.ts index 2ad7f8429..1e2080091 100644 --- a/src/test/feature-intrinsics.spec.ts +++ b/src/test/e2e-emulated/intrinsics.spec.ts @@ -1,10 +1,10 @@ import { Address, beginCell, Cell, toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { IntrinsicsTester } from "./features/output/intrinsics_IntrinsicsTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { IntrinsicsTester } from "./contracts/output/intrinsics_IntrinsicsTester"; import { sha256_sync } from "@ton/crypto"; -describe("feature-intrinsics", () => { +describe("intrinsics", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-map-traverse.spec.ts b/src/test/e2e-emulated/map-traverse.spec.ts similarity index 90% rename from src/test/feature-map-traverse.spec.ts rename to src/test/e2e-emulated/map-traverse.spec.ts index 96b646370..13ded4c5a 100644 --- a/src/test/feature-map-traverse.spec.ts +++ b/src/test/e2e-emulated/map-traverse.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { MapTraverseTestContract } from "./features/output/map-traverse_MapTraverseTestContract"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { MapTraverseTestContract } from "./contracts/output/map-traverse_MapTraverseTestContract"; -describe("feature-map-traversal", () => { +describe("map-traversal", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-map.spec.ts b/src/test/e2e-emulated/map.spec.ts similarity index 99% rename from src/test/feature-map.spec.ts rename to src/test/e2e-emulated/map.spec.ts index bcff9952f..88dc8c0e7 100644 --- a/src/test/feature-map.spec.ts +++ b/src/test/e2e-emulated/map.spec.ts @@ -1,9 +1,9 @@ -import { randomAddress } from "./utils/randomAddress"; -import { __DANGER_resetNodeId } from "../grammar/ast"; +import { randomAddress } from "../utils/randomAddress"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; import { MapTestContract, SomeStruct, -} from "./features/output/maps_MapTestContract"; +} from "./contracts/output/maps_MapTestContract"; import { ContractSystem } from "@tact-lang/emulator"; import { beginCell, toNano } from "@ton/core"; import { ComputeError } from "@ton/core"; @@ -15,7 +15,7 @@ function strEq(a: SomeStruct | null, b: SomeStruct | null) { return a.value === b.value; } -describe("feature-map", () => { +describe("map", () => { /* eslint-disable */ let globalCoverage: any; beforeAll(() => { diff --git a/src/test/feature-masterchain.spec.ts b/src/test/e2e-emulated/masterchain.spec.ts similarity index 97% rename from src/test/feature-masterchain.spec.ts rename to src/test/e2e-emulated/masterchain.spec.ts index 29d80be48..b920bf0ce 100644 --- a/src/test/feature-masterchain.spec.ts +++ b/src/test/e2e-emulated/masterchain.spec.ts @@ -1,10 +1,10 @@ import { Address, beginCell, toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { MasterchainTester } from "./features/output/masterchain_MasterchainTester"; -import { MasterchainTester as EnabledTester } from "./features/output/masterchain-allow_MasterchainTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { MasterchainTester } from "./contracts/output/masterchain_MasterchainTester"; +import { MasterchainTester as EnabledTester } from "./contracts/output/masterchain-allow_MasterchainTester"; -describe("feature-masterchain", () => { +describe("masterchain", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-math.spec.ts b/src/test/e2e-emulated/math.spec.ts similarity index 99% rename from src/test/feature-math.spec.ts rename to src/test/e2e-emulated/math.spec.ts index a17883265..68a09686c 100644 --- a/src/test/feature-math.spec.ts +++ b/src/test/e2e-emulated/math.spec.ts @@ -1,9 +1,9 @@ import { beginCell, Dictionary, toNano } from "@ton/core"; import { ContractSystem, randomAddress } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { MathTester } from "./features/output/math_MathTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { MathTester } from "./contracts/output/math_MathTester"; -describe("feature-math", () => { +describe("math", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/e2e-emulated/mutating-method-chaining.spec.ts b/src/test/e2e-emulated/mutating-method-chaining.spec.ts new file mode 100644 index 000000000..ce533e613 --- /dev/null +++ b/src/test/e2e-emulated/mutating-method-chaining.spec.ts @@ -0,0 +1,30 @@ +import { toNano } from "@ton/core"; +import { ContractSystem } from "@tact-lang/emulator"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { Tester } from "./contracts/output/mutating-method-chaining_Tester"; + +describe("bugs", () => { + beforeEach(() => { + __DANGER_resetNodeId(); + }); + it("should implement mutating method chaining correctly", async () => { + // Init + const system = await ContractSystem.create(); + const treasure = system.treasure("treasure"); + const contract = system.open(await Tester.fromInit()); + const tracker = system.track(contract.address); + await contract.send(treasure, { value: toNano("10") }, null); + await system.run(); + + expect(tracker.collect()).toMatchSnapshot(); + + expect(await contract.getTest1()).toBe(0n); + expect(await contract.getTest2()).toBe(0n); + expect(await contract.getTest3()).toBe(6n); + expect(await contract.getTest4()).toBe(24n); + expect(await contract.getTest5()).toBe(97n); + expect(await contract.getTest7()).toBe(42n); + expect(await contract.getTest8()).toBe(5n); + expect(await contract.getTest9()).toBe(5n); + }); +}); diff --git a/src/test/feature-optionals.spec.ts b/src/test/e2e-emulated/optionals.spec.ts similarity index 96% rename from src/test/feature-optionals.spec.ts rename to src/test/e2e-emulated/optionals.spec.ts index a4e903e9a..9ddd6832a 100644 --- a/src/test/feature-optionals.spec.ts +++ b/src/test/e2e-emulated/optionals.spec.ts @@ -1,11 +1,11 @@ -import { randomAddress } from "./utils/randomAddress"; -import { __DANGER_resetNodeId } from "../grammar/ast"; +import { randomAddress } from "../utils/randomAddress"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; import { ContractWithOptionals, SomeGenericStruct, StructWithOptionals, -} from "./features/output/optionals_ContractWithOptionals"; -import { Opt4 } from "./features/output/optionals_Opt4"; +} from "./contracts/output/optionals_ContractWithOptionals"; +import { Opt4 } from "./contracts/output/optionals_Opt4"; import { Address, beginCell, Cell, toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; diff --git a/src/test/feature-ordering.spec.ts b/src/test/e2e-emulated/ordering.spec.ts similarity index 87% rename from src/test/feature-ordering.spec.ts rename to src/test/e2e-emulated/ordering.spec.ts index aec5d5229..24b871d6e 100644 --- a/src/test/feature-ordering.spec.ts +++ b/src/test/e2e-emulated/ordering.spec.ts @@ -1,10 +1,10 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { A } from "./features/output/ordering_A"; -import { B } from "./features/output/ordering_B"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { A } from "./contracts/output/ordering_A"; +import { B } from "./contracts/output/ordering_B"; -describe("feature-ordering", () => { +describe("ordering", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-random.spec.ts b/src/test/e2e-emulated/random.spec.ts similarity index 86% rename from src/test/feature-random.spec.ts rename to src/test/e2e-emulated/random.spec.ts index 774da3bea..37db3f76a 100644 --- a/src/test/feature-random.spec.ts +++ b/src/test/e2e-emulated/random.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { RandomContract } from "./features/output/random_RandomContract"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { RandomContract } from "./contracts/output/random_RandomContract"; -describe("feature-random", () => { +describe("random", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-recursion.spec.ts b/src/test/e2e-emulated/recursion.spec.ts similarity index 85% rename from src/test/feature-recursion.spec.ts rename to src/test/e2e-emulated/recursion.spec.ts index e2e8864ef..c46f7625a 100644 --- a/src/test/feature-recursion.spec.ts +++ b/src/test/e2e-emulated/recursion.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { RecursionTester } from "./features/output/recursion_RecursionTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { RecursionTester } from "./contracts/output/recursion_RecursionTester"; -describe("feature-recursion", () => { +describe("recursion", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/e2e-emulated/sample-jetton.spec.ts b/src/test/e2e-emulated/sample-jetton.spec.ts new file mode 100644 index 000000000..c65ae9fed --- /dev/null +++ b/src/test/e2e-emulated/sample-jetton.spec.ts @@ -0,0 +1,42 @@ +import { beginCell, toNano } from "@ton/core"; +import { ContractSystem } from "@tact-lang/emulator"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { SampleJetton } from "./contracts/output/sample-jetton_SampleJetton"; +import { JettonDefaultWallet } from "./contracts/output/sample-jetton_JettonDefaultWallet"; + +describe("bugs", () => { + beforeEach(() => { + __DANGER_resetNodeId(); + }); + it("should deploy sample jetton correctly", async () => { + // Init + const system = await ContractSystem.create(); + const treasure = system.treasure("treasure"); + const contract = system.open( + await SampleJetton.fromInit( + treasure.address, + beginCell().endCell(), + toNano("100"), + ), + ); + const target = system.open( + await JettonDefaultWallet.fromInit( + contract.address, + treasure.address, + ), + ); + const tracker = system.track(target.address); + await contract.send( + treasure, + { value: toNano("10") }, + { + $$type: "Mint", + receiver: treasure.address, + amount: toNano("10"), + }, + ); + await system.run(); + + expect(tracker.collect()).toMatchSnapshot(); + }); +}); diff --git a/src/test/feature-send.spec.ts b/src/test/e2e-emulated/send.spec.ts similarity index 91% rename from src/test/feature-send.spec.ts rename to src/test/e2e-emulated/send.spec.ts index 28ce0def5..005591c0a 100644 --- a/src/test/feature-send.spec.ts +++ b/src/test/e2e-emulated/send.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { SendTester } from "./features/output/send_SendTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { SendTester } from "./contracts/output/send_SendTester"; -describe("feature-send", () => { +describe("send", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-serialization.spec.ts b/src/test/e2e-emulated/serialization.spec.ts similarity index 94% rename from src/test/feature-serialization.spec.ts rename to src/test/e2e-emulated/serialization.spec.ts index 6e600b54c..de6e9360c 100644 --- a/src/test/feature-serialization.spec.ts +++ b/src/test/e2e-emulated/serialization.spec.ts @@ -1,10 +1,10 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { SerializationTester2 } from "./features/output/serialization-2_SerializationTester2"; -import { SerializationTester } from "./features/output/serialization_SerializationTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { SerializationTester2 } from "./contracts/output/serialization-2_SerializationTester2"; +import { SerializationTester } from "./contracts/output/serialization_SerializationTester"; -describe("feature-serialization", () => { +describe("serialization", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/stdlib.spec.ts b/src/test/e2e-emulated/stdlib.spec.ts similarity index 100% rename from src/test/stdlib.spec.ts rename to src/test/e2e-emulated/stdlib.spec.ts diff --git a/src/test/feature-strings.spec.ts b/src/test/e2e-emulated/strings.spec.ts similarity index 94% rename from src/test/feature-strings.spec.ts rename to src/test/e2e-emulated/strings.spec.ts index 92cbebd8a..4adfc1b90 100644 --- a/src/test/feature-strings.spec.ts +++ b/src/test/e2e-emulated/strings.spec.ts @@ -1,9 +1,9 @@ import { beginCell, toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { StringsTester } from "./features/output/strings_StringsTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { StringsTester } from "./contracts/output/strings_StringsTester"; -describe("feature-strings", () => { +describe("strings", () => { beforeEach(() => { __DANGER_resetNodeId(); }); @@ -15,6 +15,10 @@ describe("feature-strings", () => { await contract.send(treasure, { value: toNano("10") }, null); await system.run(); + expect(contract.abi.errors!["31733"].message).toStrictEqual( + "condition can`t be...", + ); + // Check methods expect(await contract.getConstantString()).toBe("test string"); expect(await contract.getConstantStringUnicode()).toBe("привет мир 👀"); diff --git a/src/test/feature-ternary.spec.ts b/src/test/e2e-emulated/ternary.spec.ts similarity index 91% rename from src/test/feature-ternary.spec.ts rename to src/test/e2e-emulated/ternary.spec.ts index 11ee59eeb..c07bc9c4c 100644 --- a/src/test/feature-ternary.spec.ts +++ b/src/test/e2e-emulated/ternary.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { TernaryTester } from "./features/output/ternary_TernaryTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { TernaryTester } from "./contracts/output/ternary_TernaryTester"; -describe("feature-ternary", () => { +describe("ternary", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/feature-try-catch.spec.ts b/src/test/e2e-emulated/try-catch.spec.ts similarity index 90% rename from src/test/feature-try-catch.spec.ts rename to src/test/e2e-emulated/try-catch.spec.ts index 937ecea35..45fc6c9bd 100644 --- a/src/test/feature-try-catch.spec.ts +++ b/src/test/e2e-emulated/try-catch.spec.ts @@ -1,9 +1,9 @@ import { toNano } from "@ton/core"; import { ContractSystem } from "@tact-lang/emulator"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { TryCatchTester } from "./features/output/try-catch_TryCatchTester"; +import { __DANGER_resetNodeId } from "../../grammar/ast"; +import { TryCatchTester } from "./contracts/output/try-catch_TryCatchTester"; -describe("feature-ternary", () => { +describe("ternary", () => { beforeEach(() => { __DANGER_resetNodeId(); }); diff --git a/src/test/integration.spec.ts b/src/test/integration.spec.ts deleted file mode 100644 index 12895f0c9..000000000 --- a/src/test/integration.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import fs from "fs"; -import { CompilerContext } from "../context"; -import { __DANGER_resetNodeId } from "../grammar/ast"; -import { loadCases } from "../utils/loadCases"; -import { precompile } from "../pipeline/precompile"; -import { compile } from "../pipeline/compile"; -import { getContracts } from "../types/resolveDescriptors"; -import { createNodeFileSystem } from "../vfs/createNodeFileSystem"; -import { createVirtualFileSystem } from "../vfs/createVirtualFileSystem"; -import files from "../imports/stdlib"; - -describe("integration", () => { - beforeEach(() => { - __DANGER_resetNodeId(); - }); - for (const r of loadCases(__dirname + "/contracts/")) { - it("should resolve expressions for " + r.name, async () => { - let ctx = new CompilerContext({ shared: {} }); - const project = createNodeFileSystem(__dirname + "/contracts/"); - const stdlib = createVirtualFileSystem("@stdlib", files); - ctx = precompile(ctx, project, stdlib, r.name + ".tact"); - const contract = getContracts(ctx)[0]; - const res = await compile(ctx, contract, r.name + "_" + contract); - for (const f of res.output.files) { - expect(f.code).toEqual( - fs.readFileSync( - __dirname + "/contracts/output/" + f.name, - "utf8", - ), - ); - } - }); - } -}); diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 558d43690..ce42d8052 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -1,64 +1,66 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`resolveDescriptors should fail descriptors for case-0 1`] = ` -":9:1: Native functions cannot be getters -Line 9, col 1: - 8 | @name(hello_world) -> 9 | get native sample(a: Int): Int; - ^~~ +exports[`resolveDescriptors should fail descriptors for const-eval-overflow 1`] = ` +":8:21: Cannot evaluate constant expression due to integer overflow +Line 8, col 21: + 7 | +> 8 | const a: Int = 1 + (1 >> -1073741824); + ^~~~~~~~~~~~~~~~ + 9 | " `; -exports[`resolveDescriptors should fail descriptors for case-1 1`] = ` -":9:1: Native functions cannot be getters -Line 9, col 1: - 8 | @name(hello_world) -> 9 | get native sample(a: Int): Int; - ^~~ +exports[`resolveDescriptors should fail descriptors for contract-bounced-receiver-int 1`] = ` +":17:3: Bounce receive function can only accept bounced message, message or Slice +Line 17, col 3: + 16 | +> 17 | bounced(src: Int) { + ^~~~~~~~~~~~~~~~~~~ + 18 | " `; -exports[`resolveDescriptors should fail descriptors for case-2 1`] = ` -":8:1: Getters must be defined within a contract -Line 8, col 1: - 7 | -> 8 | get fun sample(a: Int): Int { - ^~~ - 9 | return 0; +exports[`resolveDescriptors should fail descriptors for contract-bounced-storage-var 1`] = ` +":15:3: bounced is a runtime only type and can't be used as field +Line 15, col 3: + 14 | contract Test { +> 15 | src: bounced; + ^~~~~~~~~~~~~~~ + 16 | init() {} " `; -exports[`resolveDescriptors should fail descriptors for case-3 1`] = ` -":8:1: Getters must be defined within a contract -Line 8, col 1: - 7 | -> 8 | get fun sample(a: Int): Int { - ^~~ - 9 | return 0; +exports[`resolveDescriptors should fail descriptors for contract-duplicate-bounced-fallback-receiver 1`] = ` +":24:3: Fallback bounce receive function already exists +Line 24, col 3: + 23 | +> 24 | bounced(msg: Slice) { + ^~~~~~~~~~~~~~~~~~~~~ + 25 | } " `; -exports[`resolveDescriptors should fail descriptors for case-4 1`] = ` -":8:17: Extend function must have first argument named "self" -Line 8, col 17: - 7 | -> 8 | extends fun inc(a: Int): Int { - ^~~~~~ - 9 | return a + 1; +exports[`resolveDescriptors should fail descriptors for contract-duplicate-bounced-receiver 1`] = ` +":24:3: Bounce receive function for "A" already exists +Line 24, col 3: + 23 | +> 24 | bounced(msg: bounced) { + ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 25 | } " `; -exports[`resolveDescriptors should fail descriptors for case-5 1`] = ` -":8:17: Argument name "self" is reserved -Line 8, col 17: - 7 | -> 8 | fun inc(a: Int, self: Int): Int { - ^~~~~~~~~ - 9 | return a + 1 + self; +exports[`resolveDescriptors should fail descriptors for contract-duplicate-init 1`] = ` +":13:5: Init function already exists +Line 13, col 5: + 12 | +> 13 | init(a: Bool) { + ^~~~~~~~~~~~~~~ + 14 | " `; -exports[`resolveDescriptors should fail descriptors for case-6 1`] = ` +exports[`resolveDescriptors should fail descriptors for contract-duplicate-storage-var 1`] = ` ":11:3: Field "b" already exists Line 11, col 3: 10 | b: Int; @@ -68,17 +70,27 @@ Line 11, col 3: " `; -exports[`resolveDescriptors should fail descriptors for case-7 1`] = ` -":11:3: Field "b" already exists -Line 11, col 3: - 10 | b: Int; -> 11 | b: Int; - ^~~~~~ - 12 | } +exports[`resolveDescriptors should fail descriptors for contract-missing-type 1`] = ` +":12:23: Type Point not found +Line 12, col 23: + 11 | } +> 12 | get fun hello2(): Point { + ^~~~~ + 13 | return 0; +" +`; + +exports[`resolveDescriptors should fail descriptors for contract-receiver-int 1`] = ` +":13:3: Receive function can only accept message, Slice or String +Line 13, col 3: + 12 | contract Pair { +> 13 | receive(src: Int) { + ^~~~~~~~~~~~~~~~~~~ + 14 | " `; -exports[`resolveDescriptors should fail descriptors for case-8 1`] = ` +exports[`resolveDescriptors should fail descriptors for contract-receiver-optional-msg 1`] = ` ":13:3: Receive function cannot have optional argument Line 13, col 3: 12 | contract Pair { @@ -88,7 +100,7 @@ Line 13, col 3: " `; -exports[`resolveDescriptors should fail descriptors for case-9 1`] = ` +exports[`resolveDescriptors should fail descriptors for contract-receiver-struct 1`] = ` ":13:3: Receive function can only accept message Line 13, col 3: 12 | contract Pair { @@ -98,47 +110,64 @@ Line 13, col 3: " `; -exports[`resolveDescriptors should fail descriptors for case-10 1`] = ` -":13:3: Receive function can only accept message, Slice or String -Line 13, col 3: - 12 | contract Pair { -> 13 | receive(src: Int) { - ^~~~~~~~~~~~~~~~~~~ - 14 | +exports[`resolveDescriptors should fail descriptors for expr-bitwise-not-bool-in-const1 1`] = ` +":4:18: Cannot reduce expression to a constant integer +Line 4, col 18: + 3 | +> 4 | const a: Int = ~ true; + ^~~~ " `; -exports[`resolveDescriptors should fail descriptors for case-11 1`] = ` -":12:23: Type Point not found -Line 12, col 23: - 11 | } -> 12 | get fun hello2(): Point { - ^~~~~ - 13 | return 0; +exports[`resolveDescriptors should fail descriptors for expr-bitwise-not-bool-in-const2 1`] = ` +":4:17: Cannot reduce expression to a constant boolean +Line 4, col 17: + 3 | +> 4 | const a: Bool = ~ true; + ^~~~~~ " `; -exports[`resolveDescriptors should fail descriptors for case-12 1`] = ` -":12:1: Type "Main" already exists -Line 12, col 1: - 11 | -> 12 | struct Main { - ^~~~~~~~~~~~~ - 13 | +exports[`resolveDescriptors should fail descriptors for getter-outside-contract 1`] = ` +":8:1: Getters must be defined within a contract +Line 8, col 1: + 7 | +> 8 | get fun sample(a: Int): Int { + ^~~ + 9 | return 0; " `; -exports[`resolveDescriptors should fail descriptors for case-13 1`] = ` -":12:1: Type "Main" already exists -Line 12, col 1: - 11 | -> 12 | struct Main { - ^~~~~~~~~~~~~ - 13 | +exports[`resolveDescriptors should fail descriptors for method-first-param-not-self1 1`] = ` +":8:17: Extend function must have first argument named "self" +Line 8, col 17: + 7 | +> 8 | extends fun inc(a: Int): Int { + ^~~~~~ + 9 | return a + 1; +" +`; + +exports[`resolveDescriptors should fail descriptors for method-first-param-not-self2 1`] = ` +":8:17: Argument name "self" is reserved +Line 8, col 17: + 7 | +> 8 | fun inc(a: Int, self: Int): Int { + ^~~~~~~~~ + 9 | return a + 1 + self; +" +`; + +exports[`resolveDescriptors should fail descriptors for native-fun-getter 1`] = ` +":9:1: Native functions cannot be getters +Line 9, col 1: + 8 | @name(hello_world) +> 9 | get native sample(a: Int): Int; + ^~~ " `; -exports[`resolveDescriptors should fail descriptors for case-14 1`] = ` +exports[`resolveDescriptors should fail descriptors for scope-contract-shadows-contract 1`] = ` ":12:1: Type "Main" already exists Line 12, col 1: 11 | @@ -148,17 +177,35 @@ Line 12, col 1: " `; -exports[`resolveDescriptors should fail descriptors for case-15 1`] = ` -":12:1: Struct "Main" must have at least one field +exports[`resolveDescriptors should fail descriptors for scope-duplicate-method 1`] = ` +":12:1: Function "hello" already exists in type "Main" Line 12, col 1: 11 | -> 12 | struct Main { - ^~~~~~~~~~~~~ - 13 | +> 12 | extends fun hello(self: Main): Bool { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 13 | return true; +" +`; + +exports[`resolveDescriptors should fail descriptors for scope-fun-shadows-builtin-dumpStack 1`] = ` +":1:1: Static function "dumpStack" already exists +Line 1, col 1: +> 1 | fun dumpStack() { + ^~~~~~~~~~~~~~~~~ + 2 | +" +`; + +exports[`resolveDescriptors should fail descriptors for scope-fun-shadows-builtin-ton 1`] = ` +":1:1: Static function "ton" already exists +Line 1, col 1: +> 1 | fun ton() { + ^~~~~~~~~~~ + 2 | " `; -exports[`resolveDescriptors should fail descriptors for case-16 1`] = ` +exports[`resolveDescriptors should fail descriptors for scope-fun-shadows-fun 1`] = ` ":16:1: Struct "Main" must have at least one field Line 16, col 1: 15 | @@ -168,7 +215,7 @@ Line 16, col 1: " `; -exports[`resolveDescriptors should fail descriptors for case-17 1`] = ` +exports[`resolveDescriptors should fail descriptors for scope-internal-fun-shadows-internal-fun 1`] = ` ":8:1: Function "hello" already exists in type "Main" Line 8, col 1: 7 | @@ -178,7 +225,7 @@ Line 8, col 1: " `; -exports[`resolveDescriptors should fail descriptors for case-18 1`] = ` +exports[`resolveDescriptors should fail descriptors for scope-param-shadows-param 1`] = ` ":9:24: Argument name "a" is already used Line 9, col 24: 8 | contract Main { @@ -188,201 +235,131 @@ Line 9, col 24: " `; -exports[`resolveDescriptors should fail descriptors for case-19 1`] = ` -":13:5: Init function already exists -Line 13, col 5: - 12 | -> 13 | init(a: Bool) { - ^~~~~~~~~~~~~~~ - 14 | -" -`; - -exports[`resolveDescriptors should fail descriptors for case-20 1`] = ` -":12:1: Function "hello" already exists in type "Main" +exports[`resolveDescriptors should fail descriptors for scope-struct-shadows-contract 1`] = ` +":12:1: Type "Main" already exists Line 12, col 1: 11 | -> 12 | extends fun hello(self: Main): Bool { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 13 | return true; -" -`; - -exports[`resolveDescriptors should fail descriptors for case-21 1`] = ` -":17:3: Bounce receive function can only accept bounced message, message or Slice -Line 17, col 3: - 16 | -> 17 | bounced(src: Int) { - ^~~~~~~~~~~~~~~~~~~ - 18 | -" -`; - -exports[`resolveDescriptors should fail descriptors for case-22 1`] = ` -":24:3: Bounce receive function for "A" already exists -Line 24, col 3: - 23 | -> 24 | bounced(msg: bounced) { - ^~~~~~~~~~~~~~~~~~~~~~~~~~ - 25 | } +> 12 | struct Main { + ^~~~~~~~~~~~~ + 13 | " `; -exports[`resolveDescriptors should fail descriptors for case-23 1`] = ` -":24:3: Fallback bounce receive function already exists -Line 24, col 3: - 23 | -> 24 | bounced(msg: Slice) { - ^~~~~~~~~~~~~~~~~~~~~ - 25 | } +exports[`resolveDescriptors should fail descriptors for scope-struct-shadows-struct 1`] = ` +":12:1: Type "Main" already exists +Line 12, col 1: + 11 | +> 12 | struct Main { + ^~~~~~~~~~~~~ + 13 | " `; -exports[`resolveDescriptors should fail descriptors for case-24 1`] = ` -":15:3: bounced is a runtime only type and can't be used as field -Line 15, col 3: - 14 | contract Test { -> 15 | src: bounced; - ^~~~~~~~~~~~~~~ - 16 | init() {} +exports[`resolveDescriptors should fail descriptors for struct-duplicate-field 1`] = ` +":11:3: Field "b" already exists +Line 11, col 3: + 10 | b: Int; +> 11 | b: Int; + ^~~~~~ + 12 | } " `; -exports[`resolveDescriptors should fail descriptors for case-25 1`] = ` -":8:21: Cannot evaluate constant expression due to integer overflow -Line 8, col 21: - 7 | -> 8 | const a: Int = 1 + (1 >> -1073741824); - ^~~~~~~~~~~~~~~~ - 9 | +exports[`resolveDescriptors should fail descriptors for struct-empty-not-allowed 1`] = ` +":12:1: Struct "Main" must have at least one field +Line 12, col 1: + 11 | +> 12 | struct Main { + ^~~~~~~~~~~~~ + 13 | " `; -exports[`resolveDescriptors should fail descriptors for case-26 1`] = ` -":1:1: Static function "ton" already exists -Line 1, col 1: -> 1 | fun ton() { - ^~~~~~~~~~~ - 2 | -" -`; - -exports[`resolveDescriptors should fail descriptors for case-27 1`] = ` -":1:1: Static function "dumpStack" already exists -Line 1, col 1: -> 1 | fun dumpStack() { - ^~~~~~~~~~~~~~~~~ - 2 | -" -`; - -exports[`resolveDescriptors should fail descriptors for case-28 1`] = ` -":4:18: Cannot reduce expression to a constant integer -Line 4, col 18: - 3 | -> 4 | const a: Int = ~ true; - ^~~~ -" -`; - -exports[`resolveDescriptors should fail descriptors for case-29 1`] = ` -":4:17: Cannot reduce expression to a constant boolean -Line 4, col 17: - 3 | -> 4 | const a: Bool = ~ true; - ^~~~~~ -" -`; - -exports[`resolveDescriptors should resolve descriptors for case-0 1`] = ` +exports[`resolveDescriptors should resolve descriptors for contract-bounced-slice 1`] = ` { - "BaseTrait": { + "A": { "ast": { - "attributes": [], - "declarations": [], - "id": 3, - "kind": "def_trait", - "name": "BaseTrait", + "fields": [ + { + "as": "uint32", + "id": 5, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int as uint32, + "type": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 6, + "kind": "def_struct", + "message": true, + "name": "A", "origin": "user", - "ref": trait BaseTrait { - + "prefix": null, + "ref": message A { + a: Int as uint32; }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "BaseTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - "Bool": { - "ast": { - "id": 2, - "kind": "primitive", - "name": "Bool", - "origin": "user", - "ref": primitive Bool;, - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive", - "name": "Bool", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 33424, - }, - "Int": { - "ast": { - "id": 1, - "kind": "primitive", - "name": "Int", - "origin": "user", - "ref": primitive Int;, }, "constants": [], "dependsOn": [], - "fields": [], + "fields": [ + { + "abi": { + "name": "a", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "uint", + }, + }, + "as": "uint32", + "ast": { + "as": "uint32", + "id": 5, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int as uint32, + "type": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + "default": undefined, + "index": 0, + "name": "a", + "ref": a: Int as uint32, + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], "functions": Map {}, - "header": null, + "header": 3746466057, "init": null, "interfaces": [], - "kind": "primitive", - "name": "Int", + "kind": "struct", + "name": "A", "origin": "user", - "partialFieldCount": 0, + "partialFieldCount": 1, "receivers": [], - "signature": null, - "tlb": null, + "signature": "A{a:uint32}", + "tlb": "a#df4e8909 a:uint32 = A", "traits": [], - "uid": 38154, + "uid": 22757, }, -} -`; - -exports[`resolveDescriptors should resolve descriptors for case-0 2`] = `{}`; - -exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` -{ "BaseTrait": { "ast": { "attributes": [], @@ -413,13 +390,13 @@ exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` "traits": [], "uid": 1020, }, - "Bool": { + "Int": { "ast": { - "id": 2, + "id": 1, "kind": "primitive", - "name": "Bool", + "name": "Int", "origin": "user", - "ref": primitive Bool;, + "ref": primitive Int;, }, "constants": [], "dependsOn": [], @@ -429,22 +406,22 @@ exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` "init": null, "interfaces": [], "kind": "primitive", - "name": "Bool", + "name": "Int", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, "traits": [], - "uid": 33424, + "uid": 38154, }, - "Int": { + "Slice": { "ast": { - "id": 1, + "id": 2, "kind": "primitive", - "name": "Int", + "name": "Slice", "origin": "user", - "ref": primitive Int;, + "ref": primitive Slice;, }, "constants": [], "dependsOn": [], @@ -454,58 +431,276 @@ exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` "init": null, "interfaces": [], "kind": "primitive", - "name": "Int", + "name": "Slice", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, "traits": [], - "uid": 38154, + "uid": 35456, }, - "Struct1": { + "Test": { "ast": { - "fields": [ + "attributes": [], + "declarations": [ { - "as": null, - "id": 5, - "init": null, - "kind": "def_field", - "name": "a", - "ref": a: Int, - "type": { - "id": 4, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, + "args": [], + "id": 7, + "kind": "def_init_function", + "ref": init() {}, + "statements": [], }, { - "as": null, - "id": 7, - "init": null, - "kind": "def_field", - "name": "b", - "ref": b: Bool, - "type": { - "id": 6, - "kind": "type_ref_simple", - "name": "Bool", - "optional": false, - "ref": Bool, + "id": 10, + "kind": "def_receive", + "ref": receive(src: A) { + + }, + "selector": { + "arg": { + "id": 9, + "kind": "def_argument", + "name": "src", + "ref": src: A, + "type": { + "id": 8, + "kind": "type_ref_simple", + "name": "A", + "optional": false, + "ref": A, + }, + }, + "kind": "internal-simple", }, + "statements": [], }, - ], - "id": 8, - "kind": "def_struct", - "message": false, - "name": "Struct1", - "origin": "user", - "prefix": null, - "ref": struct Struct1 { - a: Int; - b: Bool; + { + "id": 13, + "kind": "def_receive", + "ref": bounced(src: Slice) { + + }, + "selector": { + "arg": { + "id": 12, + "kind": "def_argument", + "name": "src", + "ref": src: Slice, + "type": { + "id": 11, + "kind": "type_ref_simple", + "name": "Slice", + "optional": false, + "ref": Slice, + }, + }, + "kind": "bounce", + }, + "statements": [], + }, + ], + "id": 14, + "kind": "def_contract", + "name": "Test", + "origin": "user", + "ref": contract Test { + init() {} + receive(src: A) { + + } + + bounced(src: Slice) { + + } +}, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": { + "args": [], + "ast": { + "args": [], + "id": 7, + "kind": "def_init_function", + "ref": init() {}, + "statements": [], + }, + }, + "interfaces": [], + "kind": "contract", + "name": "Test", + "origin": "user", + "partialFieldCount": 0, + "receivers": [ + { + "ast": { + "id": 10, + "kind": "def_receive", + "ref": receive(src: A) { + + }, + "selector": { + "arg": { + "id": 9, + "kind": "def_argument", + "name": "src", + "ref": src: A, + "type": { + "id": 8, + "kind": "type_ref_simple", + "name": "A", + "optional": false, + "ref": A, + }, + }, + "kind": "internal-simple", + }, + "statements": [], + }, + "selector": { + "kind": "internal-binary", + "name": "src", + "type": "A", + }, + }, + { + "ast": { + "id": 13, + "kind": "def_receive", + "ref": bounced(src: Slice) { + + }, + "selector": { + "arg": { + "id": 12, + "kind": "def_argument", + "name": "src", + "ref": src: Slice, + "type": { + "id": 11, + "kind": "type_ref_simple", + "name": "Slice", + "optional": false, + "ref": Slice, + }, + }, + "kind": "bounce", + }, + "statements": [], + }, + "selector": { + "kind": "bounce-fallback", + "name": "src", + }, + }, + ], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 3, + "kind": "def_trait", + "name": "BaseTrait", + "origin": "user", + "ref": trait BaseTrait { + +}, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "BaseTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 1020, + }, + ], + "uid": 44104, + }, +} +`; + +exports[`resolveDescriptors should resolve descriptors for contract-bounced-slice 2`] = `{}`; + +exports[`resolveDescriptors should resolve descriptors for contract-bounced-too-small-not-detected 1`] = ` +{ + "A": { + "ast": { + "fields": [ + { + "as": "uint32", + "id": 5, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int as uint32, + "type": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "as": null, + "id": 7, + "init": null, + "kind": "def_field", + "name": "b", + "ref": b: Bool, + "type": { + "id": 6, + "kind": "type_ref_simple", + "name": "Bool", + "optional": false, + "ref": Bool, + }, + }, + { + "as": "uint256", + "id": 9, + "init": null, + "kind": "def_field", + "name": "c", + "ref": c: Int as uint256, + "type": { + "id": 8, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 10, + "kind": "def_struct", + "message": true, + "name": "A", + "origin": "user", + "prefix": null, + "ref": message A { + a: Int as uint32; + b: Bool; + c: Int as uint256; }, }, "constants": [], @@ -515,20 +710,20 @@ exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` "abi": { "name": "a", "type": { - "format": 257, + "format": 32, "kind": "simple", "optional": false, - "type": "int", + "type": "uint", }, }, - "as": null, + "as": "uint32", "ast": { - "as": null, + "as": "uint32", "id": 5, "init": null, "kind": "def_field", "name": "a", - "ref": a: Int, + "ref": a: Int as uint32, "type": { "id": 4, "kind": "type_ref_simple", @@ -540,7 +735,7 @@ exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` "default": undefined, "index": 0, "name": "a", - "ref": a: Int, + "ref": a: Int as uint32, "type": { "kind": "ref", "name": "Int", @@ -582,110 +777,57 @@ exports[`resolveDescriptors should resolve descriptors for case-1 1`] = ` "optional": false, }, }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "struct", - "name": "Struct1", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": "Struct1{a:int257,b:bool}", - "tlb": "_ a:int257 b:bool = Struct1", - "traits": [], - "uid": 63177, - }, - "Struct2": { - "ast": { - "fields": [ - { - "as": null, - "id": 10, - "init": null, - "kind": "def_field", - "name": "a", - "ref": a: Struct1, - "type": { - "id": 9, - "kind": "type_ref_simple", - "name": "Struct1", - "optional": false, - "ref": Struct1, - }, - }, - ], - "id": 11, - "kind": "def_struct", - "message": false, - "name": "Struct2", - "origin": "user", - "prefix": null, - "ref": struct Struct2 { - a: Struct1; -}, - }, - "constants": [], - "dependsOn": [], - "fields": [ { "abi": { - "name": "a", + "name": "c", "type": { + "format": 256, "kind": "simple", "optional": false, - "type": "Struct1", + "type": "uint", }, }, - "as": null, + "as": "uint256", "ast": { - "as": null, - "id": 10, + "as": "uint256", + "id": 9, "init": null, "kind": "def_field", - "name": "a", - "ref": a: Struct1, + "name": "c", + "ref": c: Int as uint256, "type": { - "id": 9, + "id": 8, "kind": "type_ref_simple", - "name": "Struct1", + "name": "Int", "optional": false, - "ref": Struct1, + "ref": Int, }, }, "default": undefined, - "index": 0, - "name": "a", - "ref": a: Struct1, + "index": 2, + "name": "c", + "ref": c: Int as uint256, "type": { "kind": "ref", - "name": "Struct1", + "name": "Int", "optional": false, }, }, ], "functions": Map {}, - "header": null, + "header": 2219696518, "init": null, "interfaces": [], "kind": "struct", - "name": "Struct2", + "name": "A", "origin": "user", - "partialFieldCount": 0, + "partialFieldCount": 2, "receivers": [], - "signature": "Struct2{a:Struct1{a:int257,b:bool}}", - "tlb": "_ a:Struct1{a:int257,b:bool} = Struct2", + "signature": "A{a:uint32,b:bool,c:uint256}", + "tlb": "a#844de186 a:uint32 b:bool c:uint256 = A", "traits": [], - "uid": 50858, + "uid": 22757, }, -} -`; - -exports[`resolveDescriptors should resolve descriptors for case-1 2`] = `{}`; - -exports[`resolveDescriptors should resolve descriptors for case-2 1`] = ` -{ "BaseTrait": { "ast": { "attributes": [], @@ -766,189 +908,259 @@ exports[`resolveDescriptors should resolve descriptors for case-2 1`] = ` "traits": [], "uid": 38154, }, -} -`; - -exports[`resolveDescriptors should resolve descriptors for case-2 2`] = ` -{ - "testFunc": { - "args": [], + "Test": { "ast": { - "args": [], "attributes": [], - "id": 7, - "kind": "def_function", - "name": "testFunc", - "origin": "user", - "ref": fun testFunc(): Int { - return 0; -}, - "return": { - "id": 4, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ + "declarations": [ { - "expression": { - "id": 5, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "id": 6, - "kind": "statement_return", - "ref": return 0;, + "args": [], + "id": 11, + "kind": "def_init_function", + "ref": init() {}, + "statements": [], }, - ], - }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": false, - "isOverrides": false, - "isVirtual": false, - "name": "testFunc", - "origin": "user", - "returns": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - "self": null, - }, - "testFunc2": { - "args": [], - "ast": { - "args": [], - "attributes": [], - "id": 10, - "kind": "def_function", - "name": "testFunc2", - "origin": "user", - "ref": fun testFunc2() { - return 0; -}, - "return": null, - "statements": [ { - "expression": { - "id": 8, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "id": 9, - "kind": "statement_return", - "ref": return 0;, - }, - ], - }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": false, - "isOverrides": false, - "isVirtual": false, - "name": "testFunc2", - "origin": "user", - "returns": { - "kind": "void", - }, - "self": null, + "id": 14, + "kind": "def_receive", + "ref": receive(src: A) { + }, - "testFunc3": { - "args": [ - { - "name": "a", - "ref": a: Int, - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - { - "name": "b", - "ref": b: Bool, - "type": { - "kind": "ref", - "name": "Bool", - "optional": false, - }, - }, - ], - "ast": { - "args": [ - { - "id": 12, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 11, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, + "selector": { + "arg": { + "id": 13, + "kind": "def_argument", + "name": "src", + "ref": src: A, + "type": { + "id": 12, + "kind": "type_ref_simple", + "name": "A", + "optional": false, + "ref": A, + }, + }, + "kind": "internal-simple", }, + "statements": [], }, { - "id": 14, - "kind": "def_argument", - "name": "b", - "ref": b: Bool, - "type": { - "id": 13, - "kind": "type_ref_simple", - "name": "Bool", - "optional": false, - "ref": Bool, + "id": 21, + "kind": "def_receive", + "ref": bounced(src: bounced) { + let x: Int = src.c; + }, + "selector": { + "arg": { + "id": 16, + "kind": "def_argument", + "name": "src", + "ref": src: bounced, + "type": { + "id": 15, + "kind": "type_ref_bounced", + "name": "A", + "ref": bounced, + }, + }, + "kind": "bounce", }, + "statements": [ + { + "expression": { + "id": 19, + "kind": "op_field", + "name": "c", + "ref": src.c, + "src": { + "id": 18, + "kind": "id", + "ref": src, + "value": "src", + }, + }, + "id": 20, + "kind": "statement_let", + "name": "x", + "ref": let x: Int = src.c;, + "type": { + "id": 17, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], }, ], - "attributes": [], - "id": 17, - "kind": "def_function", - "name": "testFunc3", - "origin": "user", - "ref": fun testFunc3(a: Int, b: Bool) { - return 0; -}, - "return": null, - "statements": [ - { - "expression": { - "id": 15, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "id": 16, - "kind": "statement_return", - "ref": return 0;, - }, - ], + "id": 22, + "kind": "def_contract", + "name": "Test", + "origin": "user", + "ref": contract Test { + init() {} + receive(src: A) { + + } + + bounced(src: bounced) { + let x: Int = src.c; + } +}, + "traits": [], }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": false, - "isOverrides": false, - "isVirtual": false, - "name": "testFunc3", - "origin": "user", - "returns": { - "kind": "void", + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": { + "args": [], + "ast": { + "args": [], + "id": 11, + "kind": "def_init_function", + "ref": init() {}, + "statements": [], + }, }, - "self": null, + "interfaces": [], + "kind": "contract", + "name": "Test", + "origin": "user", + "partialFieldCount": 0, + "receivers": [ + { + "ast": { + "id": 14, + "kind": "def_receive", + "ref": receive(src: A) { + + }, + "selector": { + "arg": { + "id": 13, + "kind": "def_argument", + "name": "src", + "ref": src: A, + "type": { + "id": 12, + "kind": "type_ref_simple", + "name": "A", + "optional": false, + "ref": A, + }, + }, + "kind": "internal-simple", + }, + "statements": [], + }, + "selector": { + "kind": "internal-binary", + "name": "src", + "type": "A", + }, + }, + { + "ast": { + "id": 21, + "kind": "def_receive", + "ref": bounced(src: bounced) { + let x: Int = src.c; + }, + "selector": { + "arg": { + "id": 16, + "kind": "def_argument", + "name": "src", + "ref": src: bounced, + "type": { + "id": 15, + "kind": "type_ref_bounced", + "name": "A", + "ref": bounced, + }, + }, + "kind": "bounce", + }, + "statements": [ + { + "expression": { + "id": 19, + "kind": "op_field", + "name": "c", + "ref": src.c, + "src": { + "id": 18, + "kind": "id", + "ref": src, + "value": "src", + }, + }, + "id": 20, + "kind": "statement_let", + "name": "x", + "ref": let x: Int = src.c;, + "type": { + "id": 17, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + }, + "selector": { + "bounced": true, + "kind": "bounce-binary", + "name": "src", + "type": "A", + }, + }, + ], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 3, + "kind": "def_trait", + "name": "BaseTrait", + "origin": "user", + "ref": trait BaseTrait { + +}, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "BaseTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 1020, + }, + ], + "uid": 44104, }, } `; -exports[`resolveDescriptors should resolve descriptors for case-3 1`] = ` +exports[`resolveDescriptors should resolve descriptors for contract-bounced-too-small-not-detected 2`] = `{}`; + +exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-uninit-storage-vars 1`] = ` { "BaseTrait": { "ast": { @@ -1313,9 +1525,9 @@ exports[`resolveDescriptors should resolve descriptors for case-3 1`] = ` } `; -exports[`resolveDescriptors should resolve descriptors for case-3 2`] = `{}`; +exports[`resolveDescriptors should resolve descriptors for init-vars-analysis-uninit-storage-vars 2`] = `{}`; -exports[`resolveDescriptors should resolve descriptors for case-4 1`] = ` +exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors-in-bodies1 1`] = ` { "BaseTrait": { "ast": { @@ -1400,44 +1612,20 @@ exports[`resolveDescriptors should resolve descriptors for case-4 1`] = ` } `; -exports[`resolveDescriptors should resolve descriptors for case-4 2`] = ` +exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors-in-bodies1 2`] = ` { - "sample": { - "args": [ - { - "name": "a", - "ref": a: Int, - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], + "testFunc": { + "args": [], "ast": { - "args": [ - { - "id": 6, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 5, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], + "args": [], "attributes": [], "id": 7, - "kind": "def_native_function", - "name": "sample", - "nativeName": "hello_world", + "kind": "def_function", + "name": "testFunc", "origin": "user", - "ref": @name(hello_world) -native sample(a: Int): Int;, + "ref": fun testFunc(): Int { + return 0; +}, "return": { "id": 4, "kind": "type_ref_simple", @@ -1445,14 +1633,27 @@ native sample(a: Int): Int;, "optional": false, "ref": Int, }, - }, - "isAbstract": false, + "statements": [ + { + "expression": { + "id": 5, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 6, + "kind": "statement_return", + "ref": return 0;, + }, + ], + }, + "isAbstract": false, "isGetter": false, "isInline": false, "isMutating": false, "isOverrides": false, "isVirtual": false, - "name": "sample", + "name": "testFunc", "origin": "user", "returns": { "kind": "ref", @@ -1461,10 +1662,136 @@ native sample(a: Int): Int;, }, "self": null, }, + "testFunc2": { + "args": [], + "ast": { + "args": [], + "attributes": [], + "id": 10, + "kind": "def_function", + "name": "testFunc2", + "origin": "user", + "ref": fun testFunc2() { + return 0; +}, + "return": null, + "statements": [ + { + "expression": { + "id": 8, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 9, + "kind": "statement_return", + "ref": return 0;, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "testFunc2", + "origin": "user", + "returns": { + "kind": "void", + }, + "self": null, + }, + "testFunc3": { + "args": [ + { + "name": "a", + "ref": a: Int, + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + { + "name": "b", + "ref": b: Bool, + "type": { + "kind": "ref", + "name": "Bool", + "optional": false, + }, + }, + ], + "ast": { + "args": [ + { + "id": 12, + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { + "id": 11, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { + "id": 14, + "kind": "def_argument", + "name": "b", + "ref": b: Bool, + "type": { + "id": 13, + "kind": "type_ref_simple", + "name": "Bool", + "optional": false, + "ref": Bool, + }, + }, + ], + "attributes": [], + "id": 17, + "kind": "def_function", + "name": "testFunc3", + "origin": "user", + "ref": fun testFunc3(a: Int, b: Bool) { + return 0; +}, + "return": null, + "statements": [ + { + "expression": { + "id": 15, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 16, + "kind": "statement_return", + "ref": return 0;, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "testFunc3", + "origin": "user", + "returns": { + "kind": "void", + }, + "self": null, + }, } `; -exports[`resolveDescriptors should resolve descriptors for case-5 1`] = ` +exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors-in-bodies2 1`] = ` { "BaseTrait": { "ast": { @@ -1532,18 +1859,48 @@ exports[`resolveDescriptors should resolve descriptors for case-5 1`] = ` "constants": [], "dependsOn": [], "fields": [], - "functions": Map { - "inc" => { - "args": [], - "ast": { + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + "Main": { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int, + "type": { + "id": 7, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + { "args": [ { - "id": 6, + "id": 10, "kind": "def_argument", - "name": "self", - "ref": self: Int, + "name": "a", + "ref": a: Int, "type": { - "id": 5, + "id": 9, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -1551,167 +1908,191 @@ exports[`resolveDescriptors should resolve descriptors for case-5 1`] = ` }, }, ], - "attributes": [ + "id": 15, + "kind": "def_init_function", + "ref": init(a: Int) { + self.a = a; + }, + "statements": [ { - "ref": mutates, - "type": "mutates", + "expression": { + "id": 13, + "kind": "id", + "ref": a, + "value": "a", + }, + "id": 14, + "kind": "statement_assign", + "path": [ + { + "id": 11, + "kind": "lvalue_ref", + "name": "self", + "ref": self., + }, + { + "id": 12, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": self.a = a;, }, + ], + }, + { + "args": [], + "attributes": [ { - "ref": extends, - "type": "extends", + "ref": get, + "type": "get", }, ], - "id": 7, - "kind": "def_native_function", - "name": "inc", - "nativeName": "inc", + "id": 19, + "kind": "def_function", + "name": "hello", "origin": "user", - "ref": @name(inc) -mutates extends native inc(self: Int): Int;, + "ref": get fun hello(): Int { + return 0; + }, "return": { - "id": 4, + "id": 16, "kind": "type_ref_simple", "name": "Int", "optional": false, "ref": Int, }, + "statements": [ + { + "expression": { + "id": 17, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 18, + "kind": "statement_return", + "ref": return 0;, + }, + ], }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": true, - "isOverrides": false, - "isVirtual": false, - "name": "inc", - "origin": "user", - "returns": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - "self": "Int", - }, + { + "args": [], + "attributes": [ + { + "ref": get, + "type": "get", + }, + ], + "id": 23, + "kind": "def_function", + "name": "hello2", + "origin": "user", + "ref": get fun hello2(): Point { + return 0; }, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive", - "name": "Int", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 38154, - }, -} -`; - -exports[`resolveDescriptors should resolve descriptors for case-5 2`] = `{}`; - -exports[`resolveDescriptors should resolve descriptors for case-6 1`] = ` -{ - "BaseTrait": { - "ast": { - "attributes": [], - "declarations": [], - "id": 3, - "kind": "def_trait", - "name": "BaseTrait", + "return": { + "id": 20, + "kind": "type_ref_simple", + "name": "Point", + "optional": false, + "ref": Point, + }, + "statements": [ + { + "expression": { + "id": 21, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 22, + "kind": "statement_return", + "ref": return 0;, + }, + ], + }, + ], + "id": 24, + "kind": "def_contract", + "name": "Main", "origin": "user", - "ref": trait BaseTrait { - + "ref": contract Main { + a: Int; + init(a: Int) { + self.a = a; + } + + get fun hello(): Int { + return 0; + } + get fun hello2(): Point { + return 0; + } }, "traits": [], }, "constants": [], "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "BaseTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - "Bool": { - "ast": { - "id": 2, - "kind": "primitive", - "name": "Bool", - "origin": "user", - "ref": primitive Bool;, - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive", - "name": "Bool", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 33424, - }, - "Int": { - "ast": { - "id": 1, - "kind": "primitive", - "name": "Int", - "origin": "user", - "ref": primitive Int;, - }, - "constants": [], - "dependsOn": [], - "fields": [], + "fields": [ + { + "abi": { + "name": "a", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Int, + "type": { + "id": 7, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + "default": undefined, + "index": 0, + "name": "a", + "ref": a: Int, + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], "functions": Map { - "inc" => { + "hello" => { "args": [], "ast": { - "args": [ - { - "id": 6, - "kind": "def_argument", - "name": "self", - "ref": self: Int, - "type": { - "id": 5, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], + "args": [], "attributes": [ { - "ref": extends, - "type": "extends", + "ref": get, + "type": "get", }, ], - "id": 11, + "id": 19, "kind": "def_function", - "name": "inc", + "name": "hello", "origin": "user", - "ref": extends fun inc(self: Int): Int { - return self + 1; -}, + "ref": get fun hello(): Int { + return 0; + }, "return": { - "id": 4, + "id": 16, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -1720,64 +2101,281 @@ exports[`resolveDescriptors should resolve descriptors for case-6 1`] = ` "statements": [ { "expression": { - "id": 9, - "kind": "op_binary", - "left": { - "id": 7, - "kind": "id", - "ref": self, - "value": "self", - }, - "op": "+", - "ref": self + 1, - "right": { - "id": 8, - "kind": "number", - "ref": 1, - "value": 1n, - }, + "id": 17, + "kind": "number", + "ref": 0, + "value": 0n, }, - "id": 10, + "id": 18, "kind": "statement_return", - "ref": return self + 1;, + "ref": return 0;, }, ], }, "isAbstract": false, - "isGetter": false, + "isGetter": true, "isInline": false, - "isMutating": false, + "isMutating": true, "isOverrides": false, "isVirtual": false, - "name": "inc", + "name": "hello", "origin": "user", "returns": { "kind": "ref", "name": "Int", "optional": false, }, - "self": "Int", + "self": "Main", }, - }, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive", - "name": "Int", - "origin": "user", + "hello2" => { + "args": [], + "ast": { + "args": [], + "attributes": [ + { + "ref": get, + "type": "get", + }, + ], + "id": 23, + "kind": "def_function", + "name": "hello2", + "origin": "user", + "ref": get fun hello2(): Point { + return 0; + }, + "return": { + "id": 20, + "kind": "type_ref_simple", + "name": "Point", + "optional": false, + "ref": Point, + }, + "statements": [ + { + "expression": { + "id": 21, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 22, + "kind": "statement_return", + "ref": return 0;, + }, + ], + }, + "isAbstract": false, + "isGetter": true, + "isInline": false, + "isMutating": true, + "isOverrides": false, + "isVirtual": false, + "name": "hello2", + "origin": "user", + "returns": { + "kind": "ref", + "name": "Point", + "optional": false, + }, + "self": "Main", + }, + }, + "header": null, + "init": { + "args": [ + { + "as": null, + "name": "a", + "ref": a: Int, + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "ast": { + "args": [ + { + "id": 10, + "kind": "def_argument", + "name": "a", + "ref": a: Int, + "type": { + "id": 9, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 15, + "kind": "def_init_function", + "ref": init(a: Int) { + self.a = a; + }, + "statements": [ + { + "expression": { + "id": 13, + "kind": "id", + "ref": a, + "value": "a", + }, + "id": 14, + "kind": "statement_assign", + "path": [ + { + "id": 11, + "kind": "lvalue_ref", + "name": "self", + "ref": self., + }, + { + "id": 12, + "kind": "lvalue_ref", + "name": "a", + "ref": a, + }, + ], + "ref": self.a = a;, + }, + ], + }, + }, + "interfaces": [], + "kind": "contract", + "name": "Main", + "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 3, + "kind": "def_trait", + "name": "BaseTrait", + "origin": "user", + "ref": trait BaseTrait { + +}, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "BaseTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 1020, + }, + ], + "uid": 51099, + }, + "Point": { + "ast": { + "fields": [ + { + "as": null, + "id": 5, + "init": null, + "kind": "def_field", + "name": "p", + "ref": p: Int, + "type": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "id": 6, + "kind": "def_struct", + "message": false, + "name": "Point", + "origin": "user", + "prefix": null, + "ref": struct Point { + p: Int; +}, + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "p", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 5, + "init": null, + "kind": "def_field", + "name": "p", + "ref": p: Int, + "type": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + "default": undefined, + "index": 0, + "name": "p", + "ref": p: Int, + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "struct", + "name": "Point", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": "Point{p:int257}", + "tlb": "_ p:int257 = Point", "traits": [], - "uid": 38154, + "uid": 35778, }, } `; -exports[`resolveDescriptors should resolve descriptors for case-6 2`] = `{}`; +exports[`resolveDescriptors should resolve descriptors for item-funs-with-errors-in-bodies2 2`] = `{}`; -exports[`resolveDescriptors should resolve descriptors for case-7 1`] = ` +exports[`resolveDescriptors should resolve descriptors for item-method 1`] = ` { "BaseTrait": { "ast": { @@ -1845,48 +2443,18 @@ exports[`resolveDescriptors should resolve descriptors for case-7 1`] = ` "constants": [], "dependsOn": [], "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive", - "name": "Int", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 38154, - }, - "Main": { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 8, - "init": null, - "kind": "def_field", - "name": "a", - "ref": a: Int, - "type": { - "id": 7, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - { + "functions": Map { + "inc" => { + "args": [], + "ast": { "args": [ { - "id": 10, + "id": 6, "kind": "def_argument", - "name": "a", - "ref": a: Int, + "name": "self", + "ref": self: Int, "type": { - "id": 9, + "id": 5, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -1894,191 +2462,21 @@ exports[`resolveDescriptors should resolve descriptors for case-7 1`] = ` }, }, ], - "id": 15, - "kind": "def_init_function", - "ref": init(a: Int) { - self.a = a; - }, - "statements": [ - { - "expression": { - "id": 13, - "kind": "id", - "ref": a, - "value": "a", - }, - "id": 14, - "kind": "statement_assign", - "path": [ - { - "id": 11, - "kind": "lvalue_ref", - "name": "self", - "ref": self., - }, - { - "id": 12, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": self.a = a;, - }, - ], - }, - { - "args": [], - "attributes": [ - { - "ref": get, - "type": "get", - }, - ], - "id": 19, - "kind": "def_function", - "name": "hello", - "origin": "user", - "ref": get fun hello(): Int { - return 0; - }, - "return": { - "id": 16, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - "statements": [ - { - "expression": { - "id": 17, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "id": 18, - "kind": "statement_return", - "ref": return 0;, - }, - ], - }, - { - "args": [], "attributes": [ { - "ref": get, - "type": "get", + "ref": extends, + "type": "extends", }, ], - "id": 23, + "id": 11, "kind": "def_function", - "name": "hello2", + "name": "inc", "origin": "user", - "ref": get fun hello2(): Point { - return 0; - }, - "return": { - "id": 20, - "kind": "type_ref_simple", - "name": "Point", - "optional": false, - "ref": Point, - }, - "statements": [ - { - "expression": { - "id": 21, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "id": 22, - "kind": "statement_return", - "ref": return 0;, - }, - ], - }, - ], - "id": 24, - "kind": "def_contract", - "name": "Main", - "origin": "user", - "ref": contract Main { - a: Int; - init(a: Int) { - self.a = a; - } - - get fun hello(): Int { - return 0; - } - get fun hello2(): Point { - return 0; - } + "ref": extends fun inc(self: Int): Int { + return self + 1; }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "a", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, - "ast": { - "as": null, - "id": 8, - "init": null, - "kind": "def_field", - "name": "a", - "ref": a: Int, - "type": { - "id": 7, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - "default": undefined, - "index": 0, - "name": "a", - "ref": a: Int, - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map { - "hello" => { - "args": [], - "ast": { - "args": [], - "attributes": [ - { - "ref": get, - "type": "get", - }, - ], - "id": 19, - "kind": "def_function", - "name": "hello", - "origin": "user", - "ref": get fun hello(): Int { - return 0; - }, "return": { - "id": 16, + "id": 4, "kind": "type_ref_simple", "name": "Int", "optional": false, @@ -2087,243 +2485,317 @@ exports[`resolveDescriptors should resolve descriptors for case-7 1`] = ` "statements": [ { "expression": { - "id": 17, - "kind": "number", - "ref": 0, - "value": 0n, + "id": 9, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "id", + "ref": self, + "value": "self", + }, + "op": "+", + "ref": self + 1, + "right": { + "id": 8, + "kind": "number", + "ref": 1, + "value": 1n, + }, }, - "id": 18, + "id": 10, "kind": "statement_return", - "ref": return 0;, + "ref": return self + 1;, }, ], }, "isAbstract": false, - "isGetter": true, + "isGetter": false, "isInline": false, - "isMutating": true, + "isMutating": false, "isOverrides": false, "isVirtual": false, - "name": "hello", + "name": "inc", "origin": "user", "returns": { "kind": "ref", "name": "Int", "optional": false, }, - "self": "Main", + "self": "Int", }, - "hello2" => { - "args": [], - "ast": { - "args": [], - "attributes": [ - { - "ref": get, - "type": "get", - }, - ], - "id": 23, - "kind": "def_function", - "name": "hello2", - "origin": "user", - "ref": get fun hello2(): Point { - return 0; }, - "return": { - "id": 20, - "kind": "type_ref_simple", - "name": "Point", - "optional": false, - "ref": Point, - }, - "statements": [ - { - "expression": { - "id": 21, - "kind": "number", - "ref": 0, - "value": 0n, - }, - "id": 22, - "kind": "statement_return", - "ref": return 0;, - }, - ], - }, - "isAbstract": false, - "isGetter": true, - "isInline": false, - "isMutating": true, - "isOverrides": false, - "isVirtual": false, - "name": "hello2", - "origin": "user", - "returns": { + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, +} +`; + +exports[`resolveDescriptors should resolve descriptors for item-method 2`] = `{}`; + +exports[`resolveDescriptors should resolve descriptors for item-native-decl 1`] = ` +{ + "BaseTrait": { + "ast": { + "attributes": [], + "declarations": [], + "id": 3, + "kind": "def_trait", + "name": "BaseTrait", + "origin": "user", + "ref": trait BaseTrait { + +}, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "BaseTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 1020, + }, + "Bool": { + "ast": { + "id": 2, + "kind": "primitive", + "name": "Bool", + "origin": "user", + "ref": primitive Bool;, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive", + "name": "Bool", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 33424, + }, + "Int": { + "ast": { + "id": 1, + "kind": "primitive", + "name": "Int", + "origin": "user", + "ref": primitive Int;, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, +} +`; + +exports[`resolveDescriptors should resolve descriptors for item-native-decl 2`] = ` +{ + "sample": { + "args": [ + { + "name": "a", + "ref": a: Int, + "type": { "kind": "ref", - "name": "Point", + "name": "Int", "optional": false, }, - "self": "Main", }, - }, - "header": null, - "init": { + ], + "ast": { "args": [ { - "as": null, + "id": 6, + "kind": "def_argument", "name": "a", "ref": a: Int, "type": { - "kind": "ref", + "id": 5, + "kind": "type_ref_simple", "name": "Int", "optional": false, + "ref": Int, }, }, ], - "ast": { - "args": [ - { - "id": 10, - "kind": "def_argument", - "name": "a", - "ref": a: Int, - "type": { - "id": 9, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], - "id": 15, - "kind": "def_init_function", - "ref": init(a: Int) { - self.a = a; - }, - "statements": [ - { - "expression": { - "id": 13, - "kind": "id", - "ref": a, - "value": "a", - }, - "id": 14, - "kind": "statement_assign", - "path": [ - { - "id": 11, - "kind": "lvalue_ref", - "name": "self", - "ref": self., - }, - { - "id": 12, - "kind": "lvalue_ref", - "name": "a", - "ref": a, - }, - ], - "ref": self.a = a;, - }, - ], + "attributes": [], + "id": 7, + "kind": "def_native_function", + "name": "sample", + "nativeName": "hello_world", + "origin": "user", + "ref": @name(hello_world) +native sample(a: Int): Int;, + "return": { + "id": 4, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, }, }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "sample", + "origin": "user", + "returns": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + "self": null, + }, +} +`; + +exports[`resolveDescriptors should resolve descriptors for item-native-mutating-method 1`] = ` +{ + "BaseTrait": { + "ast": { + "attributes": [], + "declarations": [], + "id": 3, + "kind": "def_trait", + "name": "BaseTrait", + "origin": "user", + "ref": trait BaseTrait { + +}, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, "interfaces": [], - "kind": "contract", - "name": "Main", + "kind": "trait", + "name": "BaseTrait", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 3, - "kind": "def_trait", - "name": "BaseTrait", - "origin": "user", - "ref": trait BaseTrait { - -}, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "BaseTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - ], - "uid": 51099, + "traits": [], + "uid": 1020, + }, + "Bool": { + "ast": { + "id": 2, + "kind": "primitive", + "name": "Bool", + "origin": "user", + "ref": primitive Bool;, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive", + "name": "Bool", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 33424, }, - "Point": { + "Int": { "ast": { - "fields": [ - { - "as": null, - "id": 5, - "init": null, - "kind": "def_field", - "name": "p", - "ref": p: Int, - "type": { - "id": 4, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], - "id": 6, - "kind": "def_struct", - "message": false, - "name": "Point", + "id": 1, + "kind": "primitive", + "name": "Int", "origin": "user", - "prefix": null, - "ref": struct Point { - p: Int; -}, + "ref": primitive Int;, }, "constants": [], "dependsOn": [], - "fields": [ - { - "abi": { - "name": "p", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, + "fields": [], + "functions": Map { + "inc" => { + "args": [], "ast": { - "as": null, - "id": 5, - "init": null, - "kind": "def_field", - "name": "p", - "ref": p: Int, - "type": { + "args": [ + { + "id": 6, + "kind": "def_argument", + "name": "self", + "ref": self: Int, + "type": { + "id": 5, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + "attributes": [ + { + "ref": mutates, + "type": "mutates", + }, + { + "ref": extends, + "type": "extends", + }, + ], + "id": 7, + "kind": "def_native_function", + "name": "inc", + "nativeName": "inc", + "origin": "user", + "ref": @name(inc) +mutates extends native inc(self: Int): Int;, + "return": { "id": 4, "kind": "type_ref_simple", "name": "Int", @@ -2331,121 +2803,391 @@ exports[`resolveDescriptors should resolve descriptors for case-7 1`] = ` "ref": Int, }, }, - "default": undefined, - "index": 0, - "name": "p", - "ref": p: Int, - "type": { + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": true, + "isOverrides": false, + "isVirtual": false, + "name": "inc", + "origin": "user", + "returns": { "kind": "ref", "name": "Int", "optional": false, }, + "self": "Int", }, - ], - "functions": Map {}, + }, "header": null, "init": null, "interfaces": [], - "kind": "struct", - "name": "Point", + "kind": "primitive", + "name": "Int", "origin": "user", "partialFieldCount": 0, "receivers": [], - "signature": "Point{p:int257}", - "tlb": "_ p:int257 = Point", + "signature": null, + "tlb": null, "traits": [], - "uid": 35778, + "uid": 38154, }, } `; -exports[`resolveDescriptors should resolve descriptors for case-7 2`] = `{}`; +exports[`resolveDescriptors should resolve descriptors for item-native-mutating-method 2`] = `{}`; + +exports[`resolveDescriptors should resolve descriptors for scope-loops 1`] = `{}`; -exports[`resolveDescriptors should resolve descriptors for case-8 1`] = ` +exports[`resolveDescriptors should resolve descriptors for scope-loops 2`] = ` { - "A": { + "scopeIf": { + "args": [], "ast": { - "fields": [ + "args": [], + "attributes": [], + "id": 36, + "kind": "def_function", + "name": "scopeIf", + "origin": "user", + "ref": fun scopeIf() { + if (true) { + let a: Int = 0; + } + let a: String = "abc"; +}, + "return": null, + "statements": [ + { + "elseif": null, + "expression": { + "id": 28, + "kind": "boolean", + "ref": true, + "value": true, + }, + "falseStatements": null, + "id": 32, + "kind": "statement_condition", + "ref": if (true) { + let a: Int = 0; + }, + "trueStatements": [ + { + "expression": { + "id": 30, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 31, + "kind": "statement_let", + "name": "a", + "ref": let a: Int = 0;, + "type": { + "id": 29, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + }, + { + "expression": { + "id": 34, + "kind": "string", + "ref": "abc", + "value": "abc", + }, + "id": 35, + "kind": "statement_let", + "name": "a", + "ref": let a: String = "abc";, + "type": { + "id": 33, + "kind": "type_ref_simple", + "name": "String", + "optional": false, + "ref": String, + }, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "scopeIf", + "origin": "user", + "returns": { + "kind": "void", + }, + "self": null, + }, + "scopeRepeat": { + "args": [], + "ast": { + "args": [], + "attributes": [], + "id": 18, + "kind": "def_function", + "name": "scopeRepeat", + "origin": "user", + "ref": fun scopeRepeat() { + repeat (1) { + let a: Int = 0; + } + let a: String = "abc"; +}, + "return": null, + "statements": [ + { + "id": 14, + "iterations": { + "id": 10, + "kind": "number", + "ref": 1, + "value": 1n, + }, + "kind": "statement_repeat", + "ref": repeat (1) { + let a: Int = 0; + }, + "statements": [ + { + "expression": { + "id": 12, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 13, + "kind": "statement_let", + "name": "a", + "ref": let a: Int = 0;, + "type": { + "id": 11, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + }, + { + "expression": { + "id": 16, + "kind": "string", + "ref": "abc", + "value": "abc", + }, + "id": 17, + "kind": "statement_let", + "name": "a", + "ref": let a: String = "abc";, + "type": { + "id": 15, + "kind": "type_ref_simple", + "name": "String", + "optional": false, + "ref": String, + }, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "scopeRepeat", + "origin": "user", + "returns": { + "kind": "void", + }, + "self": null, + }, + "scopeUntil": { + "args": [], + "ast": { + "args": [], + "attributes": [], + "id": 9, + "kind": "def_function", + "name": "scopeUntil", + "origin": "user", + "ref": fun scopeUntil() { + do { + let a: Int = 0; + } until (true); + let a: String = "abc"; +}, + "return": null, + "statements": [ { - "as": "uint32", + "condition": { + "id": 1, + "kind": "boolean", + "ref": true, + "value": true, + }, "id": 5, - "init": null, - "kind": "def_field", + "kind": "statement_until", + "ref": do { + let a: Int = 0; + } until (true);, + "statements": [ + { + "expression": { + "id": 3, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 4, + "kind": "statement_let", + "name": "a", + "ref": let a: Int = 0;, + "type": { + "id": 2, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], + }, + { + "expression": { + "id": 7, + "kind": "string", + "ref": "abc", + "value": "abc", + }, + "id": 8, + "kind": "statement_let", "name": "a", - "ref": a: Int as uint32, + "ref": let a: String = "abc";, "type": { - "id": 4, + "id": 6, "kind": "type_ref_simple", - "name": "Int", + "name": "String", "optional": false, - "ref": Int, + "ref": String, }, }, ], - "id": 6, - "kind": "def_struct", - "message": true, - "name": "A", + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "scopeUntil", + "origin": "user", + "returns": { + "kind": "void", + }, + "self": null, + }, + "scopeWhile": { + "args": [], + "ast": { + "args": [], + "attributes": [], + "id": 27, + "kind": "def_function", + "name": "scopeWhile", "origin": "user", - "prefix": null, - "ref": message A { - a: Int as uint32; + "ref": fun scopeWhile() { + while (true) { + let a: Int = 0; + } + let a: String = "abc"; }, - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "a", - "type": { - "format": 32, - "kind": "simple", - "optional": false, - "type": "uint", + "return": null, + "statements": [ + { + "condition": { + "id": 19, + "kind": "boolean", + "ref": true, + "value": true, }, + "id": 23, + "kind": "statement_while", + "ref": while (true) { + let a: Int = 0; + }, + "statements": [ + { + "expression": { + "id": 21, + "kind": "number", + "ref": 0, + "value": 0n, + }, + "id": 22, + "kind": "statement_let", + "name": "a", + "ref": let a: Int = 0;, + "type": { + "id": 20, + "kind": "type_ref_simple", + "name": "Int", + "optional": false, + "ref": Int, + }, + }, + ], }, - "as": "uint32", - "ast": { - "as": "uint32", - "id": 5, - "init": null, - "kind": "def_field", + { + "expression": { + "id": 25, + "kind": "string", + "ref": "abc", + "value": "abc", + }, + "id": 26, + "kind": "statement_let", "name": "a", - "ref": a: Int as uint32, + "ref": let a: String = "abc";, "type": { - "id": 4, + "id": 24, "kind": "type_ref_simple", - "name": "Int", + "name": "String", "optional": false, - "ref": Int, + "ref": String, }, }, - "default": undefined, - "index": 0, - "name": "a", - "ref": a: Int as uint32, - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": 3746466057, - "init": null, - "interfaces": [], - "kind": "struct", - "name": "A", + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverrides": false, + "isVirtual": false, + "name": "scopeWhile", "origin": "user", - "partialFieldCount": 1, - "receivers": [], - "signature": "A{a:uint32}", - "tlb": "a#df4e8909 a:uint32 = A", - "traits": [], - "uid": 22757, + "returns": { + "kind": "void", + }, + "self": null, }, +} +`; + +exports[`resolveDescriptors should resolve descriptors for struct-nested 1`] = ` +{ "BaseTrait": { "ast": { "attributes": [], @@ -2476,38 +3218,13 @@ exports[`resolveDescriptors should resolve descriptors for case-8 1`] = ` "traits": [], "uid": 1020, }, - "Int": { - "ast": { - "id": 1, - "kind": "primitive", - "name": "Int", - "origin": "user", - "ref": primitive Int;, - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive", - "name": "Int", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 38154, - }, - "Slice": { + "Bool": { "ast": { "id": 2, "kind": "primitive", - "name": "Slice", + "name": "Bool", "origin": "user", - "ref": primitive Slice;, + "ref": primitive Bool;, }, "constants": [], "dependsOn": [], @@ -2517,227 +3234,50 @@ exports[`resolveDescriptors should resolve descriptors for case-8 1`] = ` "init": null, "interfaces": [], "kind": "primitive", - "name": "Slice", + "name": "Bool", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, "traits": [], - "uid": 35456, - }, - "Test": { - "ast": { - "attributes": [], - "declarations": [ - { - "args": [], - "id": 7, - "kind": "def_init_function", - "ref": init() {}, - "statements": [], - }, - { - "id": 10, - "kind": "def_receive", - "ref": receive(src: A) { - - }, - "selector": { - "arg": { - "id": 9, - "kind": "def_argument", - "name": "src", - "ref": src: A, - "type": { - "id": 8, - "kind": "type_ref_simple", - "name": "A", - "optional": false, - "ref": A, - }, - }, - "kind": "internal-simple", - }, - "statements": [], - }, - { - "id": 13, - "kind": "def_receive", - "ref": bounced(src: Slice) { - + "uid": 33424, }, - "selector": { - "arg": { - "id": 12, - "kind": "def_argument", - "name": "src", - "ref": src: Slice, - "type": { - "id": 11, - "kind": "type_ref_simple", - "name": "Slice", - "optional": false, - "ref": Slice, - }, - }, - "kind": "bounce", - }, - "statements": [], - }, - ], - "id": 14, - "kind": "def_contract", - "name": "Test", - "origin": "user", - "ref": contract Test { - init() {} - receive(src: A) { - - } - - bounced(src: Slice) { - - } -}, - "traits": [], + "Int": { + "ast": { + "id": 1, + "kind": "primitive", + "name": "Int", + "origin": "user", + "ref": primitive Int;, }, "constants": [], "dependsOn": [], "fields": [], "functions": Map {}, "header": null, - "init": { - "args": [], - "ast": { - "args": [], - "id": 7, - "kind": "def_init_function", - "ref": init() {}, - "statements": [], - }, - }, + "init": null, "interfaces": [], - "kind": "contract", - "name": "Test", + "kind": "primitive", + "name": "Int", "origin": "user", "partialFieldCount": 0, - "receivers": [ - { - "ast": { - "id": 10, - "kind": "def_receive", - "ref": receive(src: A) { - - }, - "selector": { - "arg": { - "id": 9, - "kind": "def_argument", - "name": "src", - "ref": src: A, - "type": { - "id": 8, - "kind": "type_ref_simple", - "name": "A", - "optional": false, - "ref": A, - }, - }, - "kind": "internal-simple", - }, - "statements": [], - }, - "selector": { - "kind": "internal-binary", - "name": "src", - "type": "A", - }, - }, - { - "ast": { - "id": 13, - "kind": "def_receive", - "ref": bounced(src: Slice) { - - }, - "selector": { - "arg": { - "id": 12, - "kind": "def_argument", - "name": "src", - "ref": src: Slice, - "type": { - "id": 11, - "kind": "type_ref_simple", - "name": "Slice", - "optional": false, - "ref": Slice, - }, - }, - "kind": "bounce", - }, - "statements": [], - }, - "selector": { - "kind": "bounce-fallback", - "name": "src", - }, - }, - ], + "receivers": [], "signature": null, "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 3, - "kind": "def_trait", - "name": "BaseTrait", - "origin": "user", - "ref": trait BaseTrait { - -}, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "BaseTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - ], - "uid": 44104, + "traits": [], + "uid": 38154, }, -} -`; - -exports[`resolveDescriptors should resolve descriptors for case-8 2`] = `{}`; - -exports[`resolveDescriptors should resolve descriptors for case-9 1`] = ` -{ - "A": { + "Struct1": { "ast": { "fields": [ { - "as": "uint32", + "as": null, "id": 5, "init": null, "kind": "def_field", "name": "a", - "ref": a: Int as uint32, + "ref": a: Int, "type": { "id": 4, "kind": "type_ref_simple", @@ -2761,32 +3301,16 @@ exports[`resolveDescriptors should resolve descriptors for case-9 1`] = ` "ref": Bool, }, }, - { - "as": "uint256", - "id": 9, - "init": null, - "kind": "def_field", - "name": "c", - "ref": c: Int as uint256, - "type": { - "id": 8, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, ], - "id": 10, + "id": 8, "kind": "def_struct", - "message": true, - "name": "A", + "message": false, + "name": "Struct1", "origin": "user", "prefix": null, - "ref": message A { - a: Int as uint32; - b: Bool; - c: Int as uint256; + "ref": struct Struct1 { + a: Int; + b: Bool; }, }, "constants": [], @@ -2796,20 +3320,20 @@ exports[`resolveDescriptors should resolve descriptors for case-9 1`] = ` "abi": { "name": "a", "type": { - "format": 32, + "format": 257, "kind": "simple", "optional": false, - "type": "uint", + "type": "int", }, }, - "as": "uint32", + "as": null, "ast": { - "as": "uint32", + "as": null, "id": 5, "init": null, "kind": "def_field", "name": "a", - "ref": a: Int as uint32, + "ref": a: Int, "type": { "id": 4, "kind": "type_ref_simple", @@ -2821,7 +3345,7 @@ exports[`resolveDescriptors should resolve descriptors for case-9 1`] = ` "default": undefined, "index": 0, "name": "a", - "ref": a: Int as uint32, + "ref": a: Int, "type": { "kind": "ref", "name": "Int", @@ -2863,57 +3387,110 @@ exports[`resolveDescriptors should resolve descriptors for case-9 1`] = ` "optional": false, }, }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "struct", + "name": "Struct1", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": "Struct1{a:int257,b:bool}", + "tlb": "_ a:int257 b:bool = Struct1", + "traits": [], + "uid": 63177, + }, + "Struct2": { + "ast": { + "fields": [ + { + "as": null, + "id": 10, + "init": null, + "kind": "def_field", + "name": "a", + "ref": a: Struct1, + "type": { + "id": 9, + "kind": "type_ref_simple", + "name": "Struct1", + "optional": false, + "ref": Struct1, + }, + }, + ], + "id": 11, + "kind": "def_struct", + "message": false, + "name": "Struct2", + "origin": "user", + "prefix": null, + "ref": struct Struct2 { + a: Struct1; +}, + }, + "constants": [], + "dependsOn": [], + "fields": [ { "abi": { - "name": "c", + "name": "a", "type": { - "format": 256, "kind": "simple", "optional": false, - "type": "uint", + "type": "Struct1", }, }, - "as": "uint256", + "as": null, "ast": { - "as": "uint256", - "id": 9, + "as": null, + "id": 10, "init": null, "kind": "def_field", - "name": "c", - "ref": c: Int as uint256, + "name": "a", + "ref": a: Struct1, "type": { - "id": 8, + "id": 9, "kind": "type_ref_simple", - "name": "Int", + "name": "Struct1", "optional": false, - "ref": Int, + "ref": Struct1, }, }, "default": undefined, - "index": 2, - "name": "c", - "ref": c: Int as uint256, + "index": 0, + "name": "a", + "ref": a: Struct1, "type": { "kind": "ref", - "name": "Int", + "name": "Struct1", "optional": false, }, }, ], "functions": Map {}, - "header": 2219696518, + "header": null, "init": null, "interfaces": [], "kind": "struct", - "name": "A", + "name": "Struct2", "origin": "user", - "partialFieldCount": 2, + "partialFieldCount": 0, "receivers": [], - "signature": "A{a:uint32,b:bool,c:uint256}", - "tlb": "a#844de186 a:uint32 b:bool c:uint256 = A", + "signature": "Struct2{a:Struct1{a:int257,b:bool}}", + "tlb": "_ a:Struct1{a:int257,b:bool} = Struct2", "traits": [], - "uid": 22757, + "uid": 50858, }, +} +`; + +exports[`resolveDescriptors should resolve descriptors for struct-nested 2`] = `{}`; + +exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` +{ "BaseTrait": { "ast": { "attributes": [], @@ -2994,254 +3571,7 @@ exports[`resolveDescriptors should resolve descriptors for case-9 1`] = ` "traits": [], "uid": 38154, }, - "Test": { - "ast": { - "attributes": [], - "declarations": [ - { - "args": [], - "id": 11, - "kind": "def_init_function", - "ref": init() {}, - "statements": [], - }, - { - "id": 14, - "kind": "def_receive", - "ref": receive(src: A) { - - }, - "selector": { - "arg": { - "id": 13, - "kind": "def_argument", - "name": "src", - "ref": src: A, - "type": { - "id": 12, - "kind": "type_ref_simple", - "name": "A", - "optional": false, - "ref": A, - }, - }, - "kind": "internal-simple", - }, - "statements": [], - }, - { - "id": 21, - "kind": "def_receive", - "ref": bounced(src: bounced) { - let x: Int = src.c; - }, - "selector": { - "arg": { - "id": 16, - "kind": "def_argument", - "name": "src", - "ref": src: bounced, - "type": { - "id": 15, - "kind": "type_ref_bounced", - "name": "A", - "ref": bounced, - }, - }, - "kind": "bounce", - }, - "statements": [ - { - "expression": { - "id": 19, - "kind": "op_field", - "name": "c", - "ref": src.c, - "src": { - "id": 18, - "kind": "id", - "ref": src, - "value": "src", - }, - }, - "id": 20, - "kind": "statement_let", - "name": "x", - "ref": let x: Int = src.c;, - "type": { - "id": 17, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], - }, - ], - "id": 22, - "kind": "def_contract", - "name": "Test", - "origin": "user", - "ref": contract Test { - init() {} - receive(src: A) { - - } - - bounced(src: bounced) { - let x: Int = src.c; - } -}, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": { - "args": [], - "ast": { - "args": [], - "id": 11, - "kind": "def_init_function", - "ref": init() {}, - "statements": [], - }, - }, - "interfaces": [], - "kind": "contract", - "name": "Test", - "origin": "user", - "partialFieldCount": 0, - "receivers": [ - { - "ast": { - "id": 14, - "kind": "def_receive", - "ref": receive(src: A) { - - }, - "selector": { - "arg": { - "id": 13, - "kind": "def_argument", - "name": "src", - "ref": src: A, - "type": { - "id": 12, - "kind": "type_ref_simple", - "name": "A", - "optional": false, - "ref": A, - }, - }, - "kind": "internal-simple", - }, - "statements": [], - }, - "selector": { - "kind": "internal-binary", - "name": "src", - "type": "A", - }, - }, - { - "ast": { - "id": 21, - "kind": "def_receive", - "ref": bounced(src: bounced) { - let x: Int = src.c; - }, - "selector": { - "arg": { - "id": 16, - "kind": "def_argument", - "name": "src", - "ref": src: bounced, - "type": { - "id": 15, - "kind": "type_ref_bounced", - "name": "A", - "ref": bounced, - }, - }, - "kind": "bounce", - }, - "statements": [ - { - "expression": { - "id": 19, - "kind": "op_field", - "name": "c", - "ref": src.c, - "src": { - "id": 18, - "kind": "id", - "ref": src, - "value": "src", - }, - }, - "id": 20, - "kind": "statement_let", - "name": "x", - "ref": let x: Int = src.c;, - "type": { - "id": 17, - "kind": "type_ref_simple", - "name": "Int", - "optional": false, - "ref": Int, - }, - }, - ], - }, - "selector": { - "bounced": true, - "kind": "bounce-binary", - "name": "src", - "type": "A", - }, - }, - ], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 3, - "kind": "def_trait", - "name": "BaseTrait", - "origin": "user", - "ref": trait BaseTrait { - -}, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "BaseTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - ], - "uid": 44104, - }, } `; -exports[`resolveDescriptors should resolve descriptors for case-9 2`] = `{}`; +exports[`resolveDescriptors should resolve descriptors for trait-base 2`] = `{}`; diff --git a/src/types/__snapshots__/resolveStatements.spec.ts.snap b/src/types/__snapshots__/resolveStatements.spec.ts.snap index 0207f1fff..7b1483f80 100644 --- a/src/types/__snapshots__/resolveStatements.spec.ts.snap +++ b/src/types/__snapshots__/resolveStatements.spec.ts.snap @@ -1,96 +1,96 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`resolveStatements should fail statements for case-0 1`] = ` -":9:5: Type mismatch: "Int" is not assignable to "Bool" -Line 9, col 5: - 8 | fun isZero(x: Int): Bool { -> 9 | return x; - ^~~~~~~~~ - 10 | } +exports[`resolveStatements should fail statements for bounced-type-is-smaller 1`] = ` +":23:18: Type bounced<"A"> does not have a field named "c" +Line 23, col 18: + 22 | let y: Bool = src.b; +> 23 | let z: Int = src.c; + ^~~~~ + 24 | } " `; -exports[`resolveStatements should fail statements for case-1 1`] = ` -":9:5: Type mismatch: "Bool" is not assignable to "Int" -Line 9, col 5: - 8 | fun isZero(x: Int): Bool { -> 9 | repeat(true) { - ^~~~~~~~~~~~~~ - 10 | x = x + 1; +exports[`resolveStatements should fail statements for contract-initof-wrong-arg 1`] = ` +":26:25: Invalid type "String" for argument "owner" +Line 26, col 25: + 25 | get fun newInit(): StateInit { +> 26 | return initOf A("hello"); + ^~~~~~~ + 27 | } " `; -exports[`resolveStatements should fail statements for case-2 1`] = ` -":9:5: Type mismatch: "Int" is not assignable to "Bool" -Line 9, col 5: - 8 | fun isZero(x: Int): Bool { -> 9 | while(x) { - ^~~~~~~~~~ - 10 | x = x + 1; +exports[`resolveStatements should fail statements for expr-bitwise-not-bool 1`] = ` +":5:12: Invalid type "Bool" for unary operator "~" +Line 5, col 12: + 4 | fun test(a: Bool): Int { +> 5 | return ~a; + ^~ + 6 | } " `; -exports[`resolveStatements should fail statements for case-3 1`] = ` -":9:5: Type mismatch: "Int" is not assignable to "Bool" -Line 9, col 5: - 8 | fun isZero(x: Int): Bool { -> 9 | do { - ^~~~ - 10 | x = x + 1; +exports[`resolveStatements should fail statements for expr-cmp-int-bool 1`] = ` +":5:12: Incompatible types "Int" and "Bool" for binary operator "==" +Line 5, col 12: + 4 | fun foo(x: Int): Bool { +> 5 | return x == true; + ^~~~~~~~~ + 6 | } " `; -exports[`resolveStatements should fail statements for case-4 1`] = ` -":9:5: Type mismatch: "Int" is not assignable to "Bool" -Line 9, col 5: - 8 | fun isZero(x: Int): Bool { -> 9 | if (x) { - ^~~~~~~~ - 10 | x = x + 1; +exports[`resolveStatements should fail statements for expr-conditional-branch-mismatch 1`] = ` +":5:43: Non-matching types "Bool" and "Int" for ternary branches +Line 5, col 43: + 4 | fun sample(): Int { +> 5 | return (true ? true : false) ? true : 3; + ^ + 6 | } " `; -exports[`resolveStatements should fail statements for case-5 1`] = ` -":9:5: Type mismatch: "String" is not assignable to "Int" -Line 9, col 5: - 8 | fun isZero(x: Int): Bool { -> 9 | x = "hello world"; - ^~~~~~~~~~~~~~~~~~ - 10 | return true; +exports[`resolveStatements should fail statements for expr-conditional-branch-mismatch-nested1 1`] = ` +":5:24: Non-matching types "Int" and "Bool" for ternary branches +Line 5, col 24: + 4 | fun sample(): Int { +> 5 | return (true ? 1 : false) ? 2 : 3; + ^~~~~ + 6 | } " `; -exports[`resolveStatements should fail statements for case-6 1`] = ` -":13:12: Function "f1" expects 2 arguments, got 1 -Line 13, col 12: - 12 | fun f2(a: Int): Int { -> 13 | return f1(a); - ^~~~~ - 14 | } +exports[`resolveStatements should fail statements for expr-conditional-branch-mismatch-nested2 1`] = ` +":5:39: Non-matching types "Bool" and "Int" for ternary branches +Line 5, col 39: + 4 | fun sample(): Int { +> 5 | return true ? 1 : (false ? true : 2); + ^ + 6 | } " `; -exports[`resolveStatements should fail statements for case-7 1`] = ` -":20:16: Function "f1" expects 2 arguments, got 1 -Line 20, col 16: - 19 | fun f2(a: Int): Int { -> 20 | return self.f1(a); - ^~~~~~~~~~ - 21 | } +exports[`resolveStatements should fail statements for expr-conditional-non-optional-result-expected 1`] = ` +":6:5: Type mismatch: "Int?" is not assignable to "Int" +Line 6, col 5: + 5 | let cond: Bool = true; +> 6 | return cond ? 42 : x; + ^~~~~~~~~~~~~~~~~~~~~ + 7 | } " `; -exports[`resolveStatements should fail statements for case-8 1`] = ` -":13:18: Invalid type "Bool" for argument "b" -Line 13, col 18: - 12 | fun f2(a: Int): Int { -> 13 | return f1(a, true); - ^~~~ - 14 | } +exports[`resolveStatements should fail statements for expr-conditional-result-mismatch 1`] = ` +":5:5: Type mismatch: "Bool" is not assignable to "Int" +Line 5, col 5: + 4 | fun sample(): Int { +> 5 | return (true ? true : false) ? true : false; + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 6 | } " `; -exports[`resolveStatements should fail statements for case-9 1`] = ` +exports[`resolveStatements should fail statements for expr-internal-fun-call-bool-param.tact 1`] = ` ":20:27: Invalid type "Bool" for argument "b" Line 20, col 27: 19 | fun f2(a: Int): Int { @@ -100,27 +100,27 @@ Line 20, col 27: " `; -exports[`resolveStatements should fail statements for case-10 1`] = ` -":10:5: Type mismatch: "Int" is not assignable to "Bool" -Line 10, col 5: - 9 | let a: Int = 0; -> 10 | let b: Bool = 0; - ^~~~~~~~~~~~~~~~ - 11 | } +exports[`resolveStatements should fail statements for expr-map-del-method-is-non-void 1`] = ` +":6:5: Type mismatch: "Bool" is not assignable to "" +Line 6, col 5: + 5 | m.set(1, 2); +> 6 | return m.del(1); + ^~~~~~~~~~~~~~~~ + 7 | } " `; -exports[`resolveStatements should fail statements for case-11 1`] = ` -":17:9: Invalid type "Bool" for fields "b" with type "Int" in type "SomeStruct" -Line 17, col 9: - 16 | a: 1, -> 17 | b: false // Invalid type - ^~~~~~~~ - 18 | }; +exports[`resolveStatements should fail statements for expr-module-fun-call-bool-param 1`] = ` +":13:18: Invalid type "Bool" for argument "b" +Line 13, col 18: + 12 | fun f2(a: Int): Int { +> 13 | return f1(a, true); + ^~~~ + 14 | } " `; -exports[`resolveStatements should fail statements for case-12 1`] = ` +exports[`resolveStatements should fail statements for expr-struct-duplicate-field 1`] = ` ":17:9: Duplicate fields "a" Line 17, col 9: 16 | a: 1, @@ -130,7 +130,17 @@ Line 17, col 9: " `; -exports[`resolveStatements should fail statements for case-13 1`] = ` +exports[`resolveStatements should fail statements for expr-struct-impossible-field-punning 1`] = ` +":14:26: Unknown fields "b" in type "A" +Line 14, col 26: + 13 | fun function() { +> 14 | let D: A = A { x: a, b }; + ^ + 15 | } +" +`; + +exports[`resolveStatements should fail statements for expr-struct-missing-field 1`] = ` ":16:25: Missing fields "c" in type "SomeStruct" Line 16, col 25: 15 | fun main() { @@ -140,37 +150,47 @@ Line 16, col 25: " `; -exports[`resolveStatements should fail statements for case-14 1`] = ` -":26:25: Invalid type "String" for argument "owner" -Line 26, col 25: - 25 | get fun newInit(): StateInit { -> 26 | return initOf A("hello"); - ^~~~~~~ - 27 | } +exports[`resolveStatements should fail statements for expr-struct-wrong-field-type 1`] = ` +":17:9: Invalid type "Bool" for fields "b" with type "Int" in type "SomeStruct" +Line 17, col 9: + 16 | a: 1, +> 17 | b: false // Invalid type + ^~~~~~~~ + 18 | }; " `; -exports[`resolveStatements should fail statements for case-15 1`] = ` -":10:5: Field "value" is not set -Line 10, col 5: - 9 | value: Int; -> 10 | init() { - ^~~~~~~~ - 11 | +exports[`resolveStatements should fail statements for expr-var-int-bool 1`] = ` +":9:5: Type mismatch: "Int" is not assignable to "Bool" +Line 9, col 5: + 8 | fun isZero(x: Int): Bool { +> 9 | return x; + ^~~~~~~~~ + 10 | } " `; -exports[`resolveStatements should fail statements for case-16 1`] = ` -":10:5: Field "value" is not set -Line 10, col 5: - 9 | value: Int; -> 10 | init(arg: Bool) { - ^~~~~~~~~~~~~~~~~ - 11 | if (arg) { +exports[`resolveStatements should fail statements for expr-wrong-arity-internal-fun 1`] = ` +":20:16: Function "f1" expects 2 arguments, got 1 +Line 20, col 16: + 19 | fun f2(a: Int): Int { +> 20 | return self.f1(a); + ^~~~~~~~~~ + 21 | } " `; -exports[`resolveStatements should fail statements for case-17 1`] = ` +exports[`resolveStatements should fail statements for expr-wrong-arity-module-fun 1`] = ` +":13:12: Function "f1" expects 2 arguments, got 1 +Line 13, col 12: + 12 | fun f2(a: Int): Int { +> 13 | return f1(a); + ^~~~~ + 14 | } +" +`; + +exports[`resolveStatements should fail statements for init-vars-analysis-if 1`] = ` ":10:5: Field "value" is not set Line 10, col 5: 9 | value: Int; @@ -180,27 +200,37 @@ Line 10, col 5: " `; -exports[`resolveStatements should fail statements for case-18 1`] = ` +exports[`resolveStatements should fail statements for init-vars-analysis-implicit-init 1`] = ` +":4:1: Field "test_field" is not set +Line 4, col 1: + 3 | +> 4 | contract MyContract { + ^~~~~~~~~~~~~~~~~~~~~ + 5 | counter: Int = 0; +" +`; + +exports[`resolveStatements should fail statements for init-vars-analysis-missing-storage-var 1`] = ` ":10:5: Field "value" is not set Line 10, col 5: 9 | value: Int; -> 10 | init(arg: Bool) { - ^~~~~~~~~~~~~~~~~ - 11 | if (arg) { +> 10 | init() { + ^~~~~~~~ + 11 | " `; -exports[`resolveStatements should fail statements for case-19 1`] = ` -":12:22: Field "value2" is not initialized -Line 12, col 22: - 11 | init(arg: Bool) { -> 12 | self.value = self.value2 + 1; - ^~~~~~~~~~~ - 13 | self.value2 = 10; +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-override-fun-call 1`] = ` +":15:9: Cannot access self before init +Line 15, col 9: + 14 | init(arg: Bool) { +> 15 | self.execute(); + ^~~~~~~~~~~~~~ + 16 | self.value = 1; " `; -exports[`resolveStatements should fail statements for case-20 1`] = ` +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-struct1 1`] = ` ":17:22: Field "value2" is not initialized Line 17, col 22: 16 | init(arg: Bool) { @@ -210,7 +240,7 @@ Line 17, col 22: " `; -exports[`resolveStatements should fail statements for case-21 1`] = ` +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-struct2 1`] = ` ":17:35: Field "value" is not initialized Line 17, col 35: 16 | init(arg: Bool) { @@ -220,7 +250,17 @@ Line 17, col 35: " `; -exports[`resolveStatements should fail statements for case-22 1`] = ` +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-var 1`] = ` +":12:22: Field "value2" is not initialized +Line 12, col 22: + 11 | init(arg: Bool) { +> 12 | self.value = self.value2 + 1; + ^~~~~~~~~~~ + 13 | self.value2 = 10; +" +`; + +exports[`resolveStatements should fail statements for init-vars-analysis-used-uninit-storage-var-fun-call 1`] = ` ":16:9: Cannot access self before init Line 16, col 9: 15 | init(arg: Bool) { @@ -230,369 +270,318 @@ Line 16, col 9: " `; -exports[`resolveStatements should fail statements for case-23 1`] = ` -":15:9: Cannot access self before init -Line 15, col 9: - 14 | init(arg: Bool) { -> 15 | self.update(); - ^~~~~~~~~~~~~ - 16 | self.value = 1; -" -`; - -exports[`resolveStatements should fail statements for case-24 1`] = ` -":23:18: Type bounced<"A"> does not have a field named "c" -Line 23, col 18: - 22 | let y: Bool = src.b; -> 23 | let z: Int = src.c; - ^~~~~ - 24 | } -" -`; - -exports[`resolveStatements should fail statements for case-25 1`] = ` -":5:12: Incompatible types "Int" and "Bool" for binary operator "==" -Line 5, col 12: - 4 | fun foo(x: Int): Bool { -> 5 | return x == true; - ^~~~~~~~~ - 6 | } -" -`; - -exports[`resolveStatements should fail statements for case-26 1`] = ` -":5:24: Non-matching types "Int" and "Bool" for ternary branches -Line 5, col 24: - 4 | fun sample(): Int { -> 5 | return (true ? 1 : false) ? 2 : 3; - ^~~~~ - 6 | } -" -`; - -exports[`resolveStatements should fail statements for case-27 1`] = ` -":5:43: Non-matching types "Bool" and "Int" for ternary branches -Line 5, col 43: - 4 | fun sample(): Int { -> 5 | return (true ? true : false) ? true : 3; - ^ - 6 | } +exports[`resolveStatements should fail statements for init-vars-analysis-with-if-else 1`] = ` +":10:5: Field "value" is not set +Line 10, col 5: + 9 | value: Int; +> 10 | init(arg: Bool) { + ^~~~~~~~~~~~~~~~~ + 11 | if (arg) { " `; -exports[`resolveStatements should fail statements for case-28 1`] = ` -":5:5: Type mismatch: "Bool" is not assignable to "Int" -Line 5, col 5: - 4 | fun sample(): Int { -> 5 | return (true ? true : false) ? true : false; - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6 | } +exports[`resolveStatements should fail statements for init-vars-analysis-with-if-elseif 1`] = ` +":10:5: Field "value" is not set +Line 10, col 5: + 9 | value: Int; +> 10 | init(arg: Bool) { + ^~~~~~~~~~~~~~~~~ + 11 | if (arg) { " `; -exports[`resolveStatements should fail statements for case-29 1`] = ` -":5:39: Non-matching types "Bool" and "Int" for ternary branches -Line 5, col 39: - 4 | fun sample(): Int { -> 5 | return true ? 1 : (false ? true : 2); - ^ - 6 | } +exports[`resolveStatements should fail statements for return-analysis-catch-if 1`] = ` +":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 4, col 1: + 3 | +> 4 | fun notAlwaysReachableReturn(b: Bool): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | try { " `; -exports[`resolveStatements should fail statements for case-30 1`] = ` -":7:9: Static function "toString" does not exist -Line 7, col 9: - 6 | init() { -> 7 | toString(); // non-existent function - ^~~~~~~~~~ - 8 | } +exports[`resolveStatements should fail statements for return-analysis-do-if 1`] = ` +":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 4, col 1: + 3 | +> 4 | fun notAlwaysReachableReturn(b: Bool): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | do { " `; -exports[`resolveStatements should fail statements for case-31 1`] = ` -":9:12: Unable to resolve id c -Line 9, col 12: - 8 | } -> 9 | return c; - ^ - 10 | } +exports[`resolveStatements should fail statements for return-analysis-if 1`] = ` +":6:5: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 6, col 5: + 5 | contract Foo { +> 6 | get fun notAlwaysReachableReturn(b: Bool): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 7 | if b { " `; -exports[`resolveStatements should fail statements for case-32 1`] = ` -":9:12: Unable to resolve id e -Line 9, col 12: - 8 | } -> 9 | return e; - ^ - 10 | } +exports[`resolveStatements should fail statements for return-analysis-non-void1 1`] = ` +":6:5: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 6, col 5: + 5 | contract Foo { +> 6 | get fun noReturn(): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~ + 7 | // ERROR: no return statement " `; -exports[`resolveStatements should fail statements for case-33 1`] = ` -":5:16: Unable to resolve id e -Line 5, col 16: - 4 | try { -> 5 | return e; - ^ - 6 | } catch (e) { +exports[`resolveStatements should fail statements for return-analysis-non-void2 1`] = ` +":6:5: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 6, col 5: + 5 | contract Foo { +> 6 | get fun noReturn(): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~ + 7 | let x: Int = 42; " `; -exports[`resolveStatements should fail statements for case-34 1`] = ` -":6:5: Variable already exists: "e" -Line 6, col 5: - 5 | let e: String = "qwe"; -> 6 | try { - ^~~~~ - 7 | return e; +exports[`resolveStatements should fail statements for return-analysis-repeat 1`] = ` +":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 4, col 1: + 3 | +> 4 | fun notAlwaysReachableReturn(n: Int): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | repeat (n) { " `; -exports[`resolveStatements should fail statements for case-35 1`] = ` -":8:9: Type mismatch: "Int" is not assignable to "String" -Line 8, col 9: - 7 | } catch (e) { -> 8 | return e; - ^~~~~~~~~ - 9 | } +exports[`resolveStatements should fail statements for return-analysis-separate-ifs 1`] = ` +":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 4, col 1: + 3 | +> 4 | fun notAlwaysReachableReturn(b: Bool): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | if (b) { " `; -exports[`resolveStatements should fail statements for case-36 1`] = ` -":14:26: Unknown fields "b" in type "A" -Line 14, col 26: - 13 | fun function() { -> 14 | let D: A = A { x: a, b }; - ^ - 15 | } +exports[`resolveStatements should fail statements for return-analysis-try 1`] = ` +":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 4, col 1: + 3 | +> 4 | fun notAlwaysReachableReturn(b: Bool): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | try { " `; -exports[`resolveStatements should fail statements for case-37 1`] = ` -":6:5: Type mismatch: "Bool" is not assignable to "" -Line 6, col 5: - 5 | m.set(1, 2); -> 6 | return m.del(1); - ^~~~~~~~~~~~~~~~ - 7 | } +exports[`resolveStatements should fail statements for return-analysis-while 1`] = ` +":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. +Line 4, col 1: + 3 | +> 4 | fun notAlwaysReachableReturn(b: Bool): Int { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | while (b) { " `; -exports[`resolveStatements should fail statements for case-38 1`] = ` -":6:5: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 6, col 5: - 5 | contract Foo { -> 6 | get fun noReturn(): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~ - 7 | // ERROR: no return statement +exports[`resolveStatements should fail statements for stmt-assgn-int-string 1`] = ` +":9:5: Type mismatch: "String" is not assignable to "Int" +Line 9, col 5: + 8 | fun isZero(x: Int): Bool { +> 9 | x = "hello world"; + ^~~~~~~~~~~~~~~~~~ + 10 | return true; " `; -exports[`resolveStatements should fail statements for case-39 1`] = ` -":6:5: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 6, col 5: - 5 | contract Foo { -> 6 | get fun noReturn(): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~ - 7 | let x: Int = 42; +exports[`resolveStatements should fail statements for stmt-augmented-assgn-bool 1`] = ` +":5:5: Type error: Augmented assignment is only allowed for Int type +Line 5, col 5: + 4 | let a: Bool = false; +> 5 | a %= true; + ^~~~~~~~~~ + 6 | return a; " `; - -exports[`resolveStatements should fail statements for case-40 1`] = ` -":6:5: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 6, col 5: - 5 | contract Foo { -> 6 | get fun notAlwaysReachableReturn(b: Bool): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 7 | if b { + +exports[`resolveStatements should fail statements for stmt-augmented-assgn-string 1`] = ` +":5:5: Type error: Augmented assignment is only allowed for Int type +Line 5, col 5: + 4 | let a: String = "foo"; +> 5 | a %= "bar"; + ^~~~~~~~~~~ + 6 | return a; " `; -exports[`resolveStatements should fail statements for case-41 1`] = ` -":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 4, col 1: - 3 | -> 4 | fun notAlwaysReachableReturn(b: Bool): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 | if (b) { +exports[`resolveStatements should fail statements for stmt-do-int 1`] = ` +":9:5: Type mismatch: "Int" is not assignable to "Bool" +Line 9, col 5: + 8 | fun isZero(x: Int): Bool { +> 9 | do { + ^~~~ + 10 | x = x + 1; " `; -exports[`resolveStatements should fail statements for case-42 1`] = ` -":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 4, col 1: - 3 | -> 4 | fun notAlwaysReachableReturn(b: Bool): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 | try { +exports[`resolveStatements should fail statements for stmt-if-int 1`] = ` +":9:5: Type mismatch: "Int" is not assignable to "Bool" +Line 9, col 5: + 8 | fun isZero(x: Int): Bool { +> 9 | if (x) { + ^~~~~~~~ + 10 | x = x + 1; " `; -exports[`resolveStatements should fail statements for case-43 1`] = ` -":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 4, col 1: - 3 | -> 4 | fun notAlwaysReachableReturn(b: Bool): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 | try { +exports[`resolveStatements should fail statements for stmt-let-wrong-rhs 1`] = ` +":10:5: Type mismatch: "Int" is not assignable to "Bool" +Line 10, col 5: + 9 | let a: Int = 0; +> 10 | let b: Bool = 0; + ^~~~~~~~~~~~~~~~ + 11 | } " `; -exports[`resolveStatements should fail statements for case-44 1`] = ` -":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 4, col 1: - 3 | -> 4 | fun notAlwaysReachableReturn(b: Bool): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 | while (b) { +exports[`resolveStatements should fail statements for stmt-repeat-bool 1`] = ` +":9:5: Type mismatch: "Bool" is not assignable to "Int" +Line 9, col 5: + 8 | fun isZero(x: Int): Bool { +> 9 | repeat(true) { + ^~~~~~~~~~~~~~ + 10 | x = x + 1; " `; -exports[`resolveStatements should fail statements for case-45 1`] = ` -":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 4, col 1: - 3 | -> 4 | fun notAlwaysReachableReturn(n: Int): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 | repeat (n) { +exports[`resolveStatements should fail statements for stmt-return-from-try-and-catch 1`] = ` +":8:9: Type mismatch: "Int" is not assignable to "String" +Line 8, col 9: + 7 | } catch (e) { +> 8 | return e; + ^~~~~~~~~ + 9 | } " `; -exports[`resolveStatements should fail statements for case-46 1`] = ` -":4:1: Function does not always return a result. Adding 'return' statement(s) should fix the issue. -Line 4, col 1: - 3 | -> 4 | fun notAlwaysReachableReturn(b: Bool): Int { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 | do { +exports[`resolveStatements should fail statements for stmt-while-int 1`] = ` +":9:5: Type mismatch: "Int" is not assignable to "Bool" +Line 9, col 5: + 8 | fun isZero(x: Int): Bool { +> 9 | while(x) { + ^~~~~~~~~~ + 10 | x = x + 1; " `; -exports[`resolveStatements should fail statements for case-47 1`] = ` -":5:5: Variable already exists: "k" -Line 5, col 5: - 4 | let m: map = emptyMap(); -> 5 | foreach (k, k in m) { - ^~~~~~~~~~~~~~~~~~~~~ - 6 | // something +exports[`resolveStatements should fail statements for var-scope-catch-param-does-not-shadow-outer-var 1`] = ` +":6:5: Variable already exists: "e" +Line 6, col 5: + 5 | let e: String = "qwe"; +> 6 | try { + ^~~~~ + 7 | return e; " `; -exports[`resolveStatements should fail statements for case-48 1`] = ` -":5:5: Variable already exists: "m" -Line 5, col 5: - 4 | let m: map = emptyMap(); -> 5 | foreach (k, m in m) { - ^~~~~~~~~~~~~~~~~~~~~ - 6 | // something +exports[`resolveStatements should fail statements for var-scope-catch-param-is-not-visible-in-try 1`] = ` +":5:16: Unable to resolve id e +Line 5, col 16: + 4 | try { +> 5 | return e; + ^ + 6 | } catch (e) { " `; -exports[`resolveStatements should fail statements for case-49 1`] = ` -":8:12: Unable to resolve id v +exports[`resolveStatements should fail statements for var-scope-foreach-internal-var-does-not-escape 1`] = ` +":8:12: Unable to resolve id x Line 8, col 12: 7 | } -> 8 | return v; +> 8 | return x; ^ 9 | } " `; -exports[`resolveStatements should fail statements for case-50 1`] = ` -":8:12: Unable to resolve id x +exports[`resolveStatements should fail statements for var-scope-foreach-val-does-not-escape 1`] = ` +":8:12: Unable to resolve id v Line 8, col 12: 7 | } -> 8 | return x; +> 8 | return v; ^ 9 | } " `; -exports[`resolveStatements should fail statements for case-51 1`] = ` -":5:5: Type error: Augmented assignment is only allowed for Int type +exports[`resolveStatements should fail statements for var-scope-foreach-val-shadows-key 1`] = ` +":5:5: Variable already exists: "k" Line 5, col 5: - 4 | let a: Bool = false; -> 5 | a %= true; - ^~~~~~~~~~ - 6 | return a; + 4 | let m: map = emptyMap(); +> 5 | foreach (k, k in m) { + ^~~~~~~~~~~~~~~~~~~~~ + 6 | // something " `; -exports[`resolveStatements should fail statements for case-52 1`] = ` -":5:5: Type error: Augmented assignment is only allowed for Int type +exports[`resolveStatements should fail statements for var-scope-foreach-val-shadows-map 1`] = ` +":5:5: Variable already exists: "m" Line 5, col 5: - 4 | let a: String = "foo"; -> 5 | a %= "bar"; - ^~~~~~~~~~~ - 6 | return a; + 4 | let m: map = emptyMap(); +> 5 | foreach (k, m in m) { + ^~~~~~~~~~~~~~~~~~~~~ + 6 | // something " `; -exports[`resolveStatements should fail statements for case-53 1`] = ` -":5:12: Invalid type "Bool" for unary operator "~" -Line 5, col 12: - 4 | fun test(a: Bool): Int { -> 5 | return ~a; - ^~ - 6 | } +exports[`resolveStatements should fail statements for var-scope-local-catch-param-does-not-escape 1`] = ` +":9:12: Unable to resolve id e +Line 9, col 12: + 8 | } +> 9 | return e; + ^ + 10 | } " `; -exports[`resolveStatements should fail statements for case-54 1`] = ` -":6:5: Type mismatch: "Int?" is not assignable to "Int" -Line 6, col 5: - 5 | let cond: Bool = true; -> 6 | return cond ? 42 : x; - ^~~~~~~~~~~~~~~~~~~~~ - 7 | } +exports[`resolveStatements should fail statements for var-scope-local-loop-var-does-not-escape 1`] = ` +":9:12: Unable to resolve id c +Line 9, col 12: + 8 | } +> 9 | return c; + ^ + 10 | } " `; -exports[`resolveStatements should resolve statements for case-0 1`] = ` -[ - [ - "x", - "Int", - ], - [ - "0", - "Int", - ], - [ - "x == 0", - "Bool", - ], -] +exports[`resolveStatements should fail statements for var-scope-no-toString-global-fun 1`] = ` +":7:9: Static function "toString" does not exist +Line 7, col 9: + 6 | init() { +> 7 | toString(); // non-existent function + ^~~~~~~~~~ + 8 | } +" `; -exports[`resolveStatements should resolve statements for case-1 1`] = ` +exports[`resolveStatements should resolve statements for contract-receiver-bounced 1`] = ` [ [ - "123", - "Int", - ], - [ - "10", - "Int", + "src", + "bounced", ], [ - "123 + 10", + "src.a", "Int", ], [ - "x", - "Int", + "src", + "bounced", ], [ - "123 + 10 == x", + "src.b", "Bool", ], ] `; -exports[`resolveStatements should resolve statements for case-2 1`] = ` +exports[`resolveStatements should resolve statements for expr-arith-bool-cmp 1`] = ` [ [ "123", @@ -649,133 +638,168 @@ exports[`resolveStatements should resolve statements for case-2 1`] = ` ] `; -exports[`resolveStatements should resolve statements for case-3 1`] = ` +exports[`resolveStatements should resolve statements for expr-cmp-arith 1`] = ` [ [ - "x", + "123", "Int", ], [ - "y", + "10", "Int", ], [ - "x + y", + "123 + 10", "Int", ], [ - "b", + "x", "Int", ], [ - "b", - "Int", + "123 + 10 == x", + "Bool", ], +] +`; + +exports[`resolveStatements should resolve statements for expr-cmp-literal 1`] = ` +[ [ - "1", + "x", "Int", ], [ - "b + 1", + "0", "Int", ], [ - "b", - "Int", + "x == 0", + "Bool", ], +] +`; + +exports[`resolveStatements should resolve statements for expr-conditional-with-subtyping 1`] = ` +[ [ - "0", + "true", + "Bool", + ], + [ + "cond", + "Bool", + ], + [ + "42", "Int", ], [ - "b > 0", + "x", + "Int?", + ], + [ + "cond ? 42 : x", + "Int?", + ], + [ + "true", "Bool", ], [ - "z", + "cond", "Bool", ], [ - "b > 0 || z", + "x", + "Int?", + ], + [ + "42", + "Int", + ], + [ + "cond ? x : 42", + "Int?", + ], + [ + "true", "Bool", ], -] -`; - -exports[`resolveStatements should resolve statements for case-4 1`] = ` -[ [ - "x", - "Int", + "cond", + "Bool", ], [ - "y", - "Int", + "null", + "", ], [ - "x + y", - "Int", + "m", + "map", ], [ - "b", - "Int", + "cond ? null : m", + "map", ], [ - "b", - "Int", + "true", + "Bool", ], [ - "1", - "Int", + "cond", + "Bool", ], [ - "b + 1", - "Int", + "m", + "map", ], [ - "b", - "Int", + "null", + "", ], [ - "0", - "Int", + "cond ? m : null", + "map", ], [ - "b > 0", + "true", "Bool", ], [ - "z", + "cond", "Bool", ], [ - "b > 0 || z", - "Bool", + "42", + "Int", ], [ - "w", - "Int?", + "Baz { b: 42 }", + "Baz", ], [ - "w!!", - "Int", + "Baz { b: 42 }.toCell()", + "Cell", ], [ - "0", - "Int", + "x", + "Cell?", ], [ - "w!! > 0", - "Bool", + "cond ? Baz { b: 42 }.toCell() : x", + "Cell?", ], [ - "b > 0 || z || (w!! > 0)", - "Bool", + "Bar { + a: cond ? Baz { b: 42 }.toCell() : x + }", + "Bar", ], ] `; -exports[`resolveStatements should resolve statements for case-5 1`] = ` +exports[`resolveStatements should resolve statements for expr-field-access-method-call 1`] = ` [ [ "p", @@ -824,72 +848,76 @@ exports[`resolveStatements should resolve statements for case-5 1`] = ` ] `; -exports[`resolveStatements should resolve statements for case-6 1`] = ` +exports[`resolveStatements should resolve statements for expr-maps-del-method 1`] = ` [ [ - "10", - "Int", + "emptyMap()", + "", ], [ - "a", - "Int", + "m", + "map", ], [ - "0", + "1", "Int", ], [ - "a > 0", - "Bool", - ], - [ - "a", + "2", "Int", ], [ - "10", - "Int", + "m.set(1, 2)", + "", ], [ - "a", - "Int", + "m", + "map", ], [ - "10", + "3", "Int", ], [ - "-10", - "Int", + "m.del(3)", + "Bool", ], [ - "a < -10", - "Bool", + "emptyMap()", + "", ], [ - "a", - "Int", + "m", + "map", ], [ "1", "Int", ], [ - "-1", + "2", "Int", ], [ - "a", - "Int", + "m.set(1, 2)", + "", + ], + [ + "m", + "map", ], [ "1", "Int", ], + [ + "m.del(1)", + "Bool", + ], ] `; -exports[`resolveStatements should resolve statements for case-7 1`] = ` +exports[`resolveStatements should resolve statements for expr-struct-construction 1`] = ` [ [ "1", @@ -909,7 +937,7 @@ exports[`resolveStatements should resolve statements for case-7 1`] = ` ] `; -exports[`resolveStatements should resolve statements for case-8 1`] = ` +exports[`resolveStatements should resolve statements for init-vars-analysis-with-if 1`] = ` [ [ "arg", @@ -1042,143 +1070,140 @@ exports[`resolveStatements should resolve statements for case-8 1`] = ` ] `; -exports[`resolveStatements should resolve statements for case-9 1`] = ` +exports[`resolveStatements should resolve statements for return-analysis-if-elseif 1`] = ` [ [ - "src", - "bounced", + "b", + "Bool", ], [ - "src.a", + "42", "Int", ], [ - "src", - "bounced", + "c", + "Bool", ], [ - "src.b", + "43", + "Int", + ], + [ + "d", "Bool", ], -] -`; - -exports[`resolveStatements should resolve statements for case-10 1`] = ` -[ [ - "123", + "44", "Int", ], [ - "toString()", + "45", "Int", ], ] `; -exports[`resolveStatements should resolve statements for case-11 1`] = ` +exports[`resolveStatements should resolve statements for return-analysis-if-try-catch-do-loop 1`] = ` [ [ - "1", - "Int", + "b", + "Bool", ], [ - "toString", + "1", "Int", ], [ - "dump(toString)", - "", + "b", + "Bool", ], -] -`; - -exports[`resolveStatements should resolve statements for case-12 1`] = ` -[ [ - "a", + "0", "Int", ], [ - "b", + "1", "Int", ], [ - "a + b", + "b ? 0 : 1", "Int", ], [ - "2", + "1 / (b ? 0 : 1)", "Int", ], [ - "(a + b) / 2", + "42", "Int", ], [ - "1", + "43", "Int", ], [ - "10", - "Int", + "b", + "Bool", ], [ - "valueOf(1, 10)", + "!b", + "Bool", + ], + [ + "44", "Int", ], ] `; -exports[`resolveStatements should resolve statements for case-13 1`] = ` +exports[`resolveStatements should resolve statements for return-analysis-no-return-in-void1 1`] = `[]`; + +exports[`resolveStatements should resolve statements for return-analysis-no-return-in-void2 1`] = ` [ [ - "123", - "Int", - ], - [ - "456", + "42", "Int", ], [ - "a", + "x", "Int", ], [ - "a", + "1", "Int", ], +] +`; + +exports[`resolveStatements should resolve statements for return-analysis-try-catch 1`] = ` +[ [ - "b", + "0", "Int", ], [ - "a + b", + "1", "Int", ], [ - "a", + "42", "Int", ], [ - "b", + "1", "Int", ], [ - "a + b", + "43", "Int", ], ] `; -exports[`resolveStatements should resolve statements for case-14 1`] = ` +exports[`resolveStatements should resolve statements for stmt-augmented-assgn-numerical-type 1`] = ` [ [ - "123", - "Int", - ], - [ - "456", + "3", "Int", ], [ @@ -1186,363 +1211,348 @@ exports[`resolveStatements should resolve statements for case-14 1`] = ` "Int", ], [ - "b", + "2", "Int", ], [ "a", "Int", ], - [ - "b", - "Int", - ], - [ - "a + b", - "Int", - ], - [ - "b", - "Int", - ], ] `; -exports[`resolveStatements should resolve statements for case-15 1`] = ` +exports[`resolveStatements should resolve statements for stmt-let-assgn 1`] = ` [ [ - "emptyMap()", - "", - ], - [ - "m", - "map", - ], - [ - "1", + "x", "Int", ], [ - "2", + "y", "Int", ], [ - "m.set(1, 2)", - "", - ], - [ - "m", - "map", - ], - [ - "3", + "x + y", "Int", ], [ - "m.del(3)", - "Bool", + "b", + "Int", ], [ - "emptyMap()", - "", + "b", + "Int", ], [ - "m", - "map", + "1", + "Int", ], [ - "1", + "b + 1", "Int", ], [ - "2", + "b", "Int", ], [ - "m.set(1, 2)", - "", + "0", + "Int", ], [ - "m", - "map", + "b > 0", + "Bool", ], [ - "1", - "Int", + "z", + "Bool", ], [ - "m.del(1)", + "b > 0 || z", "Bool", ], ] `; -exports[`resolveStatements should resolve statements for case-16 1`] = `[]`; - -exports[`resolveStatements should resolve statements for case-17 1`] = ` +exports[`resolveStatements should resolve statements for stmt-let-assgn-unbox 1`] = ` [ [ - "42", + "x", "Int", ], [ - "x", + "y", "Int", ], [ - "1", + "x + y", "Int", ], -] -`; - -exports[`resolveStatements should resolve statements for case-18 1`] = ` -[ [ "b", - "Bool", + "Int", ], [ - "42", + "b", "Int", ], [ - "c", - "Bool", + "1", + "Int", ], [ - "43", + "b + 1", "Int", ], [ - "d", - "Bool", + "b", + "Int", ], [ - "44", + "0", "Int", ], [ - "45", - "Int", + "b > 0", + "Bool", ], -] -`; - -exports[`resolveStatements should resolve statements for case-19 1`] = ` -[ [ - "0", - "Int", + "z", + "Bool", ], [ - "1", - "Int", + "b > 0 || z", + "Bool", ], [ - "42", - "Int", + "w", + "Int?", ], [ - "1", + "w!!", "Int", ], [ - "43", + "0", "Int", ], + [ + "w!! > 0", + "Bool", + ], + [ + "b > 0 || z || (w!! > 0)", + "Bool", + ], ] `; -exports[`resolveStatements should resolve statements for case-20 1`] = ` +exports[`resolveStatements should resolve statements for stmt-let-if-elseif 1`] = ` [ [ - "b", - "Bool", - ], - [ - "1", + "10", "Int", ], [ - "b", - "Bool", + "a", + "Int", ], [ "0", "Int", ], [ - "1", - "Int", + "a > 0", + "Bool", ], [ - "b ? 0 : 1", + "a", "Int", ], [ - "1 / (b ? 0 : 1)", + "10", "Int", ], [ - "42", + "a", "Int", ], [ - "43", + "10", "Int", ], [ - "b", - "Bool", + "-10", + "Int", ], [ - "!b", + "a < -10", "Bool", ], [ - "44", + "a", "Int", ], -] -`; - -exports[`resolveStatements should resolve statements for case-21 1`] = ` -[ [ - "3", + "1", "Int", ], [ - "a", + "-1", "Int", ], [ - "2", + "a", "Int", ], [ - "a", + "1", "Int", ], ] `; -exports[`resolveStatements should resolve statements for case-22 1`] = ` +exports[`resolveStatements should resolve statements for var-scope-let-toString 1`] = ` [ [ - "true", - "Bool", + "1", + "Int", ], [ - "cond", - "Bool", + "toString", + "Int", ], [ - "42", + "dump(toString)", + "", + ], +] +`; + +exports[`resolveStatements should resolve statements for var-scope-repeat 1`] = ` +[ + [ + "123", "Int", ], [ - "x", - "Int?", + "456", + "Int", ], [ - "cond ? 42 : x", - "Int?", + "a", + "Int", ], [ - "true", - "Bool", + "a", + "Int", ], [ - "cond", - "Bool", + "b", + "Int", ], [ - "x", - "Int?", + "a + b", + "Int", ], [ - "42", + "a", "Int", ], [ - "cond ? x : 42", - "Int?", + "b", + "Int", ], [ - "true", - "Bool", + "a + b", + "Int", ], +] +`; + +exports[`resolveStatements should resolve statements for var-scope-repeat2 1`] = ` +[ [ - "cond", - "Bool", + "123", + "Int", ], [ - "null", - "", + "456", + "Int", ], [ - "m", - "map", + "a", + "Int", ], [ - "cond ? null : m", - "map", + "b", + "Int", ], [ - "true", - "Bool", + "a", + "Int", ], [ - "cond", - "Bool", + "b", + "Int", ], [ - "m", - "map", + "a + b", + "Int", ], [ - "null", - "", + "b", + "Int", ], +] +`; + +exports[`resolveStatements should resolve statements for var-scope-toString-non-method 1`] = ` +[ [ - "cond ? m : null", - "map", + "123", + "Int", ], [ - "true", - "Bool", + "toString()", + "Int", + ], +] +`; + +exports[`resolveStatements should resolve statements for var-scope-valueOf-fun 1`] = ` +[ + [ + "a", + "Int", ], [ - "cond", - "Bool", + "b", + "Int", ], [ - "42", + "a + b", "Int", ], [ - "Baz { b: 42 }", - "Baz", + "2", + "Int", ], [ - "Baz { b: 42 }.toCell()", - "Cell", + "(a + b) / 2", + "Int", ], [ - "x", - "Cell?", + "1", + "Int", ], [ - "cond ? Baz { b: 42 }.toCell() : x", - "Cell?", + "10", + "Int", ], [ - "Bar { - a: cond ? Baz { b: 42 }.toCell() : x - }", - "Bar", + "valueOf(1, 10)", + "Int", ], ] `; diff --git a/src/types/stmts-failed/case-24.tact b/src/types/stmts-failed/bounced-type-is-smaller.tact similarity index 100% rename from src/types/stmts-failed/case-24.tact rename to src/types/stmts-failed/bounced-type-is-smaller.tact diff --git a/src/types/stmts-failed/case-14.tact b/src/types/stmts-failed/contract-initof-wrong-arg.tact similarity index 100% rename from src/types/stmts-failed/case-14.tact rename to src/types/stmts-failed/contract-initof-wrong-arg.tact diff --git a/src/types/stmts-failed/case-53.tact b/src/types/stmts-failed/expr-bitwise-not-bool.tact similarity index 100% rename from src/types/stmts-failed/case-53.tact rename to src/types/stmts-failed/expr-bitwise-not-bool.tact diff --git a/src/types/stmts-failed/case-25.tact b/src/types/stmts-failed/expr-cmp-int-bool.tact similarity index 100% rename from src/types/stmts-failed/case-25.tact rename to src/types/stmts-failed/expr-cmp-int-bool.tact diff --git a/src/types/stmts-failed/case-26.tact b/src/types/stmts-failed/expr-conditional-branch-mismatch-nested1.tact similarity index 100% rename from src/types/stmts-failed/case-26.tact rename to src/types/stmts-failed/expr-conditional-branch-mismatch-nested1.tact diff --git a/src/types/stmts-failed/case-29.tact b/src/types/stmts-failed/expr-conditional-branch-mismatch-nested2.tact similarity index 100% rename from src/types/stmts-failed/case-29.tact rename to src/types/stmts-failed/expr-conditional-branch-mismatch-nested2.tact diff --git a/src/types/stmts-failed/case-27.tact b/src/types/stmts-failed/expr-conditional-branch-mismatch.tact similarity index 100% rename from src/types/stmts-failed/case-27.tact rename to src/types/stmts-failed/expr-conditional-branch-mismatch.tact diff --git a/src/types/stmts-failed/case-54.tact b/src/types/stmts-failed/expr-conditional-non-optional-result-expected.tact similarity index 100% rename from src/types/stmts-failed/case-54.tact rename to src/types/stmts-failed/expr-conditional-non-optional-result-expected.tact diff --git a/src/types/stmts-failed/case-28.tact b/src/types/stmts-failed/expr-conditional-result-mismatch.tact similarity index 100% rename from src/types/stmts-failed/case-28.tact rename to src/types/stmts-failed/expr-conditional-result-mismatch.tact diff --git a/src/types/stmts-failed/case-9.tact b/src/types/stmts-failed/expr-internal-fun-call-bool-param.tact.tact similarity index 100% rename from src/types/stmts-failed/case-9.tact rename to src/types/stmts-failed/expr-internal-fun-call-bool-param.tact.tact diff --git a/src/types/stmts-failed/case-37.tact b/src/types/stmts-failed/expr-map-del-method-is-non-void.tact similarity index 100% rename from src/types/stmts-failed/case-37.tact rename to src/types/stmts-failed/expr-map-del-method-is-non-void.tact diff --git a/src/types/stmts-failed/case-8.tact b/src/types/stmts-failed/expr-module-fun-call-bool-param.tact similarity index 100% rename from src/types/stmts-failed/case-8.tact rename to src/types/stmts-failed/expr-module-fun-call-bool-param.tact diff --git a/src/types/stmts-failed/case-12.tact b/src/types/stmts-failed/expr-struct-duplicate-field.tact similarity index 100% rename from src/types/stmts-failed/case-12.tact rename to src/types/stmts-failed/expr-struct-duplicate-field.tact diff --git a/src/types/stmts-failed/case-36.tact b/src/types/stmts-failed/expr-struct-impossible-field-punning.tact similarity index 100% rename from src/types/stmts-failed/case-36.tact rename to src/types/stmts-failed/expr-struct-impossible-field-punning.tact diff --git a/src/types/stmts-failed/case-13.tact b/src/types/stmts-failed/expr-struct-missing-field.tact similarity index 100% rename from src/types/stmts-failed/case-13.tact rename to src/types/stmts-failed/expr-struct-missing-field.tact diff --git a/src/types/stmts-failed/case-11.tact b/src/types/stmts-failed/expr-struct-wrong-field-type.tact similarity index 100% rename from src/types/stmts-failed/case-11.tact rename to src/types/stmts-failed/expr-struct-wrong-field-type.tact diff --git a/src/types/stmts-failed/case-0.tact b/src/types/stmts-failed/expr-var-int-bool.tact similarity index 100% rename from src/types/stmts-failed/case-0.tact rename to src/types/stmts-failed/expr-var-int-bool.tact diff --git a/src/types/stmts-failed/case-7.tact b/src/types/stmts-failed/expr-wrong-arity-internal-fun.tact similarity index 100% rename from src/types/stmts-failed/case-7.tact rename to src/types/stmts-failed/expr-wrong-arity-internal-fun.tact diff --git a/src/types/stmts-failed/case-6.tact b/src/types/stmts-failed/expr-wrong-arity-module-fun.tact similarity index 100% rename from src/types/stmts-failed/case-6.tact rename to src/types/stmts-failed/expr-wrong-arity-module-fun.tact diff --git a/src/types/stmts-failed/case-16.tact b/src/types/stmts-failed/init-vars-analysis-if.tact similarity index 100% rename from src/types/stmts-failed/case-16.tact rename to src/types/stmts-failed/init-vars-analysis-if.tact diff --git a/src/test/compilation-fail/contracts/implicit-init.tact b/src/types/stmts-failed/init-vars-analysis-implicit-init.tact similarity index 79% rename from src/test/compilation-fail/contracts/implicit-init.tact rename to src/types/stmts-failed/init-vars-analysis-implicit-init.tact index 77e361784..b1744dcd6 100644 --- a/src/test/compilation-fail/contracts/implicit-init.tact +++ b/src/types/stmts-failed/init-vars-analysis-implicit-init.tact @@ -1,6 +1,7 @@ -import "@stdlib/deploy"; +primitive Int; +trait BaseTrait {} -contract MyContract with Deployable { +contract MyContract { counter: Int = 0; test_field: Int; diff --git a/src/types/stmts-failed/case-15.tact b/src/types/stmts-failed/init-vars-analysis-missing-storage-var.tact similarity index 100% rename from src/types/stmts-failed/case-15.tact rename to src/types/stmts-failed/init-vars-analysis-missing-storage-var.tact diff --git a/src/types/stmts-failed/case-23.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-override-fun-call.tact similarity index 92% rename from src/types/stmts-failed/case-23.tact rename to src/types/stmts-failed/init-vars-analysis-used-uninit-storage-override-fun-call.tact index d9d0ead01..bb15ba90b 100644 --- a/src/types/stmts-failed/case-23.tact +++ b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-override-fun-call.tact @@ -12,7 +12,7 @@ trait AbstractTrait { contract Contract { value: Int; init(arg: Bool) { - self.update(); + self.execute(); self.value = 1; } diff --git a/src/types/stmts-failed/case-20.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-struct1.tact similarity index 100% rename from src/types/stmts-failed/case-20.tact rename to src/types/stmts-failed/init-vars-analysis-used-uninit-storage-struct1.tact diff --git a/src/types/stmts-failed/case-21.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-struct2.tact similarity index 100% rename from src/types/stmts-failed/case-21.tact rename to src/types/stmts-failed/init-vars-analysis-used-uninit-storage-struct2.tact diff --git a/src/types/stmts-failed/case-22.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-var-fun-call.tact similarity index 100% rename from src/types/stmts-failed/case-22.tact rename to src/types/stmts-failed/init-vars-analysis-used-uninit-storage-var-fun-call.tact diff --git a/src/types/stmts-failed/case-19.tact b/src/types/stmts-failed/init-vars-analysis-used-uninit-storage-var.tact similarity index 100% rename from src/types/stmts-failed/case-19.tact rename to src/types/stmts-failed/init-vars-analysis-used-uninit-storage-var.tact diff --git a/src/types/stmts-failed/case-17.tact b/src/types/stmts-failed/init-vars-analysis-with-if-else.tact similarity index 100% rename from src/types/stmts-failed/case-17.tact rename to src/types/stmts-failed/init-vars-analysis-with-if-else.tact diff --git a/src/types/stmts-failed/case-18.tact b/src/types/stmts-failed/init-vars-analysis-with-if-elseif.tact similarity index 100% rename from src/types/stmts-failed/case-18.tact rename to src/types/stmts-failed/init-vars-analysis-with-if-elseif.tact diff --git a/src/types/stmts-failed/case-43.tact b/src/types/stmts-failed/return-analysis-catch-if.tact similarity index 100% rename from src/types/stmts-failed/case-43.tact rename to src/types/stmts-failed/return-analysis-catch-if.tact diff --git a/src/types/stmts-failed/case-46.tact b/src/types/stmts-failed/return-analysis-do-if.tact similarity index 100% rename from src/types/stmts-failed/case-46.tact rename to src/types/stmts-failed/return-analysis-do-if.tact diff --git a/src/types/stmts-failed/case-40.tact b/src/types/stmts-failed/return-analysis-if.tact similarity index 100% rename from src/types/stmts-failed/case-40.tact rename to src/types/stmts-failed/return-analysis-if.tact diff --git a/src/types/stmts-failed/case-38.tact b/src/types/stmts-failed/return-analysis-non-void1.tact similarity index 100% rename from src/types/stmts-failed/case-38.tact rename to src/types/stmts-failed/return-analysis-non-void1.tact diff --git a/src/types/stmts-failed/case-39.tact b/src/types/stmts-failed/return-analysis-non-void2.tact similarity index 100% rename from src/types/stmts-failed/case-39.tact rename to src/types/stmts-failed/return-analysis-non-void2.tact diff --git a/src/types/stmts-failed/case-45.tact b/src/types/stmts-failed/return-analysis-repeat.tact similarity index 100% rename from src/types/stmts-failed/case-45.tact rename to src/types/stmts-failed/return-analysis-repeat.tact diff --git a/src/types/stmts-failed/case-41.tact b/src/types/stmts-failed/return-analysis-separate-ifs.tact similarity index 100% rename from src/types/stmts-failed/case-41.tact rename to src/types/stmts-failed/return-analysis-separate-ifs.tact diff --git a/src/types/stmts-failed/case-42.tact b/src/types/stmts-failed/return-analysis-try.tact similarity index 100% rename from src/types/stmts-failed/case-42.tact rename to src/types/stmts-failed/return-analysis-try.tact diff --git a/src/types/stmts-failed/case-44.tact b/src/types/stmts-failed/return-analysis-while.tact similarity index 100% rename from src/types/stmts-failed/case-44.tact rename to src/types/stmts-failed/return-analysis-while.tact diff --git a/src/types/stmts-failed/case-5.tact b/src/types/stmts-failed/stmt-assgn-int-string.tact similarity index 100% rename from src/types/stmts-failed/case-5.tact rename to src/types/stmts-failed/stmt-assgn-int-string.tact diff --git a/src/types/stmts-failed/case-51.tact b/src/types/stmts-failed/stmt-augmented-assgn-bool.tact similarity index 100% rename from src/types/stmts-failed/case-51.tact rename to src/types/stmts-failed/stmt-augmented-assgn-bool.tact diff --git a/src/types/stmts-failed/case-52.tact b/src/types/stmts-failed/stmt-augmented-assgn-string.tact similarity index 100% rename from src/types/stmts-failed/case-52.tact rename to src/types/stmts-failed/stmt-augmented-assgn-string.tact diff --git a/src/types/stmts-failed/case-3.tact b/src/types/stmts-failed/stmt-do-int.tact similarity index 100% rename from src/types/stmts-failed/case-3.tact rename to src/types/stmts-failed/stmt-do-int.tact diff --git a/src/types/stmts-failed/case-4.tact b/src/types/stmts-failed/stmt-if-int.tact similarity index 100% rename from src/types/stmts-failed/case-4.tact rename to src/types/stmts-failed/stmt-if-int.tact diff --git a/src/types/stmts-failed/case-10.tact b/src/types/stmts-failed/stmt-let-wrong-rhs.tact similarity index 100% rename from src/types/stmts-failed/case-10.tact rename to src/types/stmts-failed/stmt-let-wrong-rhs.tact diff --git a/src/types/stmts-failed/case-1.tact b/src/types/stmts-failed/stmt-repeat-bool.tact similarity index 100% rename from src/types/stmts-failed/case-1.tact rename to src/types/stmts-failed/stmt-repeat-bool.tact diff --git a/src/types/stmts-failed/case-35.tact b/src/types/stmts-failed/stmt-return-from-try-and-catch.tact similarity index 100% rename from src/types/stmts-failed/case-35.tact rename to src/types/stmts-failed/stmt-return-from-try-and-catch.tact diff --git a/src/types/stmts-failed/case-2.tact b/src/types/stmts-failed/stmt-while-int.tact similarity index 100% rename from src/types/stmts-failed/case-2.tact rename to src/types/stmts-failed/stmt-while-int.tact diff --git a/src/types/stmts-failed/case-34.tact b/src/types/stmts-failed/var-scope-catch-param-does-not-shadow-outer-var.tact similarity index 100% rename from src/types/stmts-failed/case-34.tact rename to src/types/stmts-failed/var-scope-catch-param-does-not-shadow-outer-var.tact diff --git a/src/types/stmts-failed/case-33.tact b/src/types/stmts-failed/var-scope-catch-param-is-not-visible-in-try.tact similarity index 100% rename from src/types/stmts-failed/case-33.tact rename to src/types/stmts-failed/var-scope-catch-param-is-not-visible-in-try.tact diff --git a/src/types/stmts-failed/case-50.tact b/src/types/stmts-failed/var-scope-foreach-internal-var-does-not-escape.tact similarity index 100% rename from src/types/stmts-failed/case-50.tact rename to src/types/stmts-failed/var-scope-foreach-internal-var-does-not-escape.tact diff --git a/src/types/stmts-failed/case-49.tact b/src/types/stmts-failed/var-scope-foreach-val-does-not-escape.tact similarity index 100% rename from src/types/stmts-failed/case-49.tact rename to src/types/stmts-failed/var-scope-foreach-val-does-not-escape.tact diff --git a/src/types/stmts-failed/case-47.tact b/src/types/stmts-failed/var-scope-foreach-val-shadows-key.tact similarity index 100% rename from src/types/stmts-failed/case-47.tact rename to src/types/stmts-failed/var-scope-foreach-val-shadows-key.tact diff --git a/src/types/stmts-failed/case-48.tact b/src/types/stmts-failed/var-scope-foreach-val-shadows-map.tact similarity index 100% rename from src/types/stmts-failed/case-48.tact rename to src/types/stmts-failed/var-scope-foreach-val-shadows-map.tact diff --git a/src/types/stmts-failed/case-32.tact b/src/types/stmts-failed/var-scope-local-catch-param-does-not-escape.tact similarity index 100% rename from src/types/stmts-failed/case-32.tact rename to src/types/stmts-failed/var-scope-local-catch-param-does-not-escape.tact diff --git a/src/types/stmts-failed/case-31.tact b/src/types/stmts-failed/var-scope-local-loop-var-does-not-escape.tact similarity index 100% rename from src/types/stmts-failed/case-31.tact rename to src/types/stmts-failed/var-scope-local-loop-var-does-not-escape.tact diff --git a/src/types/stmts-failed/case-30.tact b/src/types/stmts-failed/var-scope-no-toString-global-fun.tact similarity index 100% rename from src/types/stmts-failed/case-30.tact rename to src/types/stmts-failed/var-scope-no-toString-global-fun.tact diff --git a/src/types/stmts/case-9.tact b/src/types/stmts/contract-receiver-bounced.tact similarity index 100% rename from src/types/stmts/case-9.tact rename to src/types/stmts/contract-receiver-bounced.tact diff --git a/src/types/stmts/case-2.tact b/src/types/stmts/expr-arith-bool-cmp.tact similarity index 100% rename from src/types/stmts/case-2.tact rename to src/types/stmts/expr-arith-bool-cmp.tact diff --git a/src/types/stmts/case-1.tact b/src/types/stmts/expr-cmp-arith.tact similarity index 100% rename from src/types/stmts/case-1.tact rename to src/types/stmts/expr-cmp-arith.tact diff --git a/src/types/stmts/case-0.tact b/src/types/stmts/expr-cmp-literal.tact similarity index 100% rename from src/types/stmts/case-0.tact rename to src/types/stmts/expr-cmp-literal.tact diff --git a/src/types/stmts/case-22.tact b/src/types/stmts/expr-conditional-with-subtyping.tact similarity index 100% rename from src/types/stmts/case-22.tact rename to src/types/stmts/expr-conditional-with-subtyping.tact diff --git a/src/types/stmts/case-5.tact b/src/types/stmts/expr-field-access-method-call.tact similarity index 100% rename from src/types/stmts/case-5.tact rename to src/types/stmts/expr-field-access-method-call.tact diff --git a/src/types/stmts/case-15.tact b/src/types/stmts/expr-maps-del-method.tact similarity index 100% rename from src/types/stmts/case-15.tact rename to src/types/stmts/expr-maps-del-method.tact diff --git a/src/types/stmts/case-7.tact b/src/types/stmts/expr-struct-construction.tact similarity index 100% rename from src/types/stmts/case-7.tact rename to src/types/stmts/expr-struct-construction.tact diff --git a/src/types/stmts/case-8.tact b/src/types/stmts/init-vars-analysis-with-if.tact similarity index 100% rename from src/types/stmts/case-8.tact rename to src/types/stmts/init-vars-analysis-with-if.tact diff --git a/src/types/stmts/case-18.tact b/src/types/stmts/return-analysis-if-elseif.tact similarity index 100% rename from src/types/stmts/case-18.tact rename to src/types/stmts/return-analysis-if-elseif.tact diff --git a/src/types/stmts/case-20.tact b/src/types/stmts/return-analysis-if-try-catch-do-loop.tact similarity index 100% rename from src/types/stmts/case-20.tact rename to src/types/stmts/return-analysis-if-try-catch-do-loop.tact diff --git a/src/types/stmts/case-16.tact b/src/types/stmts/return-analysis-no-return-in-void1.tact similarity index 100% rename from src/types/stmts/case-16.tact rename to src/types/stmts/return-analysis-no-return-in-void1.tact diff --git a/src/types/stmts/case-17.tact b/src/types/stmts/return-analysis-no-return-in-void2.tact similarity index 100% rename from src/types/stmts/case-17.tact rename to src/types/stmts/return-analysis-no-return-in-void2.tact diff --git a/src/types/stmts/case-19.tact b/src/types/stmts/return-analysis-try-catch.tact similarity index 100% rename from src/types/stmts/case-19.tact rename to src/types/stmts/return-analysis-try-catch.tact diff --git a/src/types/stmts/case-21.tact b/src/types/stmts/stmt-augmented-assgn-numerical-type.tact similarity index 100% rename from src/types/stmts/case-21.tact rename to src/types/stmts/stmt-augmented-assgn-numerical-type.tact diff --git a/src/types/stmts/case-4.tact b/src/types/stmts/stmt-let-assgn-unbox.tact similarity index 100% rename from src/types/stmts/case-4.tact rename to src/types/stmts/stmt-let-assgn-unbox.tact diff --git a/src/types/stmts/case-3.tact b/src/types/stmts/stmt-let-assgn.tact similarity index 100% rename from src/types/stmts/case-3.tact rename to src/types/stmts/stmt-let-assgn.tact diff --git a/src/types/stmts/case-6.tact b/src/types/stmts/stmt-let-if-elseif.tact similarity index 100% rename from src/types/stmts/case-6.tact rename to src/types/stmts/stmt-let-if-elseif.tact diff --git a/src/types/stmts/case-11.tact b/src/types/stmts/var-scope-let-toString.tact similarity index 100% rename from src/types/stmts/case-11.tact rename to src/types/stmts/var-scope-let-toString.tact diff --git a/src/types/stmts/case-13.tact b/src/types/stmts/var-scope-repeat.tact similarity index 100% rename from src/types/stmts/case-13.tact rename to src/types/stmts/var-scope-repeat.tact diff --git a/src/types/stmts/case-14.tact b/src/types/stmts/var-scope-repeat2.tact similarity index 100% rename from src/types/stmts/case-14.tact rename to src/types/stmts/var-scope-repeat2.tact diff --git a/src/types/stmts/case-10.tact b/src/types/stmts/var-scope-toString-non-method.tact similarity index 100% rename from src/types/stmts/case-10.tact rename to src/types/stmts/var-scope-toString-non-method.tact diff --git a/src/types/stmts/case-12.tact b/src/types/stmts/var-scope-valueOf-fun.tact similarity index 100% rename from src/types/stmts/case-12.tact rename to src/types/stmts/var-scope-valueOf-fun.tact diff --git a/src/types/test-failed/case-1.tact b/src/types/test-failed/case-1.tact deleted file mode 100644 index 7a4369e97..000000000 --- a/src/types/test-failed/case-1.tact +++ /dev/null @@ -1,9 +0,0 @@ -primitive Int; -primitive Bool; - -trait BaseTrait { - -} - -@name(hello_world) -get native sample(a: Int): Int; \ No newline at end of file diff --git a/src/types/test-failed/case-3.tact b/src/types/test-failed/case-3.tact deleted file mode 100644 index 7a6b4ad35..000000000 --- a/src/types/test-failed/case-3.tact +++ /dev/null @@ -1,10 +0,0 @@ -primitive Int; -primitive Bool; - -trait BaseTrait { - -} - -get fun sample(a: Int): Int { - return 0; -} \ No newline at end of file diff --git a/src/types/test-failed/case-25.tact b/src/types/test-failed/const-eval-overflow.tact similarity index 100% rename from src/types/test-failed/case-25.tact rename to src/types/test-failed/const-eval-overflow.tact diff --git a/src/types/test-failed/case-21.tact b/src/types/test-failed/contract-bounced-receiver-int.tact similarity index 100% rename from src/types/test-failed/case-21.tact rename to src/types/test-failed/contract-bounced-receiver-int.tact diff --git a/src/types/test-failed/case-24.tact b/src/types/test-failed/contract-bounced-storage-var.tact similarity index 100% rename from src/types/test-failed/case-24.tact rename to src/types/test-failed/contract-bounced-storage-var.tact diff --git a/src/types/test-failed/case-23.tact b/src/types/test-failed/contract-duplicate-bounced-fallback-receiver.tact similarity index 100% rename from src/types/test-failed/case-23.tact rename to src/types/test-failed/contract-duplicate-bounced-fallback-receiver.tact diff --git a/src/types/test-failed/case-22.tact b/src/types/test-failed/contract-duplicate-bounced-receiver.tact similarity index 100% rename from src/types/test-failed/case-22.tact rename to src/types/test-failed/contract-duplicate-bounced-receiver.tact diff --git a/src/types/test-failed/case-19.tact b/src/types/test-failed/contract-duplicate-init.tact similarity index 79% rename from src/types/test-failed/case-19.tact rename to src/types/test-failed/contract-duplicate-init.tact index 8873bdfe0..656f484f0 100644 --- a/src/types/test-failed/case-19.tact +++ b/src/types/test-failed/contract-duplicate-init.tact @@ -6,7 +6,7 @@ trait BaseTrait { } contract Main { - init(a: Bool, a: Int) { + init(a: Bool, b: Int) { } diff --git a/src/types/test-failed/case-7.tact b/src/types/test-failed/contract-duplicate-storage-var.tact similarity index 100% rename from src/types/test-failed/case-7.tact rename to src/types/test-failed/contract-duplicate-storage-var.tact diff --git a/src/types/test-failed/case-11.tact b/src/types/test-failed/contract-missing-type.tact similarity index 100% rename from src/types/test-failed/case-11.tact rename to src/types/test-failed/contract-missing-type.tact diff --git a/src/types/test-failed/case-10.tact b/src/types/test-failed/contract-receiver-int.tact similarity index 100% rename from src/types/test-failed/case-10.tact rename to src/types/test-failed/contract-receiver-int.tact diff --git a/src/types/test-failed/case-8.tact b/src/types/test-failed/contract-receiver-optional-msg.tact similarity index 100% rename from src/types/test-failed/case-8.tact rename to src/types/test-failed/contract-receiver-optional-msg.tact diff --git a/src/types/test-failed/case-9.tact b/src/types/test-failed/contract-receiver-struct.tact similarity index 100% rename from src/types/test-failed/case-9.tact rename to src/types/test-failed/contract-receiver-struct.tact diff --git a/src/types/test-failed/case-28.tact b/src/types/test-failed/expr-bitwise-not-bool-in-const1.tact similarity index 100% rename from src/types/test-failed/case-28.tact rename to src/types/test-failed/expr-bitwise-not-bool-in-const1.tact diff --git a/src/types/test-failed/case-29.tact b/src/types/test-failed/expr-bitwise-not-bool-in-const2.tact similarity index 100% rename from src/types/test-failed/case-29.tact rename to src/types/test-failed/expr-bitwise-not-bool-in-const2.tact diff --git a/src/types/test-failed/case-2.tact b/src/types/test-failed/getter-outside-contract.tact similarity index 100% rename from src/types/test-failed/case-2.tact rename to src/types/test-failed/getter-outside-contract.tact diff --git a/src/types/test-failed/case-4.tact b/src/types/test-failed/method-first-param-not-self1.tact similarity index 100% rename from src/types/test-failed/case-4.tact rename to src/types/test-failed/method-first-param-not-self1.tact diff --git a/src/types/test-failed/case-5.tact b/src/types/test-failed/method-first-param-not-self2.tact similarity index 100% rename from src/types/test-failed/case-5.tact rename to src/types/test-failed/method-first-param-not-self2.tact diff --git a/src/types/test-failed/case-0.tact b/src/types/test-failed/native-fun-getter.tact similarity index 100% rename from src/types/test-failed/case-0.tact rename to src/types/test-failed/native-fun-getter.tact diff --git a/src/types/test-failed/case-14.tact b/src/types/test-failed/scope-contract-shadows-contract.tact similarity index 100% rename from src/types/test-failed/case-14.tact rename to src/types/test-failed/scope-contract-shadows-contract.tact diff --git a/src/types/test-failed/case-20.tact b/src/types/test-failed/scope-duplicate-method.tact similarity index 100% rename from src/types/test-failed/case-20.tact rename to src/types/test-failed/scope-duplicate-method.tact diff --git a/src/types/test-failed/case-27.tact b/src/types/test-failed/scope-fun-shadows-builtin-dumpStack.tact similarity index 100% rename from src/types/test-failed/case-27.tact rename to src/types/test-failed/scope-fun-shadows-builtin-dumpStack.tact diff --git a/src/types/test-failed/case-26.tact b/src/types/test-failed/scope-fun-shadows-builtin-ton.tact similarity index 100% rename from src/types/test-failed/case-26.tact rename to src/types/test-failed/scope-fun-shadows-builtin-ton.tact diff --git a/src/types/test-failed/case-16.tact b/src/types/test-failed/scope-fun-shadows-fun.tact similarity index 100% rename from src/types/test-failed/case-16.tact rename to src/types/test-failed/scope-fun-shadows-fun.tact diff --git a/src/types/test-failed/case-17.tact b/src/types/test-failed/scope-internal-fun-shadows-internal-fun.tact similarity index 100% rename from src/types/test-failed/case-17.tact rename to src/types/test-failed/scope-internal-fun-shadows-internal-fun.tact diff --git a/src/types/test-failed/case-18.tact b/src/types/test-failed/scope-param-shadows-param.tact similarity index 100% rename from src/types/test-failed/case-18.tact rename to src/types/test-failed/scope-param-shadows-param.tact diff --git a/src/types/test-failed/case-12.tact b/src/types/test-failed/scope-struct-shadows-contract.tact similarity index 100% rename from src/types/test-failed/case-12.tact rename to src/types/test-failed/scope-struct-shadows-contract.tact diff --git a/src/types/test-failed/case-13.tact b/src/types/test-failed/scope-struct-shadows-struct.tact similarity index 100% rename from src/types/test-failed/case-13.tact rename to src/types/test-failed/scope-struct-shadows-struct.tact diff --git a/src/types/test-failed/case-6.tact b/src/types/test-failed/struct-duplicate-field.tact similarity index 100% rename from src/types/test-failed/case-6.tact rename to src/types/test-failed/struct-duplicate-field.tact diff --git a/src/types/test-failed/case-15.tact b/src/types/test-failed/struct-empty-not-allowed.tact similarity index 100% rename from src/types/test-failed/case-15.tact rename to src/types/test-failed/struct-empty-not-allowed.tact diff --git a/src/types/test/case-8.tact b/src/types/test/contract-bounced-slice.tact similarity index 100% rename from src/types/test/case-8.tact rename to src/types/test/contract-bounced-slice.tact diff --git a/src/types/test/case-9.tact b/src/types/test/contract-bounced-too-small-not-detected.tact similarity index 100% rename from src/types/test/case-9.tact rename to src/types/test/contract-bounced-too-small-not-detected.tact diff --git a/src/types/test/case-3.tact b/src/types/test/init-vars-analysis-uninit-storage-vars.tact similarity index 100% rename from src/types/test/case-3.tact rename to src/types/test/init-vars-analysis-uninit-storage-vars.tact diff --git a/src/types/test/case-2.tact b/src/types/test/item-funs-with-errors-in-bodies1.tact similarity index 100% rename from src/types/test/case-2.tact rename to src/types/test/item-funs-with-errors-in-bodies1.tact diff --git a/src/types/test/case-7.tact b/src/types/test/item-funs-with-errors-in-bodies2.tact similarity index 100% rename from src/types/test/case-7.tact rename to src/types/test/item-funs-with-errors-in-bodies2.tact diff --git a/src/types/test/case-6.tact b/src/types/test/item-method.tact similarity index 100% rename from src/types/test/case-6.tact rename to src/types/test/item-method.tact diff --git a/src/types/test/case-4.tact b/src/types/test/item-native-decl.tact similarity index 100% rename from src/types/test/case-4.tact rename to src/types/test/item-native-decl.tact diff --git a/src/types/test/case-5.tact b/src/types/test/item-native-mutating-method.tact similarity index 100% rename from src/types/test/case-5.tact rename to src/types/test/item-native-mutating-method.tact diff --git a/src/test/bugs/issue117.tact b/src/types/test/scope-loops.tact similarity index 100% rename from src/test/bugs/issue117.tact rename to src/types/test/scope-loops.tact diff --git a/src/types/test/case-1.tact b/src/types/test/struct-nested.tact similarity index 100% rename from src/types/test/case-1.tact rename to src/types/test/struct-nested.tact diff --git a/src/types/test/case-0.tact b/src/types/test/trait-base.tact similarity index 100% rename from src/types/test/case-0.tact rename to src/types/test/trait-base.tact diff --git a/tact.config.json b/tact.config.json index 3eac0aec2..43f8f872d 100644 --- a/tact.config.json +++ b/tact.config.json @@ -81,160 +81,173 @@ }, { "name": "maps", - "path": "./src/test/features/maps.tact", - "output": "./src/test/features/output" + "path": "./src/test/e2e-emulated/contracts/maps.tact", + "output": "./src/test/e2e-emulated/contracts/output" }, { "name": "map-traverse", - "path": "./src/test/features/map-traverse.tact", - "output": "./src/test/features/output" + "path": "./src/test/e2e-emulated/contracts/map-traverse.tact", + "output": "./src/test/e2e-emulated/contracts/output" + }, + { + "name": "mutating-method-chaining", + "path": "./src/test/e2e-emulated/contracts/mutating-method-chaining.tact", + "output": "./src/test/e2e-emulated/contracts/output" }, { "name": "optionals", - "path": "./src/test/features/optionals.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/optionals.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true, "masterchain": true } }, + { + "name": "sample-jetton", + "path": "./src/test/e2e-emulated/contracts/sample-jetton.tact", + "output": "./src/test/e2e-emulated/contracts/output", + "options": { + "debug": true + } + }, { "name": "serialization", - "path": "./src/test/features/serialization.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/serialization.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "serialization-2", - "path": "./src/test/features/serialization-2.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/serialization-2.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "serialization-3", - "path": "./src/test/features/serialization-3.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/serialization-3.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "strings", - "path": "./src/test/features/strings.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/strings.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "constants", - "path": "./src/test/features/constants.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/constants.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "math", - "path": "./src/test/features/math.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/math.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "dns", - "path": "./src/test/features/dns.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/dns.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "integer-literals", - "path": "./src/test/features/integer-literals.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/integer-literals.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "random", - "path": "./src/test/features/random.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/random.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "ordering", - "path": "./src/test/features/ordering.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/ordering.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "deep", - "path": "./src/test/features/deep-sequence.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/deep-sequence.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "bounced-routing", - "path": "./src/test/features/bounced-routing.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/bounced-routing.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "debug", - "path": "./src/test/features/debug.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/debug.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "send", - "path": "./src/test/features/send.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/send.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "intrinsics", - "path": "./src/test/features/intrinsics.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/intrinsics.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "masterchain", - "path": "./src/test/features/masterchain.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/masterchain.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "try-catch", - "path": "./src/test/features/try-catch.tact", - "output": "./src/test/features/output" + "path": "./src/test/e2e-emulated/contracts/try-catch.tact", + "output": "./src/test/e2e-emulated/contracts/output" }, { "name": "masterchain-allow", - "path": "./src/test/features/masterchain.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/masterchain.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true, "masterchain": true @@ -242,32 +255,32 @@ }, { "name": "address", - "path": "./src/test/features/address.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/address.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "ternary", - "path": "./src/test/features/ternary.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/ternary.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "implicit-init", - "path": "./src/test/features/implicit-init.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/implicit-init.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } }, { "name": "recursion", - "path": "./src/test/features/recursion.tact", - "output": "./src/test/features/output", + "path": "./src/test/e2e-emulated/contracts/recursion.tact", + "output": "./src/test/e2e-emulated/contracts/output", "options": { "debug": true } @@ -288,12 +301,17 @@ } }, { - "name": "bugs", - "path": "./src/test/bugs/bugs.tact", - "output": "./src/test/bugs/output", + "name": "codegen", + "path": "./src/test/codegen/all-contracts.tact", + "output": "./src/test/codegen/output", "options": { "debug": true } + }, + { + "name": "stdlib", + "path": "./src/test/e2e-emulated/contracts/stdlib.tact", + "output": "./src/test/e2e-emulated/contracts/output" } ] } diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 9fcaa7d7b..3c32dd50d 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -64,5 +64,5 @@ "resolveJsonModule": true }, "include": ["src/", "examples/", "scripts/", "./jest.config.js"], - "exclude": ["**/*.bind.ts", "src/test/features/output/**/*"] + "exclude": ["**/*.bind.ts", "src/test/**/output/**/*"] }