Fix indexOf on C++ and C#
This commit is contained in:
@@ -1126,12 +1126,15 @@ class Macros {
|
||||
var funcName = if (last) "lastIndexOf" else "indexOf";
|
||||
wholeExp.checkNumArgs(2, 3, '($funcName <list or string> <element or substring> <?startingIndex>)');
|
||||
var b = wholeExp.expBuilder();
|
||||
return b.callSymbol("case", [
|
||||
var cases = [
|
||||
b.callField(funcName, exps.shift(), exps),
|
||||
b.callSymbol("-1", [b.symbol("haxe.ds.Option.None")]),
|
||||
b.callSymbol("other", [b.callSymbol("haxe.ds.Option.Some", [b.symbol("other")])]),
|
||||
b.callSymbol("null", [b.callSymbol("throw", [b.str("Haxe indexOf is broken")])])
|
||||
]);
|
||||
];
|
||||
if (!(Context.defined('cs') || Context.defined('cpp'))) {
|
||||
cases.push(b.callSymbol("null", [b.callSymbol("throw", [b.str("Haxe indexOf is broken")])]));
|
||||
}
|
||||
return b.callSymbol("case", cases);
|
||||
}
|
||||
macros["indexOf"] = indexOfMacro.bind(false);
|
||||
macros["lastIndexOf"] = indexOfMacro.bind(true);
|
||||
|
@@ -306,10 +306,9 @@ class SpecialForms {
|
||||
|
||||
var exp = k.withoutListWrapping().convert(args[0]);
|
||||
|
||||
// On C#, value types (specifically Float and Int) cannot be null, so they cannot be compared with null.
|
||||
// On C# and C++, value types (specifically Float and Int) cannot be null, so they cannot be compared with null.
|
||||
// Therefore a null case doesn't need to be added--and will cause a compile failure if it is.
|
||||
// TODO also c++?
|
||||
var canCompareNull = if (Context.defined('cs')) {
|
||||
var canCompareNull = if (Context.defined('cs') || Context.defined('cpp')) {
|
||||
// TODO can locals from let bindings and localVar be gathered and passed to this? Would be difficult and maybe require a separate stack in KissState for each (begin) conversion
|
||||
switch (exp.typeof()) {
|
||||
case Success(TAbstract(ref, [])) if (["Int", "Float"].indexOf(ref.get().name) != -1):
|
||||
|
Reference in New Issue
Block a user