Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(traits): error on circular trait dependencies #1452

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support `AstTypedParameter` AST node in pretty printer: PR [#1347](https://github.com/tact-lang/tact/pull/1347)
- Show stacktrace of a compiler error only in verbose mode: PR [#1375](https://github.com/tact-lang/tact/pull/1375)
- Flag name in help (`--project` to `--projects`): PR [#1419](https://github.com/tact-lang/tact/pull/1419)
- Error on circular trait dependencies: PR [#1452](https://github.com/tact-lang/tact/pull/1452)

### Docs

Expand Down
18 changes: 18 additions & 0 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,24 @@ exports[`resolveDescriptors should fail descriptors for struct-decl-self-referen
"
`;

exports[`resolveDescriptors should fail descriptors for trait-circular-deps 1`] = `
"<unknown>:3:1: Circular dependency detected for type "A"
2 |
> 3 | trait A with B {}
^~~~~~~~~~~~~~~~~
4 | trait B with A {}
"
`;

exports[`resolveDescriptors should fail descriptors for trait-circular-deps-with-deep-inheritance 1`] = `
"<unknown>:3:1: Circular dependency detected for type "A"
2 |
> 3 | trait A with B {}
^~~~~~~~~~~~~~~~~
4 | trait B with C {}
"
`;

exports[`resolveDescriptors should fail descriptors for trait-duplicates-in-trait-list 1`] = `
"<unknown>:7:1: The list of inherited traits for trait "Test" has duplicates
6 |
Expand Down
2 changes: 1 addition & 1 deletion src/types/resolveDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) {
types.get(name)!.ast.loc,
);
}
processing.has(name);
processing.add(name);

// Process dependencies first
const dependencies = Array.from(types.values()).filter((v) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait BaseTrait {}

trait A with B {}
trait B with C {}
trait C with D {}
trait D with A {}

contract Test with A {}
6 changes: 6 additions & 0 deletions src/types/test-failed/trait-circular-deps.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait BaseTrait {}

trait A with B {}
trait B with A {}

contract Test with A {}
Loading