plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
b84196a
— Peter John
2026-11-01T22:58:29+05:30
fix: reject == on functions and Unit
plum-checker/src/lib.rs
CHANGED
|
@@ -4006,6 +4006,14 @@ fn inferExprInner(
|
|
|
4006
4006
|
));
|
|
4007
4007
|
}
|
|
4008
4008
|
}
|
|
4009
|
+
if matches!(c.op, ast::CmpOp::Eq | ast::CmpOp::Neq | ast::CmpOp::NotEq2) {
|
|
4010
|
+
if matches!(lt, PlumType::TFun(..)) || matches!(rt, PlumType::TFun(..)) {
|
|
4011
|
+
return Err("can't compare functions with ==".to_string());
|
|
4012
|
+
}
|
|
4013
|
+
if matches!(lt, PlumType::TUnit) && matches!(rt, PlumType::TUnit) {
|
|
4014
|
+
return Err("can't compare Unit values".to_string());
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4009
4017
|
let opn = match c.op {
|
|
4010
4018
|
ast::CmpOp::Eq => Some(("==", "eq")),
|
|
4011
4019
|
ast::CmpOp::Neq | ast::CmpOp::NotEq2 => Some(("!=", "eq")),
|
plum-checker/tests/checker_tests.rs
CHANGED
|
@@ -2150,3 +2150,15 @@ fn digit_variant_pattern_still_works() {
|
|
|
2150
2150
|
let src = "enum V2 =\n | A1(n: Int)\n | B2\n\nfun f(w: V2) -> Int =\n match w\n A1(n) => n\n B2 => 0\n\nfun g(w: V2) -> Int =\n if B2 := w\n return 1\n 0\n";
|
|
2151
2151
|
assert!(checkSrc(src).is_ok());
|
|
2152
2152
|
}
|
|
2153
|
+
|
|
2154
|
+
#[test]
|
|
2155
|
+
fn eq_on_functions_and_unit_is_rejected() {
|
|
2156
|
+
for (src, want) in [
|
|
2157
|
+
("fun f() -> Bool =\n a := |x| x\n b := |x| x\n a == b\n", "can't compare functions"),
|
|
2158
|
+
("fun f(a: fn(Int) -> Int, b: fn(Int) -> Int) -> Bool =\n a == b\n", "can't compare functions"),
|
|
2159
|
+
("fun u() =\n return\n\nfun f() -> Bool =\n u() == u()\n", "can't compare Unit values"),
|
|
2160
|
+
] {
|
|
2161
|
+
let msg = errText(checkSrc(src));
|
|
2162
|
+
assert!(msg.contains(want), "{src}: {msg}");
|
|
2163
|
+
}
|
|
2164
|
+
}
|