Warning for unused values. Close #4
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user