Add ComplexType::intersect.
This commit is contained in:
@@ -7,9 +7,7 @@ import haxe.macro.Context;
|
|||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
import haxe.macro.Type;
|
import haxe.macro.Type;
|
||||||
|
|
||||||
using tink.macro.Exprs;
|
using tink.MacroApi;
|
||||||
using tink.macro.Positions;
|
|
||||||
using tink.macro.Functions;
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Types {
|
class Types {
|
||||||
@@ -183,6 +181,33 @@ class Types {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function intersect(types:Array<ComplexType>, ?pos:Position):Outcome<ComplexType, Error> {
|
||||||
|
|
||||||
|
if (types.length == 1) return Success(types[1]);
|
||||||
|
|
||||||
|
var paths = [],
|
||||||
|
fields = [];
|
||||||
|
|
||||||
|
for (t in types)
|
||||||
|
switch t {
|
||||||
|
case TPath(p): paths.push(p);
|
||||||
|
case TAnonymous(f):
|
||||||
|
|
||||||
|
for (f in fields) fields.push(f);
|
||||||
|
|
||||||
|
case TExtend(p, f):
|
||||||
|
|
||||||
|
for (f in fields) fields.push(f);
|
||||||
|
for (p in paths) paths.push(p);
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
return Failure(new Error(t.toString() + ' cannot be interesected', pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Success(TExtend(paths, fields));
|
||||||
|
}
|
||||||
|
|
||||||
static public function lazyComplex(f:Void->Type)
|
static public function lazyComplex(f:Void->Type)
|
||||||
return
|
return
|
||||||
TPath({
|
TPath({
|
||||||
|
|||||||
Reference in New Issue
Block a user