Skip to content

Commit

Permalink
Fix compilation errors with Haxe 4: abstract Null<T> and OpIn (#12)
Browse files Browse the repository at this point in the history
* Handle both typedef and abstract Null<T>

Haxe 4 has switched to an abstract Null<T> [see: HaxeFoundation/haxe#6380].

* Handle both EIn (Haxe 3) and OpIn (Haxe 4)

Haxe 4 made the change from an `EIn` expression to an `OpIn` binop [see:
HaxeFoundation/haxe#6471].
  • Loading branch information
jonasmalacofilho authored and Simn committed Aug 23, 2017
1 parent 8fd679f commit ec1b59e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/sys/db/RecordMacros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class RecordMacros {
return c;
csup = csup.t.get().superClass;
}
case TType(t, p):
case TType(t, p) | TAbstract(t, p):
var name = t.toString();
if( p.length == 1 && (name == "Null" || name == "sys.db.SNull") ) {
isNull = true;
Expand Down Expand Up @@ -211,6 +211,7 @@ class RecordMacros {
case "Int": DInt;
case "Float": DFloat;
case "Bool": DBool;
case "Null": isNull = true; return makeType(p[0]);
case _ if (!a.get().meta.has(':coreType')):
var a = a.get();
#if macro
Expand Down Expand Up @@ -780,6 +781,17 @@ class RecordMacros {
return buildInt("<<", e1, e2, p);
case OpMod:
return buildNum("%", e1, e2, p);
#if (haxe_ver >= 4)
case OpIn:
var e = buildCond(e1);
var t = TPath({
pack : [],
name : "Iterable",
params : [TPType(convertType(e.t))],
sub : null,
});
return { sql : { expr : ECall( { expr : EField(manager, "quoteList"), pos : p }, [e.sql, { expr : ECheckType(e2,t), pos : p } ]), pos : p }, t : DBool, n : e.n };
#end
case OpUShr, OpInterval, OpAssignOp(_), OpAssign, OpArrow:
error("Unsupported operation", p);
}
Expand Down Expand Up @@ -899,6 +911,7 @@ class RecordMacros {
unify(r2.t, r1.t, e2.pos);
unify(r1.t, r2.t, e1.pos);
return { sql : { expr : EIf(e, r1.sql, r2.sql), pos : p }, t : r1.t, n : r1.n || r2.n };
#if (haxe_ver < 4)
case EIn(e, v):
var e = buildCond(e);
var t = TPath({
Expand All @@ -908,6 +921,7 @@ class RecordMacros {
sub : null,
});
return { sql : { expr : ECall( { expr : EField(manager, "quoteList"), pos : p }, [e.sql, { expr : ECheckType(v,t), pos : p } ]), pos : p }, t : DBool, n : e.n };
#end
default:
return buildDefault(cond);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Test.hx
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class Test
eq(r2s.first().theId,id3);

var ids = [id1,id2,id3];
var s = [ for (c in MySpodClass.manager.search( $anEnum == SecondValue || $theId in ids )) c.theId ];
var s = [ for (c in MySpodClass.manager.search( $anEnum == SecondValue || ($theId in ids) )) c.theId ];
s.sort(Reflect.compare);
eq([id1,id2,id3].join(','),s.join(','));

Expand Down

0 comments on commit ec1b59e

Please sign in to comment.