From fa56dbcacb18f75f26d278a984e3e6f0a2ccdb83 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 01:50:02 +0400 Subject: [PATCH 01/12] feat(types): allow serialization specifiers for trait fields Fixes #655 --- .../resolveDescriptors.spec.ts.snap | 813 ++++++++++++++++++ src/types/resolveDescriptors.ts | 11 +- ...rait-with-as-typed-field-for-contract.tact | 11 + .../trait-with-as-typed-field-for-trait.tact | 11 + ...s-typed-field-with-unsupported-format.tact | 7 + src/types/test/trait-with-as-typed-field.tact | 15 + 6 files changed, 862 insertions(+), 6 deletions(-) create mode 100644 src/types/test-failed/trait-with-as-typed-field-for-contract.tact create mode 100644 src/types/test-failed/trait-with-as-typed-field-for-trait.tact create mode 100644 src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact create mode 100644 src/types/test/trait-with-as-typed-field.tact diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index c8091958f..52fe774d3 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -650,6 +650,36 @@ Line 2, col 14: " `; +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-contract 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int as int32", but "Int" given +Line 10, col 5: + 9 | contract SomeContract with Foo { +> 10 | f: Int; + ^~~~~~ + 11 | } +" +`; + +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-trait 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int as int32", but "Int" given +Line 10, col 5: + 9 | trait SomeTrait with Foo { +> 10 | f: Int; + ^~~~~~ + 11 | } +" +`; + +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-with-unsupported-format 1`] = ` +":6:5: Unsupported format "fooo" +Line 6, col 5: + 5 | trait Foo { +> 6 | f: Int as fooo; + ^~~~~~~~~~~~~~ + 7 | } +" +`; + exports[`resolveDescriptors should fail descriptors for wf-type-const 1`] = ` ":4:19: Invalid map type. Check https://docs.tact-lang.org/book/maps#allowed-types Line 4, col 19: @@ -15203,3 +15233,786 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` `; exports[`resolveDescriptors should resolve descriptors for trait-foreach 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 17, + "kind": "trait", + "loc": trait SomeTrait with Foo { + f: Int as int32; +}, + "name": { + "id": 11, + "kind": "id", + "loc": SomeTrait, + "text": "SomeTrait", + }, + "traits": [ + { + "id": 12, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "SomeTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 8387, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 22, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 23, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 20, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 21, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 24, + "kind": "contract", + "loc": contract SomeContract with Foo { + f: Int as int32; +}, + "name": { + "id": 18, + "kind": "id", + "loc": SomeContract, + "text": "SomeContract", + }, + "traits": [ + { + "id": 19, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 22, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 23, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 20, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 21, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": { + "ast": { + "id": 26, + "kind": "contract_init", + "loc": contract SomeContract with Foo { + f: Int as int32; +}, + "params": [], + "statements": [], + }, + "params": [], + }, + "interfaces": [], + "kind": "contract", + "name": "SomeContract", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 59799, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index bd82e7ade..3837e32c7 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -560,12 +560,6 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { traitDecl.loc, ); } - if (traitDecl.as) { - throwCompilationError( - `Trait field cannot have serialization specifier`, - traitDecl.loc, - ); - } if (traitDecl.initializer) { throwCompilationError( `Trait field cannot have an initializer`, @@ -1552,6 +1546,11 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { `Trait "${tr.name}" requires field "${f.name}" of type "${printTypeRef(f.type)}"`, t.ast.loc, ); + } else if (f.as !== null && f.as !== ex.as) { + throwCompilationError( + `Trait "${tr.name}" requires field "${f.name}" of type "${printTypeRef(f.type)} as ${f.as}", but "${printTypeRef(f.type)}" given`, + ex.ast.loc, + ); } } } diff --git a/src/types/test-failed/trait-with-as-typed-field-for-contract.tact b/src/types/test-failed/trait-with-as-typed-field-for-contract.tact new file mode 100644 index 000000000..77b1bebc9 --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-for-contract.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +contract SomeContract with Foo { + f: Int; +} diff --git a/src/types/test-failed/trait-with-as-typed-field-for-trait.tact b/src/types/test-failed/trait-with-as-typed-field-for-trait.tact new file mode 100644 index 000000000..ff787b323 --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-for-trait.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +trait SomeTrait with Foo { + f: Int; +} diff --git a/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact b/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact new file mode 100644 index 000000000..0ed40084e --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact @@ -0,0 +1,7 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as fooo; +} diff --git a/src/types/test/trait-with-as-typed-field.tact b/src/types/test/trait-with-as-typed-field.tact new file mode 100644 index 000000000..9245fd6de --- /dev/null +++ b/src/types/test/trait-with-as-typed-field.tact @@ -0,0 +1,15 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +trait SomeTrait with Foo { + f: Int as int32; +} + +contract SomeContract with Foo { + f: Int as int32; +} From 4fd558edb1d48f028cb2d33f0d40737a896ec872 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 01:56:01 +0400 Subject: [PATCH 02/12] add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaf53e5e6..2b5188fbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove `org.ton.chain.any.v0` interface: PR [#1207](https://github.com/tact-lang/tact/pull/1207) - To reduce fees, Tact no longer stores the parent contract code in the system cell that holds all the child contract codes used in `initOf`. Instead, the `MYCODE` instruction is used: PR [#1213](https://github.com/tact-lang/tact/pull/1213) - Generated TS wrappers now use `const` where possible for variable declarations: PR [#1292](https://github.com/tact-lang/tact/pull/1292) +- Allow serialization specifiers for trait fields PR [#1303](https://github.com/tact-lang/tact/pull/1303) ### Fixed From 501f6176d1b15373e8227e7fc6864cd64c1cd620 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 01:59:48 +0400 Subject: [PATCH 03/12] used known word "foo" instead "fooo" --- src/types/__snapshots__/resolveDescriptors.spec.ts.snap | 6 +++--- .../trait-with-as-typed-field-with-unsupported-format.tact | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 52fe774d3..82a424f04 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -671,11 +671,11 @@ Line 10, col 5: `; exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-with-unsupported-format 1`] = ` -":6:5: Unsupported format "fooo" +":6:5: Unsupported format "foo" Line 6, col 5: 5 | trait Foo { -> 6 | f: Int as fooo; - ^~~~~~~~~~~~~~ +> 6 | f: Int as foo; + ^~~~~~~~~~~~~ 7 | } " `; diff --git a/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact b/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact index 0ed40084e..c7164e9f2 100644 --- a/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact +++ b/src/types/test-failed/trait-with-as-typed-field-with-unsupported-format.tact @@ -3,5 +3,5 @@ primitive Int; trait BaseTrait {} trait Foo { - f: Int as fooo; + f: Int as foo; } From 7bf1d926a2fd751ba20feb31d0902dd52ad5e8b9 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 02:00:26 +0400 Subject: [PATCH 04/12] fixed CHANGELOG.md entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5188fbd..8543f2f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove `org.ton.chain.any.v0` interface: PR [#1207](https://github.com/tact-lang/tact/pull/1207) - To reduce fees, Tact no longer stores the parent contract code in the system cell that holds all the child contract codes used in `initOf`. Instead, the `MYCODE` instruction is used: PR [#1213](https://github.com/tact-lang/tact/pull/1213) - Generated TS wrappers now use `const` where possible for variable declarations: PR [#1292](https://github.com/tact-lang/tact/pull/1292) -- Allow serialization specifiers for trait fields PR [#1303](https://github.com/tact-lang/tact/pull/1303) +- Allow serialization specifiers for trait fields PR: [#1303](https://github.com/tact-lang/tact/pull/1303) ### Fixed From dba6e92aeef08d48df695858be38c9c04421df01 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 02:23:32 +0400 Subject: [PATCH 05/12] added one more test --- .../resolveDescriptors.spec.ts.snap | 753 ++++++++++++++++++ ...hout-as-typed-field-inherited-with-it.tact | 15 + 2 files changed, 768 insertions(+) create mode 100644 src/types/test/trait-without-as-typed-field-inherited-with-it.tact diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 82a424f04..ebc95f738 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -16016,3 +16016,756 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f `; exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 9, + "kind": "trait", + "loc": trait Foo { + f: Int; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 14, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 15, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 12, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 13, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 16, + "kind": "trait", + "loc": trait SomeTrait with Foo { + f: Int as int32; +}, + "name": { + "id": 10, + "kind": "id", + "loc": SomeTrait, + "text": "SomeTrait", + }, + "traits": [ + { + "id": 11, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 14, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 15, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 12, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 13, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "SomeTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 9, + "kind": "trait", + "loc": trait Foo { + f: Int; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 8387, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 21, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 22, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 19, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 20, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 23, + "kind": "contract", + "loc": contract SomeContract with Foo { + f: Int as int32; +}, + "name": { + "id": 17, + "kind": "id", + "loc": SomeContract, + "text": "SomeContract", + }, + "traits": [ + { + "id": 18, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 21, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 22, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 19, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 20, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": { + "ast": { + "id": 25, + "kind": "contract_init", + "loc": contract SomeContract with Foo { + f: Int as int32; +}, + "params": [], + "statements": [], + }, + "params": [], + }, + "interfaces": [], + "kind": "contract", + "name": "SomeContract", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 9, + "kind": "trait", + "loc": trait Foo { + f: Int; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 59799, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 2`] = `[]`; diff --git a/src/types/test/trait-without-as-typed-field-inherited-with-it.tact b/src/types/test/trait-without-as-typed-field-inherited-with-it.tact new file mode 100644 index 000000000..fd54d3978 --- /dev/null +++ b/src/types/test/trait-without-as-typed-field-inherited-with-it.tact @@ -0,0 +1,15 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int; +} + +trait SomeTrait with Foo { + f: Int as int32; +} + +contract SomeContract with Foo { + f: Int as int32; +} From 9248a8b5e1d14899482085dfe14ff3666613ff29 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 02:39:09 +0400 Subject: [PATCH 06/12] forbid `field: Int as int32` in child for `field: Int` field in trait and add more tests --- .../resolveDescriptors.spec.ts.snap | 803 ++---------------- src/types/resolveDescriptors.ts | 19 +- ...or-contract-with-other-specialization.tact | 11 + ...ed-field-for-contract-with-other-type.tact | 16 + ...d-for-trait-with-other-specialization.tact | 11 + ...typed-field-for-trait-with-other-type.tact | 12 + ...hout-as-typed-field-inherited-with-it.tact | 0 7 files changed, 118 insertions(+), 754 deletions(-) create mode 100644 src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-specialization.tact create mode 100644 src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-type.tact create mode 100644 src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-specialization.tact create mode 100644 src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-type.tact rename src/types/{test => test-failed}/trait-without-as-typed-field-inherited-with-it.tact (100%) diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index ebc95f738..0c9309a4e 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -660,6 +660,26 @@ Line 10, col 5: " `; +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-contract-with-other-specialization 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int as int32", but "Int as int16" given +Line 10, col 5: + 9 | contract SomeContract with Foo { +> 10 | f: Int as int16 = 0; + ^~~~~~~~~~~~~~~~~~~ + 11 | } +" +`; + +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-contract-with-other-type 1`] = ` +":10:1: Trait "Foo" requires field "f" of type "Int" +Line 10, col 1: + 9 | +> 10 | contract SomeContract with Foo { + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 11 | f: Cell; +" +`; + exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-trait 1`] = ` ":10:5: Trait "Foo" requires field "f" of type "Int as int32", but "Int" given Line 10, col 5: @@ -670,6 +690,26 @@ Line 10, col 5: " `; +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-trait-with-other-specialization 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int as int32", but "Int as int16" given +Line 10, col 5: + 9 | trait SomeTrait with Foo { +> 10 | f: Int as int16; + ^~~~~~~~~~~~~~~ + 11 | } +" +`; + +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-for-trait-with-other-type 1`] = ` +":10:1: Trait "Foo" requires field "f" of type "Int" +Line 10, col 1: + 9 | +> 10 | trait SomeTrait with Foo { + ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 11 | f: Cell; +" +`; + exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-with-unsupported-format 1`] = ` ":6:5: Unsupported format "foo" Line 6, col 5: @@ -680,6 +720,16 @@ Line 6, col 5: " `; +exports[`resolveDescriptors should fail descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int", but "Int as int32" given +Line 10, col 5: + 9 | trait SomeTrait with Foo { +> 10 | f: Int as int32; + ^~~~~~~~~~~~~~~ + 11 | } +" +`; + exports[`resolveDescriptors should fail descriptors for wf-type-const 1`] = ` ":4:19: Invalid map type. Check https://docs.tact-lang.org/book/maps#allowed-types Line 4, col 19: @@ -16016,756 +16066,3 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f `; exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; - -exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` -[ - { - "ast": { - "id": 2, - "kind": "primitive_type_decl", - "loc": primitive Int;, - "name": { - "id": 1, - "kind": "id", - "loc": Int, - "text": "Int", - }, - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive_type_decl", - "name": "Int", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 38154, - }, - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 9, - "kind": "trait", - "loc": trait Foo { - f: Int; -}, - "name": { - "id": 5, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, - "ast": { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "Foo", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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": 10576, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": { - "id": 14, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 15, - "initializer": null, - "kind": "field_decl", - "loc": f: Int as int32, - "name": { - "id": 12, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 13, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 16, - "kind": "trait", - "loc": trait SomeTrait with Foo { - f: Int as int32; -}, - "name": { - "id": 10, - "kind": "id", - "loc": SomeTrait, - "text": "SomeTrait", - }, - "traits": [ - { - "id": 11, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - ], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 32, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": "int32", - "ast": { - "as": { - "id": 14, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 15, - "initializer": null, - "kind": "field_decl", - "loc": f: Int as int32, - "name": { - "id": 12, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 13, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int as int32, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "SomeTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 9, - "kind": "trait", - "loc": trait Foo { - f: Int; -}, - "name": { - "id": 5, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, - "ast": { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "Foo", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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": 10576, - }, - ], - "uid": 8387, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": { - "id": 21, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 22, - "initializer": null, - "kind": "field_decl", - "loc": f: Int as int32, - "name": { - "id": 19, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 20, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 23, - "kind": "contract", - "loc": contract SomeContract with Foo { - f: Int as int32; -}, - "name": { - "id": 17, - "kind": "id", - "loc": SomeContract, - "text": "SomeContract", - }, - "traits": [ - { - "id": 18, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - ], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 32, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": "int32", - "ast": { - "as": { - "id": 21, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 22, - "initializer": null, - "kind": "field_decl", - "loc": f: Int as int32, - "name": { - "id": 19, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 20, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int as int32, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": { - "ast": { - "id": 25, - "kind": "contract_init", - "loc": contract SomeContract with Foo { - f: Int as int32; -}, - "params": [], - "statements": [], - }, - "params": [], - }, - "interfaces": [], - "kind": "contract", - "name": "SomeContract", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 9, - "kind": "trait", - "loc": trait Foo { - f: Int; -}, - "name": { - "id": 5, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, - "ast": { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "Foo", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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": 10576, - }, - ], - "uid": 59799, - }, -] -`; - -exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 2`] = `[]`; diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 3837e32c7..01c73c404 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1547,8 +1547,25 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { t.ast.loc, ); } else if (f.as !== null && f.as !== ex.as) { + const expected = `${printTypeRef(f.type)} as ${f.as}`; + let actual = printTypeRef(ex.type); + if (ex.as !== null) { + actual += ` as ${ex.as}`; + } + + throwCompilationError( + `Trait "${tr.name}" requires field "${f.name}" of type "${expected}", but "${actual}" given`, + ex.ast.loc, + ); + } else if (ex.as !== null && f.as !== ex.as) { + let expected = printTypeRef(f.type); + if (f.as !== null) { + expected += ` as ${f.as}`; + } + const actual = `${printTypeRef(ex.type)} as ${ex.as}`; + throwCompilationError( - `Trait "${tr.name}" requires field "${f.name}" of type "${printTypeRef(f.type)} as ${f.as}", but "${printTypeRef(f.type)}" given`, + `Trait "${tr.name}" requires field "${f.name}" of type "${expected}", but "${actual}" given`, ex.ast.loc, ); } diff --git a/src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-specialization.tact b/src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-specialization.tact new file mode 100644 index 000000000..000881647 --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-specialization.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +contract SomeContract with Foo { + f: Int as int16 = 0; +} diff --git a/src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-type.tact b/src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-type.tact new file mode 100644 index 000000000..64fe8a31b --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-for-contract-with-other-type.tact @@ -0,0 +1,16 @@ +primitive Int; +primitive Cell; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +contract SomeContract with Foo { + f: Cell; + + init(f: Cell) { + self.f = f; + } +} diff --git a/src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-specialization.tact b/src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-specialization.tact new file mode 100644 index 000000000..4ddbbf526 --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-specialization.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +trait SomeTrait with Foo { + f: Int as int16; +} diff --git a/src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-type.tact b/src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-type.tact new file mode 100644 index 000000000..1e2d4a999 --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-for-trait-with-other-type.tact @@ -0,0 +1,12 @@ +primitive Int; +primitive Cell; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +trait SomeTrait with Foo { + f: Cell; +} diff --git a/src/types/test/trait-without-as-typed-field-inherited-with-it.tact b/src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact similarity index 100% rename from src/types/test/trait-without-as-typed-field-inherited-with-it.tact rename to src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact From d9d0266a12a0019f54dfe6e77cb489d968643490 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 02:50:00 +0400 Subject: [PATCH 07/12] allow `field: Int as coins` in child for `field: Int` in trait --- .../resolveDescriptors.spec.ts.snap | 763 +++++++++++++++++- src/types/resolveDescriptors.ts | 11 - ...hout-as-typed-field-inherited-with-it.tact | 2 +- 3 files changed, 754 insertions(+), 22 deletions(-) rename src/types/{test-failed => test}/trait-without-as-typed-field-inherited-with-it.tact (87%) diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 0c9309a4e..644c87b74 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -720,16 +720,6 @@ Line 6, col 5: " `; -exports[`resolveDescriptors should fail descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` -":10:5: Trait "Foo" requires field "f" of type "Int", but "Int as int32" given -Line 10, col 5: - 9 | trait SomeTrait with Foo { -> 10 | f: Int as int32; - ^~~~~~~~~~~~~~~ - 11 | } -" -`; - exports[`resolveDescriptors should fail descriptors for wf-type-const 1`] = ` ":4:19: Invalid map type. Check https://docs.tact-lang.org/book/maps#allowed-types Line 4, col 19: @@ -16066,3 +16056,756 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f `; exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 9, + "kind": "trait", + "loc": trait Foo { + f: Int; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 14, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 15, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 12, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 13, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 16, + "kind": "trait", + "loc": trait SomeTrait with Foo { + f: Int as int32; +}, + "name": { + "id": 10, + "kind": "id", + "loc": SomeTrait, + "text": "SomeTrait", + }, + "traits": [ + { + "id": 11, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 14, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 15, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 12, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 13, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "SomeTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 9, + "kind": "trait", + "loc": trait Foo { + f: Int; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 8387, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 21, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 22, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as coins, + "name": { + "id": 19, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 20, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 23, + "kind": "contract", + "loc": contract SomeContract with Foo { + f: Int as coins; +}, + "name": { + "id": 17, + "kind": "id", + "loc": SomeContract, + "text": "SomeContract", + }, + "traits": [ + { + "id": 18, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": "coins", + "kind": "simple", + "optional": false, + "type": "uint", + }, + }, + "as": "coins", + "ast": { + "as": { + "id": 21, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 22, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as coins, + "name": { + "id": 19, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 20, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as coins, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": { + "ast": { + "id": 25, + "kind": "contract_init", + "loc": contract SomeContract with Foo { + f: Int as coins; +}, + "params": [], + "statements": [], + }, + "params": [], + }, + "interfaces": [], + "kind": "contract", + "name": "SomeContract", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 9, + "kind": "trait", + "loc": trait Foo { + f: Int; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 8, + "initializer": null, + "kind": "field_decl", + "loc": f: Int, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 59799, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 2`] = `[]`; diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 01c73c404..7ccc24926 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1553,17 +1553,6 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { actual += ` as ${ex.as}`; } - throwCompilationError( - `Trait "${tr.name}" requires field "${f.name}" of type "${expected}", but "${actual}" given`, - ex.ast.loc, - ); - } else if (ex.as !== null && f.as !== ex.as) { - let expected = printTypeRef(f.type); - if (f.as !== null) { - expected += ` as ${f.as}`; - } - const actual = `${printTypeRef(ex.type)} as ${ex.as}`; - throwCompilationError( `Trait "${tr.name}" requires field "${f.name}" of type "${expected}", but "${actual}" given`, ex.ast.loc, diff --git a/src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact b/src/types/test/trait-without-as-typed-field-inherited-with-it.tact similarity index 87% rename from src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact rename to src/types/test/trait-without-as-typed-field-inherited-with-it.tact index fd54d3978..fca6c2baa 100644 --- a/src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact +++ b/src/types/test/trait-without-as-typed-field-inherited-with-it.tact @@ -11,5 +11,5 @@ trait SomeTrait with Foo { } contract SomeContract with Foo { - f: Int as int32; + f: Int as coins; } From 4d15708c46d6bca13be9727fcaf6f6840d647384 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:16:38 +0400 Subject: [PATCH 08/12] added diamond inheritance tests, removed unnecessary mutation --- .../resolveDescriptors.spec.ts.snap | 5223 ++++++++++++----- src/types/resolveDescriptors.ts | 7 +- ...-inheritance-and-other-specialization.tact | 23 + .../test/contract-with-as-typed-field.tact | 11 + ...as-typed-field-in-diamond-inheritance.tact | 23 + src/types/test/trait-with-as-typed-field.tact | 4 - 6 files changed, 3803 insertions(+), 1488 deletions(-) create mode 100644 src/types/test-failed/trait-with-as-typed-field-in-diamond-inheritance-and-other-specialization.tact create mode 100644 src/types/test/contract-with-as-typed-field.tact create mode 100644 src/types/test/trait-with-as-typed-field-in-diamond-inheritance.tact diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 53c672dd2..8ef90a74c 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -720,6 +720,16 @@ Line 10, col 1: " `; +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-in-diamond-inheritance-and-other-specialization 1`] = ` +":21:5: Trait "T2" requires field "f2" of type "Int as int32", but "Int as int16" given +Line 21, col 5: + 20 | f1: Int as int32; +> 21 | f2: Int as int16; + ^~~~~~~~~~~~~~~~ + 22 | f3: Int as int32; +" +`; + exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-field-with-unsupported-format 1`] = ` ":6:5: Unsupported format "foo" Line 6, col 5: @@ -6283,7 +6293,7 @@ exports[`resolveDescriptors should resolve descriptors for contract-getter-overr exports[`resolveDescriptors should resolve descriptors for contract-getter-override-virtual 2`] = `[]`; -exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self 1`] = ` +exports[`resolveDescriptors should resolve descriptors for contract-with-as-typed-field 1`] = ` [ { "ast": { @@ -6300,302 +6310,561 @@ exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self "constants": [], "dependsOn": [], "fields": [], - "functions": Map { - "test_extends" => { - "ast": { - "attributes": [ - { - "kind": "function_attribute", - "loc": extends, - "type": "extends", - }, - ], - "id": 26, - "kind": "function_def", - "loc": extends fun test_extends(self: Int, y: Int?): Int { - return 123; -}, + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, "name": { - "id": 15, + "id": 6, "kind": "id", - "loc": test_extends, - "text": "test_extends", + "loc": f, + "text": "f", }, - "params": [ - { - "id": 19, - "kind": "typed_parameter", - "loc": self: Int, - "name": { - "id": 17, - "kind": "id", - "loc": self, - "text": "self", - }, - "type": { - "id": 18, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - { - "id": 23, - "kind": "typed_parameter", - "loc": y: Int?, - "name": { - "id": 20, - "kind": "id", - "loc": y, - "text": "y", - }, - "type": { - "id": 22, - "kind": "optional_type", - "loc": Int?, - "typeArg": { - "id": 21, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - }, - ], - "return": { - "id": 16, + "type": { + "id": 7, "kind": "type_id", "loc": Int, "text": "Int", }, - "statements": [ - { - "expression": { - "base": 10, - "id": 24, - "kind": "number", - "loc": 123, - "value": 123n, - }, - "id": 25, - "kind": "statement_return", - "loc": return 123;, - }, - ], }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": false, - "isOverride": false, - "isVirtual": false, - "methodId": null, - "name": "test_extends", - "origin": "user", - "params": [ - { - "loc": y: Int?, - "name": { - "id": 20, - "kind": "id", - "loc": y, - "text": "y", - }, - "type": { - "kind": "ref", - "name": "Int", - "optional": true, - }, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", }, - ], - "returns": { - "kind": "ref", - "name": "Int", - "optional": false, }, - "self": { + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { "kind": "ref", "name": "Int", "optional": false, }, }, - "test_extends_self" => { + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { "ast": { - "attributes": [ - { - "kind": "function_attribute", - "loc": extends, - "type": "extends", - }, - ], - "id": 38, - "kind": "function_def", - "loc": extends fun test_extends_self(self: Int?, y: Int): Int { - return 123; -}, + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, "name": { - "id": 27, + "id": 3, "kind": "id", - "loc": test_extends_self, - "text": "test_extends_self", + "loc": BaseTrait, + "text": "BaseTrait", }, - "params": [ - { - "id": 32, - "kind": "typed_parameter", - "loc": self: Int?, - "name": { - "id": 29, - "kind": "id", - "loc": self, - "text": "self", - }, - "type": { - "id": 31, - "kind": "optional_type", - "loc": Int?, - "typeArg": { - "id": 30, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - }, - { - "id": 35, - "kind": "typed_parameter", - "loc": y: Int, - "name": { - "id": 33, - "kind": "id", - "loc": y, - "text": "y", - }, - "type": { - "id": 34, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "return": { - "id": 28, + "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": 10576, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 14, "kind": "type_id", "loc": Int, "text": "Int", }, - "statements": [ - { - "expression": { - "base": 10, - "id": 36, - "kind": "number", - "loc": 123, - "value": 123n, - }, - "id": 37, - "kind": "statement_return", - "loc": return 123;, - }, - ], }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": false, - "isOverride": false, - "isVirtual": false, - "methodId": null, - "name": "test_extends_self", - "origin": "user", - "params": [ - { - "loc": y: Int, - "name": { - "id": 33, - "kind": "id", - "loc": y, - "text": "y", - }, - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, + ], + "id": 17, + "kind": "contract", + "loc": contract SomeContract with Foo { + f: Int as int32; +}, + "name": { + "id": 11, + "kind": "id", + "loc": SomeContract, + "text": "SomeContract", + }, + "traits": [ + { + "id": 12, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", }, - ], - "returns": { - "kind": "ref", - "name": "Int", - "optional": false, }, - "self": { + "as": "int32", + "ast": { + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { "kind": "ref", "name": "Int", - "optional": true, + "optional": false, }, }, - "test_mutates" => { - "ast": { - "attributes": [ - { - "kind": "function_attribute", - "loc": extends, - "type": "extends", - }, - { - "kind": "function_attribute", - "loc": mutates, - "type": "mutates", - }, - ], - "id": 50, - "kind": "function_def", - "loc": extends mutates fun test_mutates(self: Int, y: Int?): Int { - return 123; + ], + "functions": Map {}, + "header": null, + "init": { + "ast": { + "id": 19, + "kind": "contract_init", + "loc": contract SomeContract with Foo { + f: Int as int32; }, + "params": [], + "statements": [], + }, + "params": [], + }, + "interfaces": [], + "kind": "contract", + "name": "SomeContract", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, "name": { - "id": 39, + "id": 3, "kind": "id", - "loc": test_mutates, - "text": "test_mutates", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 59799, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for contract-with-as-typed-field 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map { + "test_extends" => { + "ast": { + "attributes": [ + { + "kind": "function_attribute", + "loc": extends, + "type": "extends", + }, + ], + "id": 26, + "kind": "function_def", + "loc": extends fun test_extends(self: Int, y: Int?): Int { + return 123; +}, + "name": { + "id": 15, + "kind": "id", + "loc": test_extends, + "text": "test_extends", }, "params": [ { - "id": 43, + "id": 19, "kind": "typed_parameter", "loc": self: Int, "name": { - "id": 41, + "id": 17, "kind": "id", "loc": self, "text": "self", }, "type": { - "id": 42, + "id": 18, "kind": "type_id", "loc": Int, "text": "Int", }, }, { - "id": 47, + "id": 23, "kind": "typed_parameter", "loc": y: Int?, "name": { - "id": 44, + "id": 20, "kind": "id", "loc": y, "text": "y", }, "type": { - "id": 46, + "id": 22, "kind": "optional_type", "loc": Int?, "typeArg": { - "id": 45, + "id": 21, "kind": "type_id", "loc": Int, "text": "Int", @@ -6604,7 +6873,7 @@ exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self }, ], "return": { - "id": 40, + "id": 16, "kind": "type_id", "loc": Int, "text": "Int", @@ -6613,12 +6882,12 @@ exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self { "expression": { "base": 10, - "id": 48, + "id": 24, "kind": "number", "loc": 123, "value": 123n, }, - "id": 49, + "id": 25, "kind": "statement_return", "loc": return 123;, }, @@ -6627,17 +6896,17 @@ exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self "isAbstract": false, "isGetter": false, "isInline": false, - "isMutating": true, + "isMutating": false, "isOverride": false, "isVirtual": false, "methodId": null, - "name": "test_mutates", + "name": "test_extends", "origin": "user", "params": [ { "loc": y: Int?, "name": { - "id": 44, + "id": 20, "kind": "id", "loc": y, "text": "y", @@ -6660,7 +6929,7 @@ exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self "optional": false, }, }, - "test_mutates_self" => { + "test_extends_self" => { "ast": { "attributes": [ { @@ -6668,40 +6937,281 @@ exports[`resolveDescriptors should resolve descriptors for fun-extends-opt-self "loc": extends, "type": "extends", }, - { - "kind": "function_attribute", - "loc": mutates, - "type": "mutates", - }, ], - "id": 62, + "id": 38, "kind": "function_def", - "loc": extends mutates fun test_mutates_self(self: Int?, y: Int): Int { + "loc": extends fun test_extends_self(self: Int?, y: Int): Int { return 123; }, "name": { - "id": 51, + "id": 27, "kind": "id", - "loc": test_mutates_self, - "text": "test_mutates_self", + "loc": test_extends_self, + "text": "test_extends_self", }, "params": [ { - "id": 56, + "id": 32, "kind": "typed_parameter", "loc": self: Int?, "name": { - "id": 53, + "id": 29, "kind": "id", "loc": self, "text": "self", }, "type": { - "id": 55, + "id": 31, "kind": "optional_type", "loc": Int?, "typeArg": { - "id": 54, + "id": 30, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + { + "id": 35, + "kind": "typed_parameter", + "loc": y: Int, + "name": { + "id": 33, + "kind": "id", + "loc": y, + "text": "y", + }, + "type": { + "id": 34, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "return": { + "id": 28, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "statements": [ + { + "expression": { + "base": 10, + "id": 36, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "id": 37, + "kind": "statement_return", + "loc": return 123;, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": false, + "isOverride": false, + "isVirtual": false, + "methodId": null, + "name": "test_extends_self", + "origin": "user", + "params": [ + { + "loc": y: Int, + "name": { + "id": 33, + "kind": "id", + "loc": y, + "text": "y", + }, + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "returns": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + "self": { + "kind": "ref", + "name": "Int", + "optional": true, + }, + }, + "test_mutates" => { + "ast": { + "attributes": [ + { + "kind": "function_attribute", + "loc": extends, + "type": "extends", + }, + { + "kind": "function_attribute", + "loc": mutates, + "type": "mutates", + }, + ], + "id": 50, + "kind": "function_def", + "loc": extends mutates fun test_mutates(self: Int, y: Int?): Int { + return 123; +}, + "name": { + "id": 39, + "kind": "id", + "loc": test_mutates, + "text": "test_mutates", + }, + "params": [ + { + "id": 43, + "kind": "typed_parameter", + "loc": self: Int, + "name": { + "id": 41, + "kind": "id", + "loc": self, + "text": "self", + }, + "type": { + "id": 42, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "id": 47, + "kind": "typed_parameter", + "loc": y: Int?, + "name": { + "id": 44, + "kind": "id", + "loc": y, + "text": "y", + }, + "type": { + "id": 46, + "kind": "optional_type", + "loc": Int?, + "typeArg": { + "id": 45, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + ], + "return": { + "id": 40, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "statements": [ + { + "expression": { + "base": 10, + "id": 48, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "id": 49, + "kind": "statement_return", + "loc": return 123;, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": true, + "isOverride": false, + "isVirtual": false, + "methodId": null, + "name": "test_mutates", + "origin": "user", + "params": [ + { + "loc": y: Int?, + "name": { + "id": 44, + "kind": "id", + "loc": y, + "text": "y", + }, + "type": { + "kind": "ref", + "name": "Int", + "optional": true, + }, + }, + ], + "returns": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + "self": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + "test_mutates_self" => { + "ast": { + "attributes": [ + { + "kind": "function_attribute", + "loc": extends, + "type": "extends", + }, + { + "kind": "function_attribute", + "loc": mutates, + "type": "mutates", + }, + ], + "id": 62, + "kind": "function_def", + "loc": extends mutates fun test_mutates_self(self: Int?, y: Int): Int { + return 123; +}, + "name": { + "id": 51, + "kind": "id", + "loc": test_mutates_self, + "text": "test_mutates_self", + }, + "params": [ + { + "id": 56, + "kind": "typed_parameter", + "loc": self: Int?, + "name": { + "id": 53, + "kind": "id", + "loc": self, + "text": "self", + }, + "type": { + "id": 55, + "kind": "optional_type", + "loc": Int?, + "typeArg": { + "id": 54, "kind": "type_id", "loc": Int, "text": "Int", @@ -14481,77 +14991,1343 @@ exports[`resolveDescriptors should resolve descriptors for struct-decl-non-rec-t "text": "Int", }, }, - "default": undefined, - "index": 0, - "loc": value: Int, - "name": "value", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, + "default": undefined, + "index": 0, + "loc": value: Int, + "name": "value", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "struct", + "name": "SomeStruct", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": "SomeStruct{value:int257}", + "tlb": "_ value:int257 = SomeStruct", + "traits": [], + "uid": 61480, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for struct-decl-non-rec-types 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder 1`] = ` +[ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 2, + "kind": "trait", + "loc": trait BaseTrait { }, + "name": { + "id": 1, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "id": 4, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 3, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "id": 6, + "kind": "primitive_type_decl", + "loc": primitive Cell;, + "name": { + "id": 5, + "kind": "id", + "loc": Cell, + "text": "Cell", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Cell", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 26294, + }, + { + "ast": { + "fields": [ + { + "as": null, + "id": 10, + "initializer": null, + "kind": "field_decl", + "loc": a: Int, + "name": { + "id": 8, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 9, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": null, + "id": 13, + "initializer": null, + "kind": "field_decl", + "loc": b: Int, + "name": { + "id": 11, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 12, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 16, + "kind": "id", + "loc": remaining, + "text": "remaining", + }, + "id": 17, + "initializer": null, + "kind": "field_decl", + "loc": s: Cell as remaining, + "name": { + "id": 14, + "kind": "id", + "loc": s, + "text": "s", + }, + "type": { + "id": 15, + "kind": "type_id", + "loc": Cell, + "text": "Cell", + }, + }, + ], + "id": 18, + "kind": "struct_decl", + "loc": struct Test { + a: Int; + b: Int; + s: Cell as remaining; +}, + "name": { + "id": 7, + "kind": "id", + "loc": Test, + "text": "Test", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "a", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 10, + "initializer": null, + "kind": "field_decl", + "loc": a: Int, + "name": { + "id": 8, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 9, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": a: Int, + "name": "a", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + { + "abi": { + "name": "b", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": null, + "ast": { + "as": null, + "id": 13, + "initializer": null, + "kind": "field_decl", + "loc": b: Int, + "name": { + "id": 11, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 12, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 1, + "loc": b: Int, + "name": "b", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + { + "abi": { + "name": "s", + "type": { + "format": "remainder", + "kind": "simple", + "optional": false, + "type": "cell", + }, + }, + "as": "remaining", + "ast": { + "as": { + "id": 16, + "kind": "id", + "loc": remaining, + "text": "remaining", + }, + "id": 17, + "initializer": null, + "kind": "field_decl", + "loc": s: Cell as remaining, + "name": { + "id": 14, + "kind": "id", + "loc": s, + "text": "s", + }, + "type": { + "id": 15, + "kind": "type_id", + "loc": Cell, + "text": "Cell", + }, + }, + "default": undefined, + "index": 2, + "loc": s: Cell as remaining, + "name": "s", + "type": { + "kind": "ref", + "name": "Cell", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "struct", + "name": "Test", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": "Test{a:int257,b:int257,s:remainder}", + "tlb": "_ a:int257 b:int257 s:remainder = Test", + "traits": [], + "uid": 44104, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "id": 4, + "kind": "primitive_type_decl", + "loc": primitive Bool;, + "name": { + "id": 3, + "kind": "id", + "loc": Bool, + "text": "Bool", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Bool", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 33424, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 6, + "kind": "trait", + "loc": trait BaseTrait { + +}, + "name": { + "id": 5, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for trait-base 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait { }, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 10, + "initializer": null, + "kind": "field_decl", + "loc": m: map, + "name": { + "id": 6, + "kind": "id", + "loc": m, + "text": "m", + }, + "type": { + "id": 9, + "keyStorageType": null, + "keyType": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "kind": "map_type", + "loc": map, + "valueStorageType": null, + "valueType": { + "id": 8, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + { + "attributes": [], + "id": 18, + "kind": "function_def", + "loc": fun test() { foreach(_, _ in self.m) { } }, + "name": { + "id": 11, + "kind": "id", + "loc": test, + "text": "test", + }, + "params": [], + "return": null, + "statements": [ + { + "id": 17, + "keyName": { + "id": 12, + "kind": "id", + "loc": _, + "text": "_", + }, + "kind": "statement_foreach", + "loc": foreach(_, _ in self.m) { }, + "map": { + "aggregate": { + "id": 14, + "kind": "id", + "loc": self, + "text": "self", + }, + "field": { + "id": 15, + "kind": "id", + "loc": m, + "text": "m", + }, + "id": 16, + "kind": "field_access", + "loc": self.m, + }, + "statements": [], + "valueName": { + "id": 13, + "kind": "id", + "loc": _, + "text": "_", + }, + }, + ], + }, + ], + "id": 19, + "kind": "trait", + "loc": trait TraitWithForeach { + m: map; + + fun test() { foreach(_, _ in self.m) { } } +}, + "name": { + "id": 5, + "kind": "id", + "loc": TraitWithForeach, + "text": "TraitWithForeach", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "m", + "type": { + "key": "int", + "keyFormat": undefined, + "kind": "dict", + "value": "int", + "valueFormat": undefined, + }, + }, + "as": null, + "ast": { + "as": null, + "id": 10, + "initializer": null, + "kind": "field_decl", + "loc": m: map, + "name": { + "id": 6, + "kind": "id", + "loc": m, + "text": "m", + }, + "type": { + "id": 9, + "keyStorageType": null, + "keyType": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "kind": "map_type", + "loc": map, + "valueStorageType": null, + "valueType": { + "id": 8, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + "default": undefined, + "index": 0, + "loc": m: map, + "name": "m", + "type": { + "key": "Int", + "keyAs": null, + "kind": "map", + "value": "Int", + "valueAs": null, + }, + }, + ], + "functions": Map { + "test" => { + "ast": { + "attributes": [], + "id": 18, + "kind": "function_def", + "loc": fun test() { foreach(_, _ in self.m) { } }, + "name": { + "id": 11, + "kind": "id", + "loc": test, + "text": "test", + }, + "params": [], + "return": null, + "statements": [ + { + "id": 17, + "keyName": { + "id": 12, + "kind": "id", + "loc": _, + "text": "_", + }, + "kind": "statement_foreach", + "loc": foreach(_, _ in self.m) { }, + "map": { + "aggregate": { + "id": 14, + "kind": "id", + "loc": self, + "text": "self", + }, + "field": { + "id": 15, + "kind": "id", + "loc": m, + "text": "m", + }, + "id": 16, + "kind": "field_access", + "loc": self.m, + }, + "statements": [], + "valueName": { + "id": 13, + "kind": "id", + "loc": _, + "text": "_", + }, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": true, + "isOverride": false, + "isVirtual": false, + "methodId": null, + "name": "test", + "origin": "user", + "params": [], + "returns": { + "kind": "void", + }, + "self": { + "kind": "ref", + "name": "TraitWithForeach", + "optional": false, + }, + }, + }, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "TraitWithForeach", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait { }, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 20892, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 26, + "initializer": null, + "kind": "field_decl", + "loc": m: map, + "name": { + "id": 22, + "kind": "id", + "loc": m, + "text": "m", + }, + "type": { + "id": 25, + "keyStorageType": null, + "keyType": { + "id": 23, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "kind": "map_type", + "loc": map, + "valueStorageType": null, + "valueType": { + "id": 24, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + ], + "id": 27, + "kind": "contract", + "loc": contract Test with TraitWithForeach { + m: map; +}, + "name": { + "id": 20, + "kind": "id", + "loc": Test, + "text": "Test", + }, + "traits": [ + { + "id": 21, + "kind": "id", + "loc": TraitWithForeach, + "text": "TraitWithForeach", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "m", + "type": { + "key": "int", + "keyFormat": undefined, + "kind": "dict", + "value": "int", + "valueFormat": undefined, + }, + }, + "as": null, + "ast": { + "as": null, + "id": 26, + "initializer": null, + "kind": "field_decl", + "loc": m: map, + "name": { + "id": 22, + "kind": "id", + "loc": m, + "text": "m", + }, + "type": { + "id": 25, + "keyStorageType": null, + "keyType": { + "id": 23, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "kind": "map_type", + "loc": map, + "valueStorageType": null, + "valueType": { + "id": 24, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + "default": undefined, + "index": 0, + "loc": m: map, + "name": "m", + "type": { + "key": "Int", + "keyAs": null, + "kind": "map", + "value": "Int", + "valueAs": null, + }, + }, + ], + "functions": Map { + "test" => { + "ast": { + "attributes": [], + "id": 33, + "kind": "function_def", + "loc": fun test() { foreach(_, _ in self.m) { } }, + "name": { + "id": 11, + "kind": "id", + "loc": test, + "text": "test", + }, + "params": [], + "return": null, + "statements": [ + { + "id": 32, + "keyName": { + "id": 12, + "kind": "id", + "loc": _, + "text": "_", + }, + "kind": "statement_foreach", + "loc": foreach(_, _ in self.m) { }, + "map": { + "aggregate": { + "id": 30, + "kind": "id", + "loc": self, + "text": "self", + }, + "field": { + "id": 15, + "kind": "id", + "loc": m, + "text": "m", + }, + "id": 31, + "kind": "field_access", + "loc": self.m, + }, + "statements": [], + "valueName": { + "id": 13, + "kind": "id", + "loc": _, + "text": "_", + }, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": true, + "isOverride": false, + "isVirtual": false, + "methodId": null, + "name": "test", + "origin": "user", + "params": [], + "returns": { + "kind": "void", + }, + "self": { + "kind": "ref", + "name": "Test", + "optional": false, + }, + }, + }, + "header": null, + "init": { + "ast": { + "id": 29, + "kind": "contract_init", + "loc": contract Test with TraitWithForeach { + m: map; +}, + "params": [], + "statements": [], + }, + "params": [], + }, + "interfaces": [], + "kind": "contract", + "name": "Test", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait { }, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": null, + "id": 10, + "initializer": null, + "kind": "field_decl", + "loc": m: map, + "name": { + "id": 6, + "kind": "id", + "loc": m, + "text": "m", + }, + "type": { + "id": 9, + "keyStorageType": null, + "keyType": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "kind": "map_type", + "loc": map, + "valueStorageType": null, + "valueType": { + "id": 8, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + { + "attributes": [], + "id": 18, + "kind": "function_def", + "loc": fun test() { foreach(_, _ in self.m) { } }, + "name": { + "id": 11, + "kind": "id", + "loc": test, + "text": "test", + }, + "params": [], + "return": null, + "statements": [ + { + "id": 17, + "keyName": { + "id": 12, + "kind": "id", + "loc": _, + "text": "_", + }, + "kind": "statement_foreach", + "loc": foreach(_, _ in self.m) { }, + "map": { + "aggregate": { + "id": 14, + "kind": "id", + "loc": self, + "text": "self", + }, + "field": { + "id": 15, + "kind": "id", + "loc": m, + "text": "m", + }, + "id": 16, + "kind": "field_access", + "loc": self.m, + }, + "statements": [], + "valueName": { + "id": 13, + "kind": "id", + "loc": _, + "text": "_", + }, + }, + ], + }, + ], + "id": 19, + "kind": "trait", + "loc": trait TraitWithForeach { + m: map; + + fun test() { foreach(_, _ in self.m) { } } +}, + "name": { + "id": 5, + "kind": "id", + "loc": TraitWithForeach, + "text": "TraitWithForeach", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "m", + "type": { + "key": "int", + "keyFormat": undefined, + "kind": "dict", + "value": "int", + "valueFormat": undefined, + }, + }, + "as": null, + "ast": { + "as": null, + "id": 10, + "initializer": null, + "kind": "field_decl", + "loc": m: map, + "name": { + "id": 6, + "kind": "id", + "loc": m, + "text": "m", + }, + "type": { + "id": 9, + "keyStorageType": null, + "keyType": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + "kind": "map_type", + "loc": map, + "valueStorageType": null, + "valueType": { + "id": 8, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + }, + "default": undefined, + "index": 0, + "loc": m: map, + "name": "m", + "type": { + "key": "Int", + "keyAs": null, + "kind": "map", + "value": "Int", + "valueAs": null, + }, + }, + ], + "functions": Map { + "test" => { + "ast": { + "attributes": [], + "id": 18, + "kind": "function_def", + "loc": fun test() { foreach(_, _ in self.m) { } }, + "name": { + "id": 11, + "kind": "id", + "loc": test, + "text": "test", + }, + "params": [], + "return": null, + "statements": [ + { + "id": 17, + "keyName": { + "id": 12, + "kind": "id", + "loc": _, + "text": "_", + }, + "kind": "statement_foreach", + "loc": foreach(_, _ in self.m) { }, + "map": { + "aggregate": { + "id": 14, + "kind": "id", + "loc": self, + "text": "self", + }, + "field": { + "id": 15, + "kind": "id", + "loc": m, + "text": "m", + }, + "id": 16, + "kind": "field_access", + "loc": self.m, + }, + "statements": [], + "valueName": { + "id": 13, + "kind": "id", + "loc": _, + "text": "_", + }, + }, + ], + }, + "isAbstract": false, + "isGetter": false, + "isInline": false, + "isMutating": true, + "isOverride": false, + "isVirtual": false, + "methodId": null, + "name": "test", + "origin": "user", + "params": [], + "returns": { + "kind": "void", + }, + "self": { + "kind": "ref", + "name": "TraitWithForeach", + "optional": false, + }, + }, + }, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "TraitWithForeach", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait { }, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 20892, }, ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "struct", - "name": "SomeStruct", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": "SomeStruct{value:int257}", - "tlb": "_ value:int257 = SomeStruct", - "traits": [], - "uid": 61480, + "uid": 44104, }, ] `; -exports[`resolveDescriptors should resolve descriptors for struct-decl-non-rec-types 2`] = `[]`; +exports[`resolveDescriptors should resolve descriptors for trait-foreach 2`] = `[]`; -exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder 1`] = ` +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 1`] = ` [ { "ast": { - "attributes": [], - "declarations": [], "id": 2, - "kind": "trait", - "loc": trait BaseTrait { }, - "name": { - "id": 1, - "kind": "id", - "loc": BaseTrait, - "text": "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, - }, - { - "ast": { - "id": 4, "kind": "primitive_type_decl", "loc": primitive Int;, "name": { - "id": 3, + "id": 1, "kind": "id", "loc": Int, "text": "Int", @@ -14576,15 +16352,18 @@ exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder }, { "ast": { - "id": 6, - "kind": "primitive_type_decl", - "loc": primitive Cell;, + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, "name": { - "id": 5, + "id": 3, "kind": "id", - "loc": Cell, - "text": "Cell", + "loc": BaseTrait, + "text": "BaseTrait", }, + "traits": [], }, "constants": [], "dependsOn": [], @@ -14593,124 +16372,236 @@ exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder "header": null, "init": null, "interfaces": [], - "kind": "primitive_type_decl", - "name": "Cell", + "kind": "trait", + "name": "BaseTrait", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, "traits": [], - "uid": 26294, + "uid": 1020, }, { "ast": { - "fields": [ + "attributes": [], + "declarations": [ { - "as": null, - "id": 10, + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": a: Int, + "loc": f: Int as int32, "name": { - "id": 8, + "id": 6, "kind": "id", - "loc": a, - "text": "a", + "loc": f, + "text": "f", }, "type": { - "id": 9, + "id": 7, "kind": "type_id", "loc": Int, "text": "Int", }, }, - { - "as": null, - "id": 13, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": b: Int, + "loc": f: Int as int32, "name": { - "id": 11, + "id": 6, "kind": "id", - "loc": b, - "text": "b", + "loc": f, + "text": "f", }, "type": { - "id": 12, + "id": 7, "kind": "type_id", "loc": Int, "text": "Int", }, }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + { + "ast": { + "attributes": [], + "declarations": [ { "as": { - "id": 16, + "id": 15, "kind": "id", - "loc": remaining, - "text": "remaining", + "loc": int32, + "text": "int32", }, - "id": 17, + "id": 16, "initializer": null, "kind": "field_decl", - "loc": s: Cell as remaining, + "loc": f: Int as int32, "name": { - "id": 14, + "id": 13, "kind": "id", - "loc": s, - "text": "s", + "loc": f, + "text": "f", }, "type": { - "id": 15, + "id": 14, "kind": "type_id", - "loc": Cell, - "text": "Cell", + "loc": Int, + "text": "Int", }, }, ], - "id": 18, - "kind": "struct_decl", - "loc": struct Test { - a: Int; - b: Int; - s: Cell as remaining; + "id": 17, + "kind": "trait", + "loc": trait SomeTrait with Foo { + f: Int as int32; }, "name": { - "id": 7, + "id": 11, "kind": "id", - "loc": Test, - "text": "Test", + "loc": SomeTrait, + "text": "SomeTrait", }, + "traits": [ + { + "id": 12, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + ], }, "constants": [], "dependsOn": [], "fields": [ { "abi": { - "name": "a", + "name": "f", "type": { - "format": 257, + "format": 32, "kind": "simple", "optional": false, "type": "int", }, }, - "as": null, + "as": "int32", "ast": { - "as": null, - "id": 10, + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, "initializer": null, "kind": "field_decl", - "loc": a: Int, + "loc": f: Int as int32, "name": { - "id": 8, + "id": 13, "kind": "id", - "loc": a, - "text": "a", + "loc": f, + "text": "f", }, "type": { - "id": 9, + "id": 14, "kind": "type_id", "loc": Int, "text": "Int", @@ -14718,120 +16609,206 @@ exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder }, "default": undefined, "index": 0, - "loc": a: Int, - "name": "a", + "loc": f: Int as int32, + "name": "f", "type": { "kind": "ref", "name": "Int", "optional": false, }, }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "SomeTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ { - "abi": { - "name": "b", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, "ast": { - "as": null, - "id": 13, - "initializer": null, - "kind": "field_decl", - "loc": b: Int, + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, "name": { - "id": 11, + "id": 3, "kind": "id", - "loc": b, - "text": "b", - }, - "type": { - "id": 12, - "kind": "type_id", - "loc": Int, - "text": "Int", + "loc": BaseTrait, + "text": "BaseTrait", }, + "traits": [], }, - "default": undefined, - "index": 1, - "loc": b: Int, - "name": "b", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, + "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, }, { - "abi": { - "name": "s", - "type": { - "format": "remainder", - "kind": "simple", - "optional": false, - "type": "cell", - }, - }, - "as": "remaining", "ast": { - "as": { - "id": 16, - "kind": "id", - "loc": remaining, - "text": "remaining", - }, - "id": 17, - "initializer": null, - "kind": "field_decl", - "loc": s: Cell as remaining, + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait Foo { + f: Int as int32; +}, "name": { - "id": 14, + "id": 5, "kind": "id", - "loc": s, - "text": "s", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, }, - "type": { - "id": 15, - "kind": "type_id", - "loc": Cell, - "text": "Cell", + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, }, - }, - "default": undefined, - "index": 2, - "loc": s: Cell as remaining, - "name": "s", - "type": { - "kind": "ref", - "name": "Cell", - "optional": false, - }, + ], + "uid": 10576, }, ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "struct", - "name": "Test", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": "Test{a:int257,b:int257,s:remainder}", - "tlb": "_ a:int257 b:int257 s:remainder = Test", - "traits": [], - "uid": 44104, + "uid": 8387, }, ] `; -exports[`resolveDescriptors should resolve descriptors for struct-decl-remainder 2`] = `[]`; +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; -exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field-in-diamond-inheritance 1`] = ` [ { "ast": { @@ -14862,46 +16839,15 @@ exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` "traits": [], "uid": 38154, }, - { - "ast": { - "id": 4, - "kind": "primitive_type_decl", - "loc": primitive Bool;, - "name": { - "id": 3, - "kind": "id", - "loc": Bool, - "text": "Bool", - }, - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive_type_decl", - "name": "Bool", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 33424, - }, { "ast": { "attributes": [], "declarations": [], - "id": 6, + "id": 4, "kind": "trait", - "loc": trait BaseTrait { - -}, + "loc": trait BaseTrait {}, "name": { - "id": 5, + "id": 3, "kind": "id", "loc": BaseTrait, "text": "BaseTrait", @@ -14925,315 +16871,318 @@ exports[`resolveDescriptors should resolve descriptors for trait-base 1`] = ` "traits": [], "uid": 1020, }, -] -`; - -exports[`resolveDescriptors should resolve descriptors for trait-base 2`] = `[]`; - -exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` -[ { "ast": { - "id": 2, - "kind": "primitive_type_decl", - "loc": primitive Int;, + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait T { + f1: Int as int32; +}, "name": { - "id": 1, + "id": 5, "kind": "id", - "loc": Int, - "text": "Int", + "loc": T, + "text": "T", }, + "traits": [], }, "constants": [], "dependsOn": [], - "fields": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], "functions": Map {}, "header": null, "init": null, "interfaces": [], - "kind": "primitive_type_decl", - "name": "Int", + "kind": "trait", + "name": "T", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, - "traits": [], - "uid": 38154, - }, - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait { }, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "BaseTrait", + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, }, - "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": 6769, }, { "ast": { "attributes": [], "declarations": [ { - "as": null, - "id": 10, + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, "initializer": null, "kind": "field_decl", - "loc": m: map, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 13, "kind": "id", - "loc": m, - "text": "m", + "loc": f1, + "text": "f1", }, "type": { - "id": 9, - "keyStorageType": null, - "keyType": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - "kind": "map_type", - "loc": map, - "valueStorageType": null, - "valueType": { - "id": 8, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", }, }, { - "attributes": [], - "id": 18, - "kind": "function_def", - "loc": fun test() { foreach(_, _ in self.m) { } }, + "as": { + "id": 19, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 20, + "initializer": null, + "kind": "field_decl", + "loc": f2: Int as int32, "name": { - "id": 11, + "id": 17, "kind": "id", - "loc": test, - "text": "test", + "loc": f2, + "text": "f2", + }, + "type": { + "id": 18, + "kind": "type_id", + "loc": Int, + "text": "Int", }, - "params": [], - "return": null, - "statements": [ - { - "id": 17, - "keyName": { - "id": 12, - "kind": "id", - "loc": _, - "text": "_", - }, - "kind": "statement_foreach", - "loc": foreach(_, _ in self.m) { }, - "map": { - "aggregate": { - "id": 14, - "kind": "id", - "loc": self, - "text": "self", - }, - "field": { - "id": 15, - "kind": "id", - "loc": m, - "text": "m", - }, - "id": 16, - "kind": "field_access", - "loc": self.m, - }, - "statements": [], - "valueName": { - "id": 13, - "kind": "id", - "loc": _, - "text": "_", - }, - }, - ], }, ], - "id": 19, + "id": 21, "kind": "trait", - "loc": trait TraitWithForeach { - m: map; - - fun test() { foreach(_, _ in self.m) { } } + "loc": trait T2 with T { + f1: Int as int32; + f2: Int as int32; }, "name": { - "id": 5, + "id": 11, "kind": "id", - "loc": TraitWithForeach, - "text": "TraitWithForeach", + "loc": T2, + "text": "T2", }, - "traits": [], + "traits": [ + { + "id": 12, + "kind": "id", + "loc": T, + "text": "T", + }, + ], }, "constants": [], "dependsOn": [], "fields": [ { "abi": { - "name": "m", + "name": "f1", "type": { - "key": "int", - "keyFormat": undefined, - "kind": "dict", - "value": "int", - "valueFormat": undefined, + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", }, }, - "as": null, + "as": "int32", "ast": { - "as": null, - "id": 10, + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, "initializer": null, "kind": "field_decl", - "loc": m: map, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 13, "kind": "id", - "loc": m, - "text": "m", + "loc": f1, + "text": "f1", }, "type": { - "id": 9, - "keyStorageType": null, - "keyType": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - "kind": "map_type", - "loc": map, - "valueStorageType": null, - "valueType": { - "id": 8, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", }, }, "default": undefined, "index": 0, - "loc": m: map, - "name": "m", + "loc": f1: Int as int32, + "name": "f1", "type": { - "key": "Int", - "keyAs": null, - "kind": "map", - "value": "Int", - "valueAs": null, + "kind": "ref", + "name": "Int", + "optional": false, }, - }, - ], - "functions": Map { - "test" => { - "ast": { - "attributes": [], - "id": 18, - "kind": "function_def", - "loc": fun test() { foreach(_, _ in self.m) { } }, - "name": { - "id": 11, - "kind": "id", - "loc": test, - "text": "test", - }, - "params": [], - "return": null, - "statements": [ - { - "id": 17, - "keyName": { - "id": 12, - "kind": "id", - "loc": _, - "text": "_", - }, - "kind": "statement_foreach", - "loc": foreach(_, _ in self.m) { }, - "map": { - "aggregate": { - "id": 14, - "kind": "id", - "loc": self, - "text": "self", - }, - "field": { - "id": 15, - "kind": "id", - "loc": m, - "text": "m", - }, - "id": 16, - "kind": "field_access", - "loc": self.m, - }, - "statements": [], - "valueName": { - "id": 13, - "kind": "id", - "loc": _, - "text": "_", - }, - }, - ], + }, + { + "abi": { + "name": "f2", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": true, - "isOverride": false, - "isVirtual": false, - "methodId": null, - "name": "test", - "origin": "user", - "params": [], - "returns": { - "kind": "void", + "as": "int32", + "ast": { + "as": { + "id": 19, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 20, + "initializer": null, + "kind": "field_decl", + "loc": f2: Int as int32, + "name": { + "id": 17, + "kind": "id", + "loc": f2, + "text": "f2", + }, + "type": { + "id": 18, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, }, - "self": { + "default": undefined, + "index": 1, + "loc": f2: Int as int32, + "name": "f2", + "type": { "kind": "ref", - "name": "TraitWithForeach", + "name": "Int", "optional": false, }, }, - }, + ], + "functions": Map {}, "header": null, "init": null, "interfaces": [], "kind": "trait", - "name": "TraitWithForeach", + "name": "T2", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -15246,7 +17195,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "declarations": [], "id": 4, "kind": "trait", - "loc": trait BaseTrait { }, + "loc": trait BaseTrait {}, "name": { "id": 3, "kind": "id", @@ -15272,63 +17221,218 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "traits": [], "uid": 1020, }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait T { + f1: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": T, + "text": "T", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "T", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 6769, + }, ], - "uid": 20892, + "uid": 54378, }, { "ast": { "attributes": [], "declarations": [ { - "as": null, - "id": 26, + "as": { + "id": 26, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 27, "initializer": null, "kind": "field_decl", - "loc": m: map, + "loc": f1: Int as int32, "name": { - "id": 22, + "id": 24, "kind": "id", - "loc": m, - "text": "m", + "loc": f1, + "text": "f1", }, "type": { "id": 25, - "keyStorageType": null, - "keyType": { - "id": 23, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - "kind": "map_type", - "loc": map, - "valueStorageType": null, - "valueType": { - "id": 24, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 30, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 31, + "initializer": null, + "kind": "field_decl", + "loc": f3: Int as int32, + "name": { + "id": 28, + "kind": "id", + "loc": f3, + "text": "f3", + }, + "type": { + "id": 29, + "kind": "type_id", + "loc": Int, + "text": "Int", }, }, ], - "id": 27, - "kind": "contract", - "loc": contract Test with TraitWithForeach { - m: map; + "id": 32, + "kind": "trait", + "loc": trait T3 with T { + f1: Int as int32; + f3: Int as int32; }, "name": { - "id": 20, + "id": 22, "kind": "id", - "loc": Test, - "text": "Test", + "loc": T3, + "text": "T3", }, "traits": [ { - "id": 21, + "id": 23, "kind": "id", - "loc": TraitWithForeach, - "text": "TraitWithForeach", + "loc": T, + "text": "T", }, ], }, @@ -15337,150 +17441,101 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "fields": [ { "abi": { - "name": "m", + "name": "f1", "type": { - "key": "int", - "keyFormat": undefined, - "kind": "dict", - "value": "int", - "valueFormat": undefined, + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", }, }, - "as": null, + "as": "int32", "ast": { - "as": null, - "id": 26, + "as": { + "id": 26, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 27, "initializer": null, "kind": "field_decl", - "loc": m: map, + "loc": f1: Int as int32, "name": { - "id": 22, + "id": 24, "kind": "id", - "loc": m, - "text": "m", + "loc": f1, + "text": "f1", }, "type": { "id": 25, - "keyStorageType": null, - "keyType": { - "id": 23, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - "kind": "map_type", - "loc": map, - "valueStorageType": null, - "valueType": { - "id": 24, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, + "kind": "type_id", + "loc": Int, + "text": "Int", }, }, "default": undefined, "index": 0, - "loc": m: map, - "name": "m", + "loc": f1: Int as int32, + "name": "f1", "type": { - "key": "Int", - "keyAs": null, - "kind": "map", - "value": "Int", - "valueAs": null, + "kind": "ref", + "name": "Int", + "optional": false, }, }, - ], - "functions": Map { - "test" => { + { + "abi": { + "name": "f3", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", "ast": { - "attributes": [], - "id": 33, - "kind": "function_def", - "loc": fun test() { foreach(_, _ in self.m) { } }, + "as": { + "id": 30, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 31, + "initializer": null, + "kind": "field_decl", + "loc": f3: Int as int32, "name": { - "id": 11, + "id": 28, "kind": "id", - "loc": test, - "text": "test", + "loc": f3, + "text": "f3", + }, + "type": { + "id": 29, + "kind": "type_id", + "loc": Int, + "text": "Int", }, - "params": [], - "return": null, - "statements": [ - { - "id": 32, - "keyName": { - "id": 12, - "kind": "id", - "loc": _, - "text": "_", - }, - "kind": "statement_foreach", - "loc": foreach(_, _ in self.m) { }, - "map": { - "aggregate": { - "id": 30, - "kind": "id", - "loc": self, - "text": "self", - }, - "field": { - "id": 15, - "kind": "id", - "loc": m, - "text": "m", - }, - "id": 31, - "kind": "field_access", - "loc": self.m, - }, - "statements": [], - "valueName": { - "id": 13, - "kind": "id", - "loc": _, - "text": "_", - }, - }, - ], - }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": true, - "isOverride": false, - "isVirtual": false, - "methodId": null, - "name": "test", - "origin": "user", - "params": [], - "returns": { - "kind": "void", }, - "self": { + "default": undefined, + "index": 1, + "loc": f3: Int as int32, + "name": "f3", + "type": { "kind": "ref", - "name": "Test", + "name": "Int", "optional": false, }, }, - }, + ], + "functions": Map {}, "header": null, - "init": { - "ast": { - "id": 29, - "kind": "contract_init", - "loc": contract Test with TraitWithForeach { - m: map; -}, - "params": [], - "statements": [], - }, - "params": [], - }, + "init": null, "interfaces": [], - "kind": "contract", - "name": "Test", + "kind": "trait", + "name": "T3", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -15493,7 +17548,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "declarations": [], "id": 4, "kind": "trait", - "loc": trait BaseTrait { }, + "loc": trait BaseTrait {}, "name": { "id": 3, "kind": "id", @@ -15508,117 +17563,56 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "functions": Map {}, "header": null, "init": null, - "interfaces": [], - "kind": "trait", - "name": "BaseTrait", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 10, - "initializer": null, - "kind": "field_decl", - "loc": m: map, - "name": { - "id": 6, - "kind": "id", - "loc": m, - "text": "m", - }, - "type": { - "id": 9, - "keyStorageType": null, - "keyType": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - "kind": "map_type", - "loc": map, - "valueStorageType": null, - "valueType": { - "id": 8, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - }, - { - "attributes": [], - "id": 18, - "kind": "function_def", - "loc": fun test() { foreach(_, _ in self.m) { } }, - "name": { - "id": 11, - "kind": "id", - "loc": test, - "text": "test", - }, - "params": [], - "return": null, - "statements": [ - { - "id": 17, - "keyName": { - "id": 12, - "kind": "id", - "loc": _, - "text": "_", - }, - "kind": "statement_foreach", - "loc": foreach(_, _ in self.m) { }, - "map": { - "aggregate": { - "id": 14, - "kind": "id", - "loc": self, - "text": "self", - }, - "field": { - "id": 15, - "kind": "id", - "loc": m, - "text": "m", - }, - "id": 16, - "kind": "field_access", - "loc": self.m, - }, - "statements": [], - "valueName": { - "id": 13, - "kind": "id", - "loc": _, - "text": "_", - }, - }, - ], + "interfaces": [], + "kind": "trait", + "name": "BaseTrait", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 1020, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, }, ], - "id": 19, + "id": 10, "kind": "trait", - "loc": trait TraitWithForeach { - m: map; - - fun test() { foreach(_, _ in self.m) { } } + "loc": trait T { + f1: Int as int32; }, "name": { "id": 5, "kind": "id", - "loc": TraitWithForeach, - "text": "TraitWithForeach", + "loc": T, + "text": "T", }, "traits": [], }, @@ -15627,139 +17621,56 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "fields": [ { "abi": { - "name": "m", + "name": "f1", "type": { - "key": "int", - "keyFormat": undefined, - "kind": "dict", - "value": "int", - "valueFormat": undefined, + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", }, }, - "as": null, + "as": "int32", "ast": { - "as": null, - "id": 10, + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": m: map, + "loc": f1: Int as int32, "name": { "id": 6, "kind": "id", - "loc": m, - "text": "m", + "loc": f1, + "text": "f1", }, "type": { - "id": 9, - "keyStorageType": null, - "keyType": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - "kind": "map_type", - "loc": map, - "valueStorageType": null, - "valueType": { - "id": 8, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", }, }, "default": undefined, "index": 0, - "loc": m: map, - "name": "m", + "loc": f1: Int as int32, + "name": "f1", "type": { - "key": "Int", - "keyAs": null, - "kind": "map", - "value": "Int", - "valueAs": null, - }, - }, - ], - "functions": Map { - "test" => { - "ast": { - "attributes": [], - "id": 18, - "kind": "function_def", - "loc": fun test() { foreach(_, _ in self.m) { } }, - "name": { - "id": 11, - "kind": "id", - "loc": test, - "text": "test", - }, - "params": [], - "return": null, - "statements": [ - { - "id": 17, - "keyName": { - "id": 12, - "kind": "id", - "loc": _, - "text": "_", - }, - "kind": "statement_foreach", - "loc": foreach(_, _ in self.m) { }, - "map": { - "aggregate": { - "id": 14, - "kind": "id", - "loc": self, - "text": "self", - }, - "field": { - "id": 15, - "kind": "id", - "loc": m, - "text": "m", - }, - "id": 16, - "kind": "field_access", - "loc": self.m, - }, - "statements": [], - "valueName": { - "id": 13, - "kind": "id", - "loc": _, - "text": "_", - }, - }, - ], - }, - "isAbstract": false, - "isGetter": false, - "isInline": false, - "isMutating": true, - "isOverride": false, - "isVirtual": false, - "methodId": null, - "name": "test", - "origin": "user", - "params": [], - "returns": { - "kind": "void", - }, - "self": { "kind": "ref", - "name": "TraitWithForeach", + "name": "Int", "optional": false, }, }, - }, + ], + "functions": Map {}, "header": null, "init": null, "interfaces": [], "kind": "trait", - "name": "TraitWithForeach", + "name": "T", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -15772,7 +17683,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "declarations": [], "id": 4, "kind": "trait", - "loc": trait BaseTrait { }, + "loc": trait BaseTrait {}, "name": { "id": 3, "kind": "id", @@ -15792,85 +17703,17 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` "name": "BaseTrait", "origin": "user", "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 1020, - }, - ], - "uid": 20892, - }, - ], - "uid": 44104, - }, -] -`; - -exports[`resolveDescriptors should resolve descriptors for trait-foreach 2`] = `[]`; - -exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 1`] = ` -[ - { - "ast": { - "id": 2, - "kind": "primitive_type_decl", - "loc": primitive Int;, - "name": { - "id": 1, - "kind": "id", - "loc": Int, - "text": "Int", - }, - }, - "constants": [], - "dependsOn": [], - "fields": [], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "primitive_type_decl", - "name": "Int", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [], - "uid": 38154, - }, - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 1020, + }, + ], + "uid": 6769, + }, + ], + "uid": 50251, }, { "ast": { @@ -15878,48 +17721,111 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "declarations": [ { "as": { - "id": 8, + "id": 38, "kind": "id", "loc": int32, "text": "int32", }, - "id": 9, + "id": 39, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 36, "kind": "id", - "loc": f, - "text": "f", + "loc": f1, + "text": "f1", }, "type": { - "id": 7, + "id": 37, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 42, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 43, + "initializer": null, + "kind": "field_decl", + "loc": f2: Int as int32, + "name": { + "id": 40, + "kind": "id", + "loc": f2, + "text": "f2", + }, + "type": { + "id": 41, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 46, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 47, + "initializer": null, + "kind": "field_decl", + "loc": f3: Int as int32, + "name": { + "id": 44, + "kind": "id", + "loc": f3, + "text": "f3", + }, + "type": { + "id": 45, "kind": "type_id", "loc": Int, "text": "Int", }, }, ], - "id": 10, + "id": 48, "kind": "trait", - "loc": trait Foo { - f: Int as int32; + "loc": trait SomeTrait with T2, T3 { + f1: Int as int32; + f2: Int as int32; + f3: Int as int32; }, "name": { - "id": 5, + "id": 33, "kind": "id", - "loc": Foo, - "text": "Foo", + "loc": SomeTrait, + "text": "SomeTrait", }, - "traits": [], + "traits": [ + { + "id": 34, + "kind": "id", + "loc": T2, + "text": "T2", + }, + { + "id": 35, + "kind": "id", + "loc": T3, + "text": "T3", + }, + ], }, "constants": [], "dependsOn": [], "fields": [ { "abi": { - "name": "f", + "name": "f1", "type": { "format": 32, "kind": "simple", @@ -15930,23 +17836,23 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "as": "int32", "ast": { "as": { - "id": 8, + "id": 38, "kind": "id", "loc": int32, "text": "int32", }, - "id": 9, + "id": 39, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 36, "kind": "id", - "loc": f, - "text": "f", + "loc": f1, + "text": "f1", }, "type": { - "id": 7, + "id": 37, "kind": "type_id", "loc": Int, "text": "Int", @@ -15954,117 +17860,62 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f: Int as int32, - "name": "f", + "loc": f1: Int as int32, + "name": "f1", "type": { "kind": "ref", "name": "Int", "optional": false, }, }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "Foo", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "BaseTrait", + "abi": { + "name": "f2", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", }, - "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": 10576, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { + "as": "int32", + "ast": { "as": { - "id": 15, + "id": 42, "kind": "id", "loc": int32, "text": "int32", }, - "id": 16, + "id": 43, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f2: Int as int32, "name": { - "id": 13, + "id": 40, "kind": "id", - "loc": f, - "text": "f", + "loc": f2, + "text": "f2", }, "type": { - "id": 14, + "id": 41, "kind": "type_id", "loc": Int, "text": "Int", }, }, - ], - "id": 17, - "kind": "trait", - "loc": trait SomeTrait with Foo { - f: Int as int32; -}, - "name": { - "id": 11, - "kind": "id", - "loc": SomeTrait, - "text": "SomeTrait", - }, - "traits": [ - { - "id": 12, - "kind": "id", - "loc": Foo, - "text": "Foo", + "default": undefined, + "index": 1, + "loc": f2: Int as int32, + "name": "f2", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, }, - ], - }, - "constants": [], - "dependsOn": [], - "fields": [ + }, { "abi": { - "name": "f", + "name": "f3", "type": { "format": 32, "kind": "simple", @@ -16075,32 +17926,32 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "as": "int32", "ast": { "as": { - "id": 15, + "id": 46, "kind": "id", "loc": int32, "text": "int32", }, - "id": 16, + "id": 47, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f3: Int as int32, "name": { - "id": 13, + "id": 44, "kind": "id", - "loc": f, - "text": "f", + "loc": f3, + "text": "f3", }, "type": { - "id": 14, + "id": 45, "kind": "type_id", "loc": Int, "text": "Int", }, }, "default": undefined, - "index": 0, - "loc": f: Int as int32, - "name": "f", + "index": 2, + "loc": f3: Int as int32, + "name": "f3", "type": { "kind": "ref", "name": "Int", @@ -16158,48 +18009,125 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "declarations": [ { "as": { - "id": 8, + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 19, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 20, + "initializer": null, + "kind": "field_decl", + "loc": f2: Int as int32, + "name": { + "id": 17, + "kind": "id", + "loc": f2, + "text": "f2", + }, + "type": { + "id": 18, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 21, + "kind": "trait", + "loc": trait T2 with T { + f1: Int as int32; + f2: Int as int32; +}, + "name": { + "id": 11, + "kind": "id", + "loc": T2, + "text": "T2", + }, + "traits": [ + { + "id": 12, + "kind": "id", + "loc": T, + "text": "T", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 15, "kind": "id", "loc": int32, "text": "int32", }, - "id": 9, + "id": 16, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 13, "kind": "id", - "loc": f, - "text": "f", + "loc": f1, + "text": "f1", }, "type": { - "id": 7, + "id": 14, "kind": "type_id", "loc": Int, "text": "Int", }, }, - ], - "id": 10, - "kind": "trait", - "loc": trait Foo { - f: Int as int32; -}, - "name": { - "id": 5, - "kind": "id", - "loc": Foo, - "text": "Foo", + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ { "abi": { - "name": "f", + "name": "f2", "type": { "format": 32, "kind": "simple", @@ -16210,32 +18138,32 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "as": "int32", "ast": { "as": { - "id": 8, + "id": 19, "kind": "id", "loc": int32, "text": "int32", }, - "id": 9, + "id": 20, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f2: Int as int32, "name": { - "id": 6, + "id": 17, "kind": "id", - "loc": f, - "text": "f", + "loc": f2, + "text": "f2", }, "type": { - "id": 7, + "id": 18, "kind": "type_id", "loc": Int, "text": "Int", }, }, "default": undefined, - "index": 0, - "loc": f: Int as int32, - "name": "f", + "index": 1, + "loc": f2: Int as int32, + "name": "f2", "type": { "kind": "ref", "name": "Int", @@ -16248,7 +18176,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "init": null, "interfaces": [], "kind": "trait", - "name": "Foo", + "name": "T2", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -16287,164 +18215,284 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "traits": [], "uid": 1020, }, - ], - "uid": 10576, - }, - ], - "uid": 8387, - }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": { - "id": 22, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 23, - "initializer": null, - "kind": "field_decl", - "loc": f: Int as int32, - "name": { - "id": 20, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 21, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 24, - "kind": "contract", - "loc": contract SomeContract with Foo { - f: Int as int32; + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait T { + f1: Int as int32; }, - "name": { - "id": 18, - "kind": "id", - "loc": SomeContract, - "text": "SomeContract", - }, - "traits": [ - { - "id": 19, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - ], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 32, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": "int32", - "ast": { - "as": { - "id": 22, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 23, - "initializer": null, - "kind": "field_decl", - "loc": f: Int as int32, - "name": { - "id": 20, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 21, - "kind": "type_id", - "loc": Int, - "text": "Int", + "name": { + "id": 5, + "kind": "id", + "loc": T, + "text": "T", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "T", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 6769, }, - }, - "default": undefined, - "index": 0, - "loc": f: Int as int32, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": { - "ast": { - "id": 26, - "kind": "contract_init", - "loc": contract SomeContract with Foo { - f: Int as int32; -}, - "params": [], - "statements": [], + ], + "uid": 54378, }, - "params": [], - }, - "interfaces": [], - "kind": "contract", - "name": "SomeContract", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ { "ast": { "attributes": [], - "declarations": [], - "id": 4, + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, "kind": "trait", - "loc": trait BaseTrait {}, + "loc": trait T { + f1: Int as int32; +}, "name": { - "id": 3, + "id": 5, "kind": "id", - "loc": BaseTrait, - "text": "BaseTrait", + "loc": T, + "text": "T", }, "traits": [], }, "constants": [], "dependsOn": [], - "fields": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], "functions": Map {}, "header": null, "init": null, "interfaces": [], "kind": "trait", - "name": "BaseTrait", + "name": "T", "origin": "user", "partialFieldCount": 0, "receivers": [], "signature": null, "tlb": null, - "traits": [], - "uid": 1020, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 6769, }, { "ast": { @@ -16452,48 +18500,80 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "declarations": [ { "as": { - "id": 8, + "id": 26, "kind": "id", "loc": int32, "text": "int32", }, - "id": 9, + "id": 27, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 24, "kind": "id", - "loc": f, - "text": "f", + "loc": f1, + "text": "f1", }, "type": { - "id": 7, + "id": 25, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 30, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 31, + "initializer": null, + "kind": "field_decl", + "loc": f3: Int as int32, + "name": { + "id": 28, + "kind": "id", + "loc": f3, + "text": "f3", + }, + "type": { + "id": 29, "kind": "type_id", "loc": Int, "text": "Int", }, }, ], - "id": 10, + "id": 32, "kind": "trait", - "loc": trait Foo { - f: Int as int32; + "loc": trait T3 with T { + f1: Int as int32; + f3: Int as int32; }, "name": { - "id": 5, + "id": 22, "kind": "id", - "loc": Foo, - "text": "Foo", + "loc": T3, + "text": "T3", }, - "traits": [], + "traits": [ + { + "id": 23, + "kind": "id", + "loc": T, + "text": "T", + }, + ], }, "constants": [], "dependsOn": [], "fields": [ { "abi": { - "name": "f", + "name": "f1", "type": { "format": 32, "kind": "simple", @@ -16504,23 +18584,23 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "as": "int32", "ast": { "as": { - "id": 8, + "id": 26, "kind": "id", "loc": int32, "text": "int32", }, - "id": 9, + "id": 27, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f1: Int as int32, "name": { - "id": 6, + "id": 24, "kind": "id", - "loc": f, - "text": "f", + "loc": f1, + "text": "f1", }, "type": { - "id": 7, + "id": 25, "kind": "type_id", "loc": Int, "text": "Int", @@ -16528,8 +18608,53 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f: Int as int32, - "name": "f", + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + { + "abi": { + "name": "f3", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 30, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 31, + "initializer": null, + "kind": "field_decl", + "loc": f3: Int as int32, + "name": { + "id": 28, + "kind": "id", + "loc": f3, + "text": "f3", + }, + "type": { + "id": 29, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 1, + "loc": f3: Int as int32, + "name": "f3", "type": { "kind": "ref", "name": "Int", @@ -16542,7 +18667,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "init": null, "interfaces": [], "kind": "trait", - "name": "Foo", + "name": "T3", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -16581,16 +18706,154 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "traits": [], "uid": 1020, }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait T { + f1: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": T, + "text": "T", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "T", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 6769, + }, ], - "uid": 10576, + "uid": 50251, }, ], - "uid": 59799, + "uid": 8387, }, ] `; -exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field-in-diamond-inheritance 2`] = `[]`; exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` [ diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 7ccc24926..91817bd78 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1548,10 +1548,9 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { ); } else if (f.as !== null && f.as !== ex.as) { const expected = `${printTypeRef(f.type)} as ${f.as}`; - let actual = printTypeRef(ex.type); - if (ex.as !== null) { - actual += ` as ${ex.as}`; - } + const actual = + printTypeRef(ex.type) + + (ex.as !== null ? ` as ${ex.as}` : ""); throwCompilationError( `Trait "${tr.name}" requires field "${f.name}" of type "${expected}", but "${actual}" given`, diff --git a/src/types/test-failed/trait-with-as-typed-field-in-diamond-inheritance-and-other-specialization.tact b/src/types/test-failed/trait-with-as-typed-field-in-diamond-inheritance-and-other-specialization.tact new file mode 100644 index 000000000..69bb2360c --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-field-in-diamond-inheritance-and-other-specialization.tact @@ -0,0 +1,23 @@ +primitive Int; + +trait BaseTrait {} + +trait T { + f1: Int as int32; +} + +trait T2 with T { + f1: Int as int32; + f2: Int as int32; +} + +trait T3 with T { + f1: Int as int32; + f3: Int as int32; +} + +trait SomeTrait with T2, T3 { + f1: Int as int32; + f2: Int as int16; + f3: Int as int32; +} diff --git a/src/types/test/contract-with-as-typed-field.tact b/src/types/test/contract-with-as-typed-field.tact new file mode 100644 index 000000000..342f16a34 --- /dev/null +++ b/src/types/test/contract-with-as-typed-field.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int32; +} + +contract SomeContract with Foo { + f: Int as int32; +} diff --git a/src/types/test/trait-with-as-typed-field-in-diamond-inheritance.tact b/src/types/test/trait-with-as-typed-field-in-diamond-inheritance.tact new file mode 100644 index 000000000..32937ff13 --- /dev/null +++ b/src/types/test/trait-with-as-typed-field-in-diamond-inheritance.tact @@ -0,0 +1,23 @@ +primitive Int; + +trait BaseTrait {} + +trait T { + f1: Int as int32; +} + +trait T2 with T { + f1: Int as int32; + f2: Int as int32; +} + +trait T3 with T { + f1: Int as int32; + f3: Int as int32; +} + +trait SomeTrait with T2, T3 { + f1: Int as int32; + f2: Int as int32; + f3: Int as int32; +} diff --git a/src/types/test/trait-with-as-typed-field.tact b/src/types/test/trait-with-as-typed-field.tact index 9245fd6de..83b36de7b 100644 --- a/src/types/test/trait-with-as-typed-field.tact +++ b/src/types/test/trait-with-as-typed-field.tact @@ -9,7 +9,3 @@ trait Foo { trait SomeTrait with Foo { f: Int as int32; } - -contract SomeContract with Foo { - f: Int as int32; -} From 8b92b387508eeee2eac9c00dc87372b24f2c4bb9 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:44:22 +0400 Subject: [PATCH 09/12] forbid `field: Int as int32` in child for `field: Int` in trait and add more tests --- .../resolveDescriptors.spec.ts.snap | 1255 ++++++++++------- src/types/resolveDescriptors.ts | 25 +- ...out-as-typed-field-inherited-with-it.tact} | 4 - ...hout-as-typed-field-inherited-with-it.tact | 11 + ...nheritance-with-as-typed-int257-field.tact | 11 + ...-with-inheritance-without-typed-field.tact | 11 + 6 files changed, 788 insertions(+), 529 deletions(-) rename src/types/{test/trait-without-as-typed-field-inherited-with-it.tact => test-failed/contract-without-as-typed-field-inherited-with-it.tact} (70%) create mode 100644 src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact create mode 100644 src/types/test/trait-int-field-with-inheritance-with-as-typed-int257-field.tact create mode 100644 src/types/test/trait-with-as-typed-int257-field-with-inheritance-without-typed-field.tact diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 8ef90a74c..cfb3b5cbe 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -320,6 +320,16 @@ Line 13, col 3: " `; +exports[`resolveDescriptors should fail descriptors for contract-without-as-typed-field-inherited-with-it 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int", but "Int as coins" given +Line 10, col 5: + 9 | contract SomeContract with Foo { +> 10 | f: Int as coins; + ^~~~~~~~~~~~~~~ + 11 | } +" +`; + exports[`resolveDescriptors should fail descriptors for expr-bitwise-not-bool-in-const1 1`] = ` ":4:16: Invalid type "Bool" for unary operator "~" Line 4, col 16: @@ -740,6 +750,16 @@ Line 6, col 5: " `; +exports[`resolveDescriptors should fail descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` +":10:5: Trait "Foo" requires field "f" of type "Int", but "Int as int32" given +Line 10, col 5: + 9 | trait SomeTrait with Foo { +> 10 | f: Int as int32; + ^~~~~~~~~~~~~~~ + 11 | } +" +`; + exports[`resolveDescriptors should fail descriptors for wf-type-const 1`] = ` ":4:19: Invalid map type. Check https://docs.tact-lang.org/book/maps#allowed-types Line 4, col 19: @@ -16319,7 +16339,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-foreach 1`] = ` exports[`resolveDescriptors should resolve descriptors for trait-foreach 2`] = `[]`; -exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 1`] = ` +exports[`resolveDescriptors should resolve descriptors for trait-int-field-with-inheritance-with-as-typed-int257-field 1`] = ` [ { "ast": { @@ -16387,16 +16407,11 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "attributes": [], "declarations": [ { - "as": { - "id": 8, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 9, + "as": null, + "id": 8, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int, "name": { "id": 6, "kind": "id", @@ -16411,10 +16426,10 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, }, ], - "id": 10, + "id": 9, "kind": "trait", "loc": trait Foo { - f: Int as int32; + f: Int; }, "name": { "id": 5, @@ -16431,24 +16446,19 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "abi": { "name": "f", "type": { - "format": 32, + "format": 257, "kind": "simple", "optional": false, "type": "int", }, }, - "as": "int32", + "as": null, "ast": { - "as": { - "id": 8, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 9, + "as": null, + "id": 8, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int, "name": { "id": 6, "kind": "id", @@ -16464,7 +16474,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f: Int as int32, + "loc": f: Int, "name": "f", "type": { "kind": "ref", @@ -16526,43 +16536,43 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "declarations": [ { "as": { - "id": 15, + "id": 14, "kind": "id", - "loc": int32, - "text": "int32", + "loc": int257, + "text": "int257", }, - "id": 16, + "id": 15, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int as int257, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 14, + "id": 13, "kind": "type_id", "loc": Int, "text": "Int", }, }, ], - "id": 17, + "id": 16, "kind": "trait", "loc": trait SomeTrait with Foo { - f: Int as int32; + f: Int as int257; }, "name": { - "id": 11, + "id": 10, "kind": "id", "loc": SomeTrait, "text": "SomeTrait", }, "traits": [ { - "id": 12, + "id": 11, "kind": "id", "loc": Foo, "text": "Foo", @@ -16576,32 +16586,32 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "abi": { "name": "f", "type": { - "format": 32, + "format": 257, "kind": "simple", "optional": false, "type": "int", }, }, - "as": "int32", + "as": "int257", "ast": { "as": { - "id": 15, + "id": 14, "kind": "id", - "loc": int32, - "text": "int32", + "loc": int257, + "text": "int257", }, - "id": 16, + "id": 15, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int as int257, "name": { - "id": 13, + "id": 12, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 14, + "id": 13, "kind": "type_id", "loc": Int, "text": "Int", @@ -16609,7 +16619,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f: Int as int32, + "loc": f: Int as int257, "name": "f", "type": { "kind": "ref", @@ -16667,16 +16677,11 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "attributes": [], "declarations": [ { - "as": { - "id": 8, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 9, + "as": null, + "id": 8, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int, "name": { "id": 6, "kind": "id", @@ -16691,10 +16696,10 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, }, ], - "id": 10, + "id": 9, "kind": "trait", "loc": trait Foo { - f: Int as int32; + f: Int; }, "name": { "id": 5, @@ -16711,24 +16716,19 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "abi": { "name": "f", "type": { - "format": 32, + "format": 257, "kind": "simple", "optional": false, "type": "int", }, }, - "as": "int32", + "as": null, "ast": { - "as": { - "id": 8, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 9, + "as": null, + "id": 8, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int, "name": { "id": 6, "kind": "id", @@ -16744,7 +16744,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f: Int as int32, + "loc": f: Int, "name": "f", "type": { "kind": "ref", @@ -16806,9 +16806,9 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f ] `; -exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; +exports[`resolveDescriptors should resolve descriptors for trait-int-field-with-inheritance-with-as-typed-int257-field 2`] = `[]`; -exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field-in-diamond-inheritance 1`] = ` +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 1`] = ` [ { "ast": { @@ -16885,12 +16885,12 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "id": 9, "initializer": null, "kind": "field_decl", - "loc": f1: Int as int32, + "loc": f: Int as int32, "name": { "id": 6, "kind": "id", - "loc": f1, - "text": "f1", + "loc": f, + "text": "f", }, "type": { "id": 7, @@ -16902,14 +16902,14 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f ], "id": 10, "kind": "trait", - "loc": trait T { - f1: Int as int32; + "loc": trait Foo { + f: Int as int32; }, "name": { "id": 5, "kind": "id", - "loc": T, - "text": "T", + "loc": Foo, + "text": "Foo", }, "traits": [], }, @@ -16918,7 +16918,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "fields": [ { "abi": { - "name": "f1", + "name": "f", "type": { "format": 32, "kind": "simple", @@ -16937,12 +16937,12 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "id": 9, "initializer": null, "kind": "field_decl", - "loc": f1: Int as int32, + "loc": f: Int as int32, "name": { "id": 6, "kind": "id", - "loc": f1, - "text": "f1", + "loc": f, + "text": "f", }, "type": { "id": 7, @@ -16953,8 +16953,8 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f1: Int as int32, - "name": "f1", + "loc": f: Int as int32, + "name": "f", "type": { "kind": "ref", "name": "Int", @@ -16967,7 +16967,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "init": null, "interfaces": [], "kind": "trait", - "name": "T", + "name": "Foo", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -17007,7 +17007,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "uid": 1020, }, ], - "uid": 6769, + "uid": 10576, }, { "ast": { @@ -17023,12 +17023,12 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "id": 16, "initializer": null, "kind": "field_decl", - "loc": f1: Int as int32, + "loc": f: Int as int32, "name": { "id": 13, "kind": "id", - "loc": f1, - "text": "f1", + "loc": f, + "text": "f", }, "type": { "id": 14, @@ -17037,49 +17037,24 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "text": "Int", }, }, - { - "as": { - "id": 19, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 20, - "initializer": null, - "kind": "field_decl", - "loc": f2: Int as int32, - "name": { - "id": 17, - "kind": "id", - "loc": f2, - "text": "f2", - }, - "type": { - "id": 18, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, ], - "id": 21, + "id": 17, "kind": "trait", - "loc": trait T2 with T { - f1: Int as int32; - f2: Int as int32; + "loc": trait SomeTrait with Foo { + f: Int as int32; }, "name": { "id": 11, "kind": "id", - "loc": T2, - "text": "T2", + "loc": SomeTrait, + "text": "SomeTrait", }, "traits": [ { "id": 12, "kind": "id", - "loc": T, - "text": "T", + "loc": Foo, + "text": "Foo", }, ], }, @@ -17088,7 +17063,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "fields": [ { "abi": { - "name": "f1", + "name": "f", "type": { "format": 32, "kind": "simple", @@ -17107,12 +17082,12 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "id": 16, "initializer": null, "kind": "field_decl", - "loc": f1: Int as int32, + "loc": f: Int as int32, "name": { "id": 13, "kind": "id", - "loc": f1, - "text": "f1", + "loc": f, + "text": "f", }, "type": { "id": 14, @@ -17123,53 +17098,8 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f }, "default": undefined, "index": 0, - "loc": f1: Int as int32, - "name": "f1", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - { - "abi": { - "name": "f2", - "type": { - "format": 32, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": "int32", - "ast": { - "as": { - "id": 19, - "kind": "id", - "loc": int32, - "text": "int32", - }, - "id": 20, - "initializer": null, - "kind": "field_decl", - "loc": f2: Int as int32, - "name": { - "id": 17, - "kind": "id", - "loc": f2, - "text": "f2", - }, - "type": { - "id": 18, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 1, - "loc": f2: Int as int32, - "name": "f2", + "loc": f: Int as int32, + "name": "f", "type": { "kind": "ref", "name": "Int", @@ -17182,7 +17112,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "init": null, "interfaces": [], "kind": "trait", - "name": "T2", + "name": "SomeTrait", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -17235,12 +17165,12 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f "id": 9, "initializer": null, "kind": "field_decl", - "loc": f1: Int as int32, + "loc": f: Int as int32, "name": { "id": 6, "kind": "id", - "loc": f1, - "text": "f1", + "loc": f, + "text": "f", }, "type": { "id": 7, @@ -17252,7 +17182,566 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f ], "id": 10, "kind": "trait", - "loc": trait T { + "loc": trait Foo { + f: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f, + "text": "f", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f: Int as int32, + "name": "f", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "Foo", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 10576, + }, + ], + "uid": 8387, + }, +] +`; + +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field 2`] = `[]`; + +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field-in-diamond-inheritance 1`] = ` +[ + { + "ast": { + "id": 2, + "kind": "primitive_type_decl", + "loc": primitive Int;, + "name": { + "id": 1, + "kind": "id", + "loc": Int, + "text": "Int", + }, + }, + "constants": [], + "dependsOn": [], + "fields": [], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "primitive_type_decl", + "name": "Int", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [], + "uid": 38154, + }, + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait T { + f1: Int as int32; +}, + "name": { + "id": 5, + "kind": "id", + "loc": T, + "text": "T", + }, + "traits": [], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "T", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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": 6769, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 19, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 20, + "initializer": null, + "kind": "field_decl", + "loc": f2: Int as int32, + "name": { + "id": 17, + "kind": "id", + "loc": f2, + "text": "f2", + }, + "type": { + "id": 18, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 21, + "kind": "trait", + "loc": trait T2 with T { + f1: Int as int32; + f2: Int as int32; +}, + "name": { + "id": 11, + "kind": "id", + "loc": T2, + "text": "T2", + }, + "traits": [ + { + "id": 12, + "kind": "id", + "loc": T, + "text": "T", + }, + ], + }, + "constants": [], + "dependsOn": [], + "fields": [ + { + "abi": { + "name": "f1", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 15, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 16, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 13, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 0, + "loc": f1: Int as int32, + "name": "f1", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + { + "abi": { + "name": "f2", + "type": { + "format": 32, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + "as": "int32", + "ast": { + "as": { + "id": 19, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 20, + "initializer": null, + "kind": "field_decl", + "loc": f2: Int as int32, + "name": { + "id": 17, + "kind": "id", + "loc": f2, + "text": "f2", + }, + "type": { + "id": 18, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + "default": undefined, + "index": 1, + "loc": f2: Int as int32, + "name": "f2", + "type": { + "kind": "ref", + "name": "Int", + "optional": false, + }, + }, + ], + "functions": Map {}, + "header": null, + "init": null, + "interfaces": [], + "kind": "trait", + "name": "T2", + "origin": "user", + "partialFieldCount": 0, + "receivers": [], + "signature": null, + "tlb": null, + "traits": [ + { + "ast": { + "attributes": [], + "declarations": [], + "id": 4, + "kind": "trait", + "loc": trait BaseTrait {}, + "name": { + "id": 3, + "kind": "id", + "loc": BaseTrait, + "text": "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, + }, + { + "ast": { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": int32, + "text": "int32", + }, + "id": 9, + "initializer": null, + "kind": "field_decl", + "loc": f1: Int as int32, + "name": { + "id": 6, + "kind": "id", + "loc": f1, + "text": "f1", + }, + "type": { + "id": 7, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 10, + "kind": "trait", + "loc": trait T { f1: Int as int32; }, "name": { @@ -18855,7 +19344,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-f exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-field-in-diamond-inheritance 2`] = `[]`; -exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-int257-field-with-inheritance-without-typed-field 1`] = ` [ { "ast": { @@ -18918,182 +19407,47 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "traits": [], "uid": 1020, }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 9, - "kind": "trait", - "loc": trait Foo { - f: Int; -}, - "name": { - "id": 5, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, - "ast": { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "Foo", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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": 10576, - }, { "ast": { "attributes": [], "declarations": [ { "as": { - "id": 14, + "id": 8, "kind": "id", - "loc": int32, - "text": "int32", + "loc": int257, + "text": "int257", }, - "id": 15, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int as int257, "name": { - "id": 12, + "id": 6, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 13, + "id": 7, "kind": "type_id", "loc": Int, "text": "Int", }, }, ], - "id": 16, + "id": 10, "kind": "trait", - "loc": trait SomeTrait with Foo { - f: Int as int32; + "loc": trait Foo { + f: Int as int257; }, "name": { - "id": 10, + "id": 5, "kind": "id", - "loc": SomeTrait, - "text": "SomeTrait", + "loc": Foo, + "text": "Foo", }, - "traits": [ - { - "id": 11, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - ], + "traits": [], }, "constants": [], "dependsOn": [], @@ -19102,32 +19456,32 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "abi": { "name": "f", "type": { - "format": 32, + "format": 257, "kind": "simple", "optional": false, "type": "int", }, }, - "as": "int32", + "as": "int257", "ast": { "as": { - "id": 14, + "id": 8, "kind": "id", - "loc": int32, - "text": "int32", + "loc": int257, + "text": "int257", }, - "id": 15, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": f: Int as int32, + "loc": f: Int as int257, "name": { - "id": 12, + "id": 6, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 13, + "id": 7, "kind": "type_id", "loc": Int, "text": "Int", @@ -19135,7 +19489,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type }, "default": undefined, "index": 0, - "loc": f: Int as int32, + "loc": f: Int as int257, "name": "f", "type": { "kind": "ref", @@ -19149,7 +19503,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "init": null, "interfaces": [], "kind": "trait", - "name": "SomeTrait", + "name": "Foo", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -19188,180 +19542,47 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "traits": [], "uid": 1020, }, - { - "ast": { - "attributes": [], - "declarations": [ - { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - ], - "id": 9, - "kind": "trait", - "loc": trait Foo { - f: Int; -}, - "name": { - "id": 5, - "kind": "id", - "loc": Foo, - "text": "Foo", - }, - "traits": [], - }, - "constants": [], - "dependsOn": [], - "fields": [ - { - "abi": { - "name": "f", - "type": { - "format": 257, - "kind": "simple", - "optional": false, - "type": "int", - }, - }, - "as": null, - "ast": { - "as": null, - "id": 8, - "initializer": null, - "kind": "field_decl", - "loc": f: Int, - "name": { - "id": 6, - "kind": "id", - "loc": f, - "text": "f", - }, - "type": { - "id": 7, - "kind": "type_id", - "loc": Int, - "text": "Int", - }, - }, - "default": undefined, - "index": 0, - "loc": f: Int, - "name": "f", - "type": { - "kind": "ref", - "name": "Int", - "optional": false, - }, - }, - ], - "functions": Map {}, - "header": null, - "init": null, - "interfaces": [], - "kind": "trait", - "name": "Foo", - "origin": "user", - "partialFieldCount": 0, - "receivers": [], - "signature": null, - "tlb": null, - "traits": [ - { - "ast": { - "attributes": [], - "declarations": [], - "id": 4, - "kind": "trait", - "loc": trait BaseTrait {}, - "name": { - "id": 3, - "kind": "id", - "loc": BaseTrait, - "text": "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": 10576, - }, ], - "uid": 8387, + "uid": 10576, }, { "ast": { "attributes": [], "declarations": [ { - "as": { - "id": 21, - "kind": "id", - "loc": coins, - "text": "coins", - }, - "id": 22, + "as": null, + "id": 15, "initializer": null, "kind": "field_decl", - "loc": f: Int as coins, + "loc": f: Int, "name": { - "id": 19, + "id": 13, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 20, + "id": 14, "kind": "type_id", "loc": Int, "text": "Int", }, }, ], - "id": 23, - "kind": "contract", - "loc": contract SomeContract with Foo { - f: Int as coins; + "id": 16, + "kind": "trait", + "loc": trait SomeTrait with Foo { + f: Int; }, "name": { - "id": 17, + "id": 11, "kind": "id", - "loc": SomeContract, - "text": "SomeContract", + "loc": SomeTrait, + "text": "SomeTrait", }, "traits": [ { - "id": 18, + "id": 12, "kind": "id", "loc": Foo, "text": "Foo", @@ -19375,32 +19596,27 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "abi": { "name": "f", "type": { - "format": "coins", + "format": 257, "kind": "simple", "optional": false, - "type": "uint", + "type": "int", }, }, - "as": "coins", + "as": null, "ast": { - "as": { - "id": 21, - "kind": "id", - "loc": coins, - "text": "coins", - }, - "id": 22, + "as": null, + "id": 15, "initializer": null, "kind": "field_decl", - "loc": f: Int as coins, + "loc": f: Int, "name": { - "id": 19, + "id": 13, "kind": "id", "loc": f, "text": "f", }, "type": { - "id": 20, + "id": 14, "kind": "type_id", "loc": Int, "text": "Int", @@ -19408,7 +19624,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type }, "default": undefined, "index": 0, - "loc": f: Int as coins, + "loc": f: Int, "name": "f", "type": { "kind": "ref", @@ -19419,21 +19635,10 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type ], "functions": Map {}, "header": null, - "init": { - "ast": { - "id": 25, - "kind": "contract_init", - "loc": contract SomeContract with Foo { - f: Int as coins; -}, - "params": [], - "statements": [], - }, - "params": [], - }, + "init": null, "interfaces": [], - "kind": "contract", - "name": "SomeContract", + "kind": "trait", + "name": "SomeTrait", "origin": "user", "partialFieldCount": 0, "receivers": [], @@ -19477,11 +19682,16 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "attributes": [], "declarations": [ { - "as": null, - "id": 8, + "as": { + "id": 8, + "kind": "id", + "loc": int257, + "text": "int257", + }, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": f: Int, + "loc": f: Int as int257, "name": { "id": 6, "kind": "id", @@ -19496,10 +19706,10 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type }, }, ], - "id": 9, + "id": 10, "kind": "trait", "loc": trait Foo { - f: Int; + f: Int as int257; }, "name": { "id": 5, @@ -19522,13 +19732,18 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "type": "int", }, }, - "as": null, + "as": "int257", "ast": { - "as": null, - "id": 8, + "as": { + "id": 8, + "kind": "id", + "loc": int257, + "text": "int257", + }, + "id": 9, "initializer": null, "kind": "field_decl", - "loc": f: Int, + "loc": f: Int as int257, "name": { "id": 6, "kind": "id", @@ -19544,7 +19759,7 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type }, "default": undefined, "index": 0, - "loc": f: Int, + "loc": f: Int as int257, "name": "f", "type": { "kind": "ref", @@ -19601,9 +19816,9 @@ exports[`resolveDescriptors should resolve descriptors for trait-without-as-type "uid": 10576, }, ], - "uid": 59799, + "uid": 8387, }, ] `; -exports[`resolveDescriptors should resolve descriptors for trait-without-as-typed-field-inherited-with-it 2`] = `[]`; +exports[`resolveDescriptors should resolve descriptors for trait-with-as-typed-int257-field-with-inheritance-without-typed-field 2`] = `[]`; diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 91817bd78..746f78ff6 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1512,6 +1512,10 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { // Verify trait fields // + function printFieldTypeRefWithAs(ex: FieldDescription) { + return printTypeRef(ex.type) + (ex.as !== null ? ` as ${ex.as}` : ""); + } + for (const t of types.values()) { for (const tr of t.traits) { // Check that trait is valid @@ -1546,11 +1550,22 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { `Trait "${tr.name}" requires field "${f.name}" of type "${printTypeRef(f.type)}"`, t.ast.loc, ); - } else if (f.as !== null && f.as !== ex.as) { - const expected = `${printTypeRef(f.type)} as ${f.as}`; - const actual = - printTypeRef(ex.type) + - (ex.as !== null ? ` as ${ex.as}` : ""); + } else if ( + (f.as !== null || ex.as !== null) && + f.as !== ex.as + ) { + if ( + (ex.as === "int257" && f.as === null) || + (ex.as === null && f.as === "int257") + ) { + // allow overriding: + // - `f: Int` with `f: Int as int257` + // - `f: Int as int257` with `f: Int` + continue; + } + + const expected = printFieldTypeRefWithAs(f); + const actual = printFieldTypeRefWithAs(ex); throwCompilationError( `Trait "${tr.name}" requires field "${f.name}" of type "${expected}", but "${actual}" given`, diff --git a/src/types/test/trait-without-as-typed-field-inherited-with-it.tact b/src/types/test-failed/contract-without-as-typed-field-inherited-with-it.tact similarity index 70% rename from src/types/test/trait-without-as-typed-field-inherited-with-it.tact rename to src/types/test-failed/contract-without-as-typed-field-inherited-with-it.tact index fca6c2baa..1d277be61 100644 --- a/src/types/test/trait-without-as-typed-field-inherited-with-it.tact +++ b/src/types/test-failed/contract-without-as-typed-field-inherited-with-it.tact @@ -6,10 +6,6 @@ trait Foo { f: Int; } -trait SomeTrait with Foo { - f: Int as int32; -} - contract SomeContract with Foo { f: Int as coins; } diff --git a/src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact b/src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact new file mode 100644 index 000000000..fd39cf806 --- /dev/null +++ b/src/types/test-failed/trait-without-as-typed-field-inherited-with-it.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int; +} + +trait SomeTrait with Foo { + f: Int as int32; +} diff --git a/src/types/test/trait-int-field-with-inheritance-with-as-typed-int257-field.tact b/src/types/test/trait-int-field-with-inheritance-with-as-typed-int257-field.tact new file mode 100644 index 000000000..ad79be994 --- /dev/null +++ b/src/types/test/trait-int-field-with-inheritance-with-as-typed-int257-field.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int; +} + +trait SomeTrait with Foo { + f: Int as int257; +} diff --git a/src/types/test/trait-with-as-typed-int257-field-with-inheritance-without-typed-field.tact b/src/types/test/trait-with-as-typed-int257-field-with-inheritance-without-typed-field.tact new file mode 100644 index 000000000..1d8272396 --- /dev/null +++ b/src/types/test/trait-with-as-typed-int257-field-with-inheritance-without-typed-field.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Foo { + f: Int as int257; +} + +trait SomeTrait with Foo { + f: Int; +} From 56adfe483b2f1e8528ecb9896042683765987b68 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:51:43 +0400 Subject: [PATCH 10/12] added explicit `as coins` to `Jetton` trait --- src/test/e2e-emulated/contracts/sample-jetton.tact | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/e2e-emulated/contracts/sample-jetton.tact b/src/test/e2e-emulated/contracts/sample-jetton.tact index a24daf289..a47d6bd05 100644 --- a/src/test/e2e-emulated/contracts/sample-jetton.tact +++ b/src/test/e2e-emulated/contracts/sample-jetton.tact @@ -51,8 +51,8 @@ contract SampleJetton with Jetton { // ============================================================================================================ // @interface("org.ton.jetton.master") trait Jetton with Ownable { - totalSupply: Int; // Already set initially - max_supply: Int; + totalSupply: Int as coins; // Already set initially + max_supply: Int as coins; mintable: Bool; owner: Address; content: Cell; @@ -331,4 +331,4 @@ struct JettonWalletData { owner: Address; master: Address; walletCode: Cell; -} \ No newline at end of file +} From 73be6c8c77c0079c85615bbf114fa5cbfa48d135 Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:00:13 +0400 Subject: [PATCH 11/12] simplified condition --- src/types/resolveDescriptors.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 746f78ff6..dd41e4c73 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1551,19 +1551,10 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { t.ast.loc, ); } else if ( - (f.as !== null || ex.as !== null) && - f.as !== ex.as + f.as !== ex.as && + f.as !== "int257" && + ex.as !== "int257" ) { - if ( - (ex.as === "int257" && f.as === null) || - (ex.as === null && f.as === "int257") - ) { - // allow overriding: - // - `f: Int` with `f: Int as int257` - // - `f: Int as int257` with `f: Int` - continue; - } - const expected = printFieldTypeRefWithAs(f); const actual = printFieldTypeRefWithAs(ex); From d44943e3297db5508110a7209b95a6973f2c62fe Mon Sep 17 00:00:00 2001 From: i582 <51853996+i582@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:33:49 +0400 Subject: [PATCH 12/12] fixed case with `f: Int as int257` and `f: Int as coins` --- .../__snapshots__/resolveDescriptors.spec.ts.snap | 10 ++++++++++ src/types/resolveDescriptors.ts | 6 ++++-- ...257-field-for-trait-with-as-typed-coins-field.tact | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/types/test-failed/trait-with-as-typed-int257-field-for-trait-with-as-typed-coins-field.tact diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index cfb3b5cbe..027e1f1af 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -750,6 +750,16 @@ Line 6, col 5: " `; +exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-int257-field-for-trait-with-as-typed-coins-field 1`] = ` +":10:5: Trait "Trait" requires field "i" of type "Int as int257", but "Int as coins" given +Line 10, col 5: + 9 | contract Foo with Trait { +> 10 | i: Int as coins = 0; + ^~~~~~~~~~~~~~~~~~~ + 11 | } +" +`; + exports[`resolveDescriptors should fail descriptors for trait-without-as-typed-field-inherited-with-it 1`] = ` ":10:5: Trait "Foo" requires field "f" of type "Int", but "Int as int32" given Line 10, col 5: diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index dd41e4c73..6f24e8037 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -1552,8 +1552,10 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) { ); } else if ( f.as !== ex.as && - f.as !== "int257" && - ex.as !== "int257" + !( + (f.as === "int257" && ex.as === null) || + (f.as === null && ex.as === "int257") + ) ) { const expected = printFieldTypeRefWithAs(f); const actual = printFieldTypeRefWithAs(ex); diff --git a/src/types/test-failed/trait-with-as-typed-int257-field-for-trait-with-as-typed-coins-field.tact b/src/types/test-failed/trait-with-as-typed-int257-field-for-trait-with-as-typed-coins-field.tact new file mode 100644 index 000000000..2721eebb3 --- /dev/null +++ b/src/types/test-failed/trait-with-as-typed-int257-field-for-trait-with-as-typed-coins-field.tact @@ -0,0 +1,11 @@ +primitive Int; + +trait BaseTrait {} + +trait Trait { + i: Int as int257; +} + +contract Foo with Trait { + i: Int as coins = 0; +}