Skip to content

Commit

Permalink
fix: Prohibited empty inherited trait lists
Browse files Browse the repository at this point in the history
See: #247
  • Loading branch information
novusnota committed Apr 13, 2024
1 parent 7145b5d commit 1e6e0a1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Update the `dump` function to handle addresses: PR [#175](https://github.com/tact-lang/tact/pull/175)
- Support trailing commas in all comma-separated lists (struct instance fields, `initOf` arguments, `init()` parameters, inherited traits via `with`, function arguments and parameters): PR [#179](https://github.com/tact-lang/tact/pull/179) and PR [#246](https://github.com/tact-lang/tact/pull/246)
- Support trailing commas in all comma-separated lists (struct instantiations, `initOf` arguments, `init()` parameters, inherited traits via `with`, function arguments and parameters): PR [#179](https://github.com/tact-lang/tact/pull/179) and PR [#246](https://github.com/tact-lang/tact/pull/246)
- The implicit empty `init` function is now present by default in the contract if not declared: PR [#167](https://github.com/tact-lang/tact/pull/167)
- `@stdlib/stoppable` now imports `@stdlib/ownable` so the programmer does not have to do it separately: PR [#193](https://github.com/tact-lang/tact/pull/193)
- Support escape sequences for strings (`\\`, `\"`, `\n`, `\r`, `\t`, `\v`, `\b`, `\f`, `\u{0}` through `\u{FFFFFF}`, `\u0000` through `\uFFFF`, `\x00` through `\xFF`): PR [#192](https://github.com/tact-lang/tact/pull/192)
Expand All @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Incorrect "already exists" errors when using names such as `toString` or `valueOf`: PR [#208](https://github.com/tact-lang/tact/pull/208)
- Escape backticks in error messages for generated TypeScript code: PR [#192](https://github.com/tact-lang/tact/pull/192)
- Empty inherited trait lists after `with` keyword are now disallowed: PR [#246](https://github.com/tact-lang/tact/pull/246)

## [1.2.0] - 2024-02-29

Expand Down
22 changes: 20 additions & 2 deletions src/grammar/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Line 2, col 31:
`;
exports[`grammar should fail case-27 1`] = `
"<unknown>:1:19: Empty inherited traits list should not have a dangling comma.
"<unknown>:1:19: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 19:
> 1 | contract Name with, {}
^
Expand All @@ -264,7 +264,7 @@ Line 1, col 19:
`;
exports[`grammar should fail case-28 1`] = `
"<unknown>:1:16: Empty inherited traits list should not have a dangling comma.
"<unknown>:1:16: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 16:
> 1 | trait Name with, {}
^
Expand All @@ -282,6 +282,24 @@ Line 2, col 10:
"
`;
exports[`grammar should fail case-30 1`] = `
"<unknown>:1:20: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 20:
> 1 | contract Name with {}
^
2 |
"
`;
exports[`grammar should fail case-31 1`] = `
"<unknown>:1:17: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 17:
> 1 | trait Name with {}
^
2 |
"
`;
exports[`grammar should parse case-0 1`] = `
{
"entries": [
Expand Down
4 changes: 2 additions & 2 deletions src/grammar/grammar.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Tact {

// Contract
Contract = ContractAttribute* contract id "{" ContractBody* "}" --simple
| ContractAttribute* contract id with ListOf<id,","> ","? "{" ContractBody* "}" --withTraits
| ContractAttribute* contract id with NonemptyListOf<id,","> ","? "{" ContractBody* "}" --withTraits
ContractInit = "init" "(" ListOf<FunctionArg,","> ","? ")" "{" Statement* "}"
ContractBody = Field
| ContractInit
Expand All @@ -55,7 +55,7 @@ Tact {

// Trait
Trait = ContractAttribute* trait id "{" TraitBody* "}" --originary
| ContractAttribute* trait id with ListOf<id,","> ","? "{" TraitBody* "}" --withTraits
| ContractAttribute* trait id with NonemptyListOf<id,","> ","? "{" TraitBody* "}" --withTraits
TraitBody = Field
| ReceiveFunction
| Function
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/grammar.ohm-bundle.js

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,11 @@ semantics.addOperation<ASTNode>("resolve_program_item", {
arg2,
_arg3,
arg4,
arg5,
_arg5,
_arg6,
arg7,
_arg8,
) {
if (arg4.source.contents === "" && arg5.sourceString === ",") {
throwError(
"Empty inherited traits list should not have a dangling comma.",
createRef(arg5),
);
}

checkVariableName(arg2.sourceString, createRef(arg2));
return createNode({
kind: "def_contract",
Expand Down Expand Up @@ -154,14 +147,17 @@ semantics.addOperation<ASTNode>("resolve_program_item", {
ref: createRef(this),
});
},
Trait_withTraits(arg0, _arg1, arg2, _arg3, arg4, arg5, _arg6, arg7, _arg8) {
if (arg4.source.contents === "" && arg5.sourceString === ",") {
throwError(
"Empty inherited traits list should not have a dangling comma.",
createRef(arg5),
);
}

Trait_withTraits(
arg0,
_arg1,
arg2,
_arg3,
arg4,
_arg5,
_arg6,
arg7,
_arg8,
) {
checkVariableName(arg2.sourceString, createRef(arg2));
return createNode({
kind: "def_trait",
Expand Down
1 change: 1 addition & 0 deletions src/grammar/test-failed/case-30.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contract Name with {}
1 change: 1 addition & 0 deletions src/grammar/test-failed/case-31.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trait Name with {}

0 comments on commit 1e6e0a1

Please sign in to comment.