Skip to content

Commit

Permalink
test: extension functions are not allowed inside contracts/traits (#1344
Browse files Browse the repository at this point in the history
)
  • Loading branch information
xpyctumo authored Jan 15, 2025
1 parent 90b1f35 commit 7fbe9a2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,44 @@ Line 4, col 17:
"
`;

exports[`resolveDescriptors should fail descriptors for extend-fun-cannot-be-defined-within-contract 1`] = `
"<unknown>:3:5: Extend functions cannot be defined within a contract
Line 3, col 5:
2 | contract Foo {
> 3 | extends fun Bar(self: Int, a: Int): Int {}
^~~~~~~
4 | }
"
`;

exports[`resolveDescriptors should fail descriptors for extend-fun-cannot-be-defined-within-trait 1`] = `
"<unknown>:3:5: Extend functions cannot be defined within a contract
Line 3, col 5:
2 | trait Foo {
> 3 | extends fun Bar(self: Int, a: Int): Int {}
^~~~~~~
4 | }
"
`;

exports[`resolveDescriptors should fail descriptors for extend-fun-missing-type 1`] = `
"<unknown>:1:32: Type "Bar" not found
Line 1, col 32:
> 1 | extends fun Foo(self: String): Bar {
^~~
2 | return "";
"
`;

exports[`resolveDescriptors should fail descriptors for extend-fun-must-have-at-least-one-parameter 1`] = `
"<unknown>:2:1: Extend functions must have at least one parameter
Line 2, col 1:
1 | primitive Int;
> 2 | extends fun Bar(): Int {}
^~~~~~~
"
`;

exports[`resolveDescriptors should fail descriptors for getter-outside-contract 1`] = `
"<unknown>:8:1: Getters must be defined within a contract
Line 8, col 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitive Int;
contract Foo {
extends fun Bar(self: Int, a: Int): Int {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
primitive Int;
trait Foo {
extends fun Bar(self: Int, a: Int): Int {}
}
3 changes: 3 additions & 0 deletions src/types/test-failed/extend-fun-missing-type.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends fun Foo(self: String): Bar {
return "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
primitive Int;
extends fun Bar(): Int {}

0 comments on commit 7fbe9a2

Please sign in to comment.