From 7fbe9a2b369f9406f40c97afedc25ce65ec6682b Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:20:16 +0300 Subject: [PATCH] test: extension functions are not allowed inside contracts/traits (#1344) --- .../resolveDescriptors.spec.ts.snap | 38 +++++++++++++++++++ ...fun-cannot-be-defined-within-contract.tact | 4 ++ ...nd-fun-cannot-be-defined-within-trait.tact | 4 ++ .../test-failed/extend-fun-missing-type.tact | 3 ++ ...-fun-must-have-at-least-one-parameter.tact | 2 + 5 files changed, 51 insertions(+) create mode 100644 src/types/test-failed/extend-fun-cannot-be-defined-within-contract.tact create mode 100644 src/types/test-failed/extend-fun-cannot-be-defined-within-trait.tact create mode 100644 src/types/test-failed/extend-fun-missing-type.tact create mode 100644 src/types/test-failed/extend-fun-must-have-at-least-one-parameter.tact diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 8aee4a3a1..c4e541a92 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -348,6 +348,44 @@ Line 4, col 17: " `; +exports[`resolveDescriptors should fail descriptors for extend-fun-cannot-be-defined-within-contract 1`] = ` +":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`] = ` +":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`] = ` +":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`] = ` +":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`] = ` ":8:1: Getters must be defined within a contract Line 8, col 1: diff --git a/src/types/test-failed/extend-fun-cannot-be-defined-within-contract.tact b/src/types/test-failed/extend-fun-cannot-be-defined-within-contract.tact new file mode 100644 index 000000000..ef09c5ab3 --- /dev/null +++ b/src/types/test-failed/extend-fun-cannot-be-defined-within-contract.tact @@ -0,0 +1,4 @@ +primitive Int; +contract Foo { + extends fun Bar(self: Int, a: Int): Int {} +} \ No newline at end of file diff --git a/src/types/test-failed/extend-fun-cannot-be-defined-within-trait.tact b/src/types/test-failed/extend-fun-cannot-be-defined-within-trait.tact new file mode 100644 index 000000000..c5f776b60 --- /dev/null +++ b/src/types/test-failed/extend-fun-cannot-be-defined-within-trait.tact @@ -0,0 +1,4 @@ +primitive Int; +trait Foo { + extends fun Bar(self: Int, a: Int): Int {} +} \ No newline at end of file diff --git a/src/types/test-failed/extend-fun-missing-type.tact b/src/types/test-failed/extend-fun-missing-type.tact new file mode 100644 index 000000000..fb3050b8a --- /dev/null +++ b/src/types/test-failed/extend-fun-missing-type.tact @@ -0,0 +1,3 @@ +extends fun Foo(self: String): Bar { + return ""; +} \ No newline at end of file diff --git a/src/types/test-failed/extend-fun-must-have-at-least-one-parameter.tact b/src/types/test-failed/extend-fun-must-have-at-least-one-parameter.tact new file mode 100644 index 000000000..41aee3efb --- /dev/null +++ b/src/types/test-failed/extend-fun-must-have-at-least-one-parameter.tact @@ -0,0 +1,2 @@ +primitive Int; +extends fun Bar(): Int {} \ No newline at end of file