Warning for unused values. Close #4

This commit is contained in:
2024-02-17 14:21:35 -07:00
parent 6c113ca1ee
commit 771652b753
2 changed files with 16 additions and 0 deletions

View File

@@ -46,12 +46,25 @@ class SpecialForms {
// blocks can contain field forms that don't return an expression. These can't be included in blocks
var exprs = [];
var lastArg = null;
if (args.length > 1) {
lastArg = args.pop();
}
for (bodyExp in args) {
switch(bodyExp.def) {
case Symbol(_) if (lastArg != null):
KissError.warnFromExp(bodyExp, "This looks like an unused value");
default:
}
var expr = k.convert(bodyExp);
if (expr != null) {
exprs.push(expr);
}
}
if (lastArg != null)
exprs.push(k.convert(lastArg));
EBlock(exprs).withMacroPosOf(wholeExp);
};

View File

@@ -427,6 +427,9 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(assertLet [(Some _) (indexOf ["hey" "found"] key)] 0)
(assertLet [(Some _) (indexOf ["you" "me"] value)] 0))
// This demonstrates a nice compiler warning when you make a certain mistake:
(when myMap.exists "hey" (print "always true"))
// Map destructuring:
(let [[=>"hey" v1 =>"found" v2] myMap]
(Assert.equals "you" v1)