Skip to content

Commit a41a598

Browse files
authored
fix(typechecker): self-inheritance case for contracts and traits (#3094)
1 parent 3edfc39 commit a41a598

File tree

8 files changed

+82
-8
lines changed

8 files changed

+82
-8
lines changed

dev-docs/CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- [fix] Added fixed-bytes support to bounced message size calculations
10+
### Language features
11+
12+
- [fix] Disallow self-inheritance for contracts and traits: PR [#3094](https://github.com/tact-lang/tact/pull/3094)
13+
- [fix] Added fixed-bytes support to bounced message size calculations: PR [#3129](https://github.com/tact-lang/tact/pull/3129)
1114

1215
### Docs
1316

1417
- Changed the title of the "Gas-expensive" badge to "500+ gas" to avoid confusion when discussing relative gas-efficiency: PR [#3120](https://github.com/tact-lang/tact/pull/3120)
1518

19+
### Release contributors
20+
21+
- [hazyone](https://github.com/hazyone)
22+
- [lordivash](https://github.com/lordivash)
23+
- [Novus Nota](https://github.com/novusnota)
24+
1625
## [1.6.10] - 2025-05-16
1726

1827
### Infrastructure
1928

2029
- [fix] Explicit dependencies to fix Blueprint integration: PR [#3088](https://github.com/tact-lang/tact/pull/3088)
2130

31+
### Release contributors
32+
33+
- [Petr Makhnev](https://github.com/i582)
34+
- [verytactical](https://github.com/verytactical)
35+
2236
## [1.6.9] - 2025-05-16
2337

2438
### TypeScript third-party API

spell/cspell-list.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cheatsheet
2222
Cheatsheet
2323
cheatsheets
2424
Cheatsheets
25+
chksgn
2526
cleanall
2627
CNFT
2728
codegen
@@ -30,7 +31,6 @@ Compilables
3031
comptime
3132
Comptime
3233
CSBT
33-
chksgn
3434
Daniil
3535
Danil
3636
decompilation
@@ -42,18 +42,18 @@ decompiles
4242
decompiling
4343
dentry
4444
Descr
45+
dictpush
4546
disasm
4647
divmod
4748
dnsresolve
4849
Domínguez
4950
dstr
50-
dictpush
5151
elseifnot
5252
Eltociear
5353
Epva
5454
errno
55-
Excno
5655
Esorat
56+
Excno
5757
extracurrency
5858
flamegraph
5959
flamegraphs
@@ -67,6 +67,7 @@ Georgiy
6767
getsimpleforwardfee
6868
gettest
6969
guarantor
70+
hazyone
7071
Héctor
7172
hehe
7273
heisenbugs
@@ -79,8 +80,8 @@ infixl
7980
infixr
8081
initof
8182
injectivity
82-
Ints
8383
Intelli
84+
Ints
8485
ipfs
8586
IPFS
8687
ipld
@@ -107,6 +108,7 @@ Liskov
107108
llm
108109
llms
109110
logomark
111+
lordivash
110112
lparen
111113
lvalue
112114
lvalues

src/types/__snapshots__/resolveDescriptors.spec.ts.snap

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,24 @@ exports[`resolveDescriptors should fail descriptors for contract-receiver-struct
315315
"
316316
`;
317317

318+
exports[`resolveDescriptors should fail descriptors for contract-self-inheritance-combined 1`] = `
319+
"<unknown>:7:1: Self-inheritance is not allowed
320+
6 | contract B {}
321+
> 7 | contract C with A, B, C {}
322+
^~~~~~~~~~~~~~~~~~~~~~~~~~
323+
8 |
324+
"
325+
`;
326+
327+
exports[`resolveDescriptors should fail descriptors for contract-with-self-inheritance 1`] = `
328+
"<unknown>:5:1: Self-inheritance is not allowed
329+
4 |
330+
> 5 | contract A with A {
331+
^~~~~~~~~~~~~~~~~~~
332+
6 | }
333+
"
334+
`;
335+
318336
exports[`resolveDescriptors should fail descriptors for contract-without-as-typed-field-inherited-with-it 1`] = `
319337
"<unknown>:10:5: Trait "Foo" requires field "f" of type "Int", but "Int as coins" given
320338
9 | contract SomeContract with Foo {
@@ -1338,6 +1356,23 @@ exports[`resolveDescriptors should fail descriptors for trait-with-as-typed-int2
13381356
"
13391357
`;
13401358

1359+
exports[`resolveDescriptors should fail descriptors for trait-with-self-inheritance 1`] = `
1360+
"<unknown>:1:1: Self-inheritance is not allowed
1361+
> 1 | trait A with A {
1362+
^~~~~~~~~~~~~~~~
1363+
2 | }
1364+
"
1365+
`;
1366+
1367+
exports[`resolveDescriptors should fail descriptors for trait-with-self-inheritance-combined 1`] = `
1368+
"<unknown>:3:1: Self-inheritance is not allowed
1369+
2 | trait B {}
1370+
> 3 | trait C with A, B, C {}
1371+
^~~~~~~~~~~~~~~~~~~~~~~
1372+
4 |
1373+
"
1374+
`;
1375+
13411376
exports[`resolveDescriptors should fail descriptors for trait-without-as-typed-field-inherited-with-it 1`] = `
13421377
"<unknown>:10:5: Trait "Foo" requires field "f" of type "Int", but "Int as int32" given
13431378
9 | trait SomeTrait with Foo {

src/types/resolveDescriptors.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,10 +1638,14 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) {
16381638
// Check there are no duplicates in the _immediately_ inherited traits
16391639
const traitSet: Set<string> = new Set(t.ast.traits.map(idText));
16401640
if (traitSet.size !== t.ast.traits.length) {
1641-
const aggregateType =
1642-
t.ast.kind === "contract" ? "contract" : "trait";
16431641
throwCompilationError(
1644-
`The list of inherited traits for ${aggregateType} "${t.name}" has duplicates`,
1642+
`The list of inherited traits for ${t.ast.kind} "${t.name}" has duplicates`,
1643+
t.ast.loc,
1644+
);
1645+
}
1646+
if (traitSet.has(t.name)) {
1647+
throwCompilationError(
1648+
`Self-inheritance is not allowed`,
16451649
t.ast.loc,
16461650
);
16471651
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait BaseTrait {
2+
3+
}
4+
5+
contract A {}
6+
contract B {}
7+
contract C with A, B, C {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait BaseTrait {
2+
3+
}
4+
5+
contract A with A {
6+
}
7+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait A {}
2+
trait B {}
3+
trait C with A, B, C {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait A with A {
2+
}

0 commit comments

Comments
 (0)