plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
805d96d
— Peter John
2026-08-09T21:07:14+05:30
test: migrate plum-checker/plum-wasm-codegen fixtures off <Receiver> syntax
- examples/methods.plum +6 -6
- plum-checker/tests/checker_tests.rs +10 -15
- plum-wasm-codegen/tests/codegen_tests.rs +20 -20
examples/methods.plum
CHANGED
|
@@ -2,18 +2,18 @@ type Cat =
|
|
|
2
2
|
name: Str
|
|
3
3
|
age: Int
|
|
4
4
|
|
|
5
|
-
fun getAge
|
|
5
|
+
fun getAge(self) -> Int =
|
|
6
|
-
|
|
6
|
+
self.age
|
|
7
7
|
|
|
8
|
-
fun birthday
|
|
8
|
+
fun birthday(self) -> Int =
|
|
9
|
-
|
|
9
|
+
self.age + 1
|
|
10
10
|
|
|
11
11
|
type Wrapper =
|
|
12
12
|
inner: Cat
|
|
13
13
|
tag: Int
|
|
14
14
|
|
|
15
|
-
fun innerAge
|
|
15
|
+
fun innerAge(self) -> Int =
|
|
16
|
-
|
|
16
|
+
self.inner.age
|
|
17
17
|
|
|
18
18
|
fun makeCat() -> Cat =
|
|
19
19
|
Cat(name: "Whiskers", age: 3)
|
plum-checker/tests/checker_tests.rs
CHANGED
|
@@ -101,7 +101,7 @@ fn bool_literal_wrong_return_type_is_error() {
|
|
|
101
101
|
|
|
102
102
|
#[test]
|
|
103
103
|
fn method_self_field_access_passes() {
|
|
104
|
-
let src = "type Cat =\n name: Str\n age: Int\n\
|
|
104
|
+
let src = "type Cat =\n name: Str\n age: Int\n\n fun getName() -> Str =\n self.name\n";
|
|
105
105
|
let source = parse(src);
|
|
106
106
|
let result = check_source(&source);
|
|
107
107
|
assert!(result.is_ok(), "expected Ok, got {:?}", result.err());
|
|
@@ -116,21 +116,16 @@ fn method_self_unknown_field_is_error() {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
#[test]
|
|
119
|
-
fn
|
|
119
|
+
fn nested_method_type_checks() {
|
|
120
|
-
let
|
|
120
|
+
let src = "type Cat =\n name: Str\n age: Int\n\n fun getName(self) -> Str =\n self.name\n";
|
|
121
|
-
let top_level_src = "type Cat =\n name: Str\n age: Int\n\nfun getName<Cat>() -> Str =\n self.name\n";
|
|
122
|
-
let
|
|
121
|
+
let result = check_source(&parse(src));
|
|
123
|
-
let top_level_result = check_source(&parse(top_level_src));
|
|
124
|
-
assert!(
|
|
122
|
+
assert!(result.is_ok(), "expected Ok, got {:?}", result.err());
|
|
125
|
-
assert!(top_level_result.is_ok(), "expected Ok, got {:?}", top_level_result.err());
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
#[test]
|
|
129
|
-
fn
|
|
126
|
+
fn nested_method_unknown_field_is_error() {
|
|
130
|
-
let
|
|
127
|
+
let src = "type Cat =\n name: Str\n\n fun getAge(self) -> Int =\n self.age\n";
|
|
131
|
-
let top_level_src = "type Cat =\n name: Str\n\nfun getAge<Cat>() -> Int =\n self.age\n";
|
|
132
|
-
assert!(check_source(&parse(
|
|
128
|
+
assert!(check_source(&parse(src)).is_err());
|
|
133
|
-
assert!(check_source(&parse(top_level_src)).is_err());
|
|
134
129
|
}
|
|
135
130
|
|
|
136
131
|
#[test]
|
|
@@ -705,8 +700,8 @@ type Cat =
|
|
|
705
700
|
name: Str
|
|
706
701
|
age: Int
|
|
707
702
|
|
|
708
|
-
fun haveBirthday
|
|
703
|
+
fun haveBirthday() =
|
|
709
|
-
|
|
704
|
+
self.age = self.age + 1
|
|
710
705
|
";
|
|
711
706
|
let source = parse(src);
|
|
712
707
|
assert!(check_source(&source).is_ok(), "expected Ok");
|
plum-wasm-codegen/tests/codegen_tests.rs
CHANGED
|
@@ -150,8 +150,8 @@ type Cat =
|
|
|
150
150
|
name: Str
|
|
151
151
|
age: Int
|
|
152
152
|
|
|
153
|
-
fun getAge
|
|
153
|
+
fun getAge() -> Int =
|
|
154
|
-
|
|
154
|
+
self.age
|
|
155
155
|
|
|
156
156
|
fun makeCat() -> Int =
|
|
157
157
|
c = Cat(name: \"x\", age: 3)
|
|
@@ -391,8 +391,8 @@ type Cat =
|
|
|
391
391
|
name: Str
|
|
392
392
|
age: Int
|
|
393
393
|
|
|
394
|
-
fun getAge
|
|
394
|
+
fun getAge() -> Int =
|
|
395
|
-
|
|
395
|
+
self.age
|
|
396
396
|
|
|
397
397
|
fun main() -> Int =
|
|
398
398
|
c = Cat(name: \"x\", age: 7)
|
|
@@ -759,12 +759,12 @@ enum Option =
|
|
|
759
759
|
type Box =
|
|
760
760
|
value: Option
|
|
761
761
|
|
|
762
|
-
fun unwrap
|
|
762
|
+
fun unwrap(default: Int) -> Int =
|
|
763
|
-
|
|
763
|
+
match self.value
|
|
764
|
-
|
|
764
|
+
Some(v) =>
|
|
765
|
-
|
|
765
|
+
return v
|
|
766
|
-
|
|
766
|
+
None =>
|
|
767
|
-
|
|
767
|
+
return default
|
|
768
768
|
|
|
769
769
|
fun main() -> Int =
|
|
770
770
|
b = Box(value: Some(42))
|
|
@@ -913,8 +913,8 @@ fn generic_class_specialized_at_two_types_does_not_alias() {
|
|
|
913
913
|
type Box[T] =
|
|
914
914
|
value: T
|
|
915
915
|
|
|
916
|
-
fun getIntValue
|
|
916
|
+
fun getIntValue() -> Int =
|
|
917
|
-
|
|
917
|
+
self.value
|
|
918
918
|
|
|
919
919
|
fun useInt() -> Int =
|
|
920
920
|
b = Box(value: 7)
|
|
@@ -948,8 +948,8 @@ fn generic_method_on_generic_class_runs_correctly() {
|
|
|
948
948
|
type Box[T] =
|
|
949
949
|
value: T
|
|
950
950
|
|
|
951
|
-
fun getValue
|
|
951
|
+
fun getValue() -> Int =
|
|
952
|
-
|
|
952
|
+
self.value
|
|
953
953
|
|
|
954
954
|
fun main() -> Int =
|
|
955
955
|
b = Box(value: 9)
|
|
@@ -1067,8 +1067,8 @@ fn ordinary_function_with_bare_generic_class_param_runs_correctly() {
|
|
|
1067
1067
|
type Box[T] =
|
|
1068
1068
|
value: T
|
|
1069
1069
|
|
|
1070
|
-
fun getBoxValue
|
|
1070
|
+
fun getBoxValue() -> Int =
|
|
1071
|
-
|
|
1071
|
+
self.value
|
|
1072
1072
|
|
|
1073
1073
|
fun sumBox(b: Box) -> Int =
|
|
1074
1074
|
b.getBoxValue()
|
|
@@ -1433,8 +1433,8 @@ fn field_assignment_target_runs_correctly() {
|
|
|
1433
1433
|
type Counter =
|
|
1434
1434
|
value: Int
|
|
1435
1435
|
|
|
1436
|
-
fun bump
|
|
1436
|
+
fun bump() =
|
|
1437
|
-
|
|
1437
|
+
self.value = self.value + 1
|
|
1438
1438
|
|
|
1439
1439
|
fun main() -> Int =
|
|
1440
1440
|
c = Counter(value: 41)
|
|
@@ -1455,8 +1455,8 @@ type Inner =
|
|
|
1455
1455
|
type Outer =
|
|
1456
1456
|
inner: Inner
|
|
1457
1457
|
|
|
1458
|
-
fun bump
|
|
1458
|
+
fun bump() =
|
|
1459
|
-
|
|
1459
|
+
self.inner.value = self.inner.value + 1
|
|
1460
1460
|
|
|
1461
1461
|
fun main() -> Int =
|
|
1462
1462
|
o = Outer(inner: Inner(value: 9))
|