fix an (if... ) bug
This commit is contained in:
@@ -7,6 +7,7 @@ import kiss.CompileError;
|
||||
import kiss.Types;
|
||||
|
||||
using kiss.Reader;
|
||||
using kiss.Helpers;
|
||||
using StringTools;
|
||||
|
||||
class Helpers {
|
||||
@@ -85,10 +86,7 @@ class Helpers {
|
||||
default:
|
||||
throw CompileError.fromExp(argList, 'expected an argument list');
|
||||
},
|
||||
expr: {
|
||||
pos: Context.currentPos(),
|
||||
expr: EReturn(convert(CallExp(Symbol("begin").withPos(body[0].pos), body).withPos(body[0].pos)))
|
||||
}
|
||||
expr: EReturn(convert(CallExp(Symbol("begin").withPos(body[0].pos), body).withPos(body[0].pos))).withContextPos()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -190,7 +190,13 @@ class SpecialForms {
|
||||
|
||||
var condition = macro Prelude.truthy(${convert(args[0])});
|
||||
var thenExp = convert(args[1]);
|
||||
var elseExp = if (args.length > 2) convert(args[2]) else null;
|
||||
var elseExp = if (args.length > 2) {
|
||||
convert(args[2]);
|
||||
} else {
|
||||
// Kiss (if... ) expressions all need to generate a Haxe else block
|
||||
// to make sure they always return something
|
||||
macro null;
|
||||
};
|
||||
|
||||
macro if ($condition)
|
||||
$thenExp
|
||||
|
@@ -120,6 +120,8 @@ class BasicTestCase extends Test {
|
||||
Assert.equals(false, BasicTestCase.myIf8);
|
||||
Assert.equals(false, BasicTestCase.myIf9);
|
||||
Assert.equals(true, BasicTestCase.myIf10);
|
||||
Assert.equals(5, BasicTestCase.myIf11);
|
||||
Assert.equals(null, BasicTestCase.myIf12);
|
||||
}
|
||||
|
||||
function testMacros() {
|
||||
|
@@ -64,6 +64,8 @@
|
||||
(defvar myIf8 (if "" true false))
|
||||
(defvar myIf9 (if [] true false))
|
||||
(defvar myIf10 (if [1] true false))
|
||||
(defvar myIf11 (if true 5))
|
||||
(defvar myIf12 (if false 5))
|
||||
|
||||
(defvar :Int myInt 8)
|
||||
|
||||
|
Reference in New Issue
Block a user