Add some missing cases in type mapping.
This commit is contained in:
@@ -135,40 +135,50 @@ class Exprs {
|
|||||||
if (!subst.iterator().hasNext())
|
if (!subst.iterator().hasNext())
|
||||||
return source;
|
return source;
|
||||||
|
|
||||||
function replace(ct:ComplexType) {
|
function replace(ct:ComplexType)
|
||||||
return switch ct {
|
return switch ct {
|
||||||
case TPath({ pack: [], name: name }) if (subst.exists(name)):
|
case TPath({ pack: [], name: name }) if (subst.exists(name)):
|
||||||
subst.get(name);
|
subst.get(name);
|
||||||
default: ct;
|
default: ct;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return source.transform(
|
return source
|
||||||
|
.transform(
|
||||||
|
function (e) return switch e {
|
||||||
|
case macro $i{name} if (subst.exists(name)):
|
||||||
|
switch subst.get(name) {
|
||||||
|
case TPath({ pack: pack, name: name }):
|
||||||
|
pack.concat([name]).drill(e.pos);
|
||||||
|
default: e;//TODO: report an error?
|
||||||
|
}
|
||||||
|
default: e;
|
||||||
|
})
|
||||||
|
.mapTypes(replace);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function mapTypes(e:Expr, transformer:ComplexType->ComplexType, ?pos:Position) {
|
||||||
|
return e.transform(
|
||||||
function (e) return switch e {
|
function (e) return switch e {
|
||||||
case { expr: ENew(p, args) }:
|
case { expr: ENew(p, args) }:
|
||||||
switch TPath(p).map(replace) {
|
switch TPath(p).map(transformer) {
|
||||||
case TPath(nu):
|
case TPath(nu):
|
||||||
ENew(nu, args).at(e.pos);
|
ENew(nu, args).at(e.pos);
|
||||||
case v:
|
case v:
|
||||||
pos.error(v.toString() + ' cannot be instantiated in ${e.pos}');
|
pos.error(v.toString() + ' cannot be instantiated in ${e.pos}');
|
||||||
}
|
}
|
||||||
case macro $i{name} if (subst.exists(name)):
|
case macro cast($v, $ct):
|
||||||
switch subst.get(name) {
|
ct = ct.map(transformer);
|
||||||
case TPath({ pack: pack, name: name }):
|
(macro @:pos(e.pos) cast($v, $ct));
|
||||||
pack.concat([name]).drill(e.pos);
|
case { expr: ECheckType(v, ct) }: // cannot use reification, because that's `EParentheses(ECheckType)` and macros can (and apparently do) generate a non-wrapped one
|
||||||
default: e;//TODO: report an error?
|
ECheckType(v, ct.map(transformer)).at(e.pos);
|
||||||
}
|
|
||||||
case macro ($v : $ct):
|
|
||||||
ct = ct.map(replace);
|
|
||||||
macro @:pos(e.pos) ($v : $ct);
|
|
||||||
case { expr: EVars(vars) }:
|
case { expr: EVars(vars) }:
|
||||||
EVars([for (v in vars) {
|
EVars([for (v in vars) {
|
||||||
name: v.name,
|
name: v.name,
|
||||||
type: v.type.map(replace),
|
type: v.type.map(transformer),
|
||||||
expr: v.expr,
|
expr: v.expr,
|
||||||
}]).at(e.pos);
|
}]).at(e.pos);
|
||||||
case { expr: EFunction(kind, f) }:
|
case { expr: EFunction(kind, f) }:
|
||||||
EFunction(kind, Functions.mapSignature(f, replace)).at(e.pos);
|
EFunction(kind, Functions.mapSignature(f, transformer)).at(e.pos);
|
||||||
default: e;
|
default: e;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ class Types {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public function map(ct:ComplexType, transform:ComplexType->ComplexType) {
|
static public function map(ct:ComplexType, transform:ComplexType->ComplexType) {
|
||||||
|
if (ct == null)
|
||||||
|
return null;
|
||||||
inline function rec(ct)
|
inline function rec(ct)
|
||||||
return map(transform(ct), transform);
|
return map(transform(ct), transform);
|
||||||
|
|
||||||
@@ -112,9 +114,18 @@ class Types {
|
|||||||
case FProp(get, set, t, e): FProp(get, set, rec(t), e);
|
case FProp(get, set, t, e): FProp(get, set, rec(t), e);
|
||||||
case FFun(f): FFun(Functions.mapSignature(f, transform));
|
case FFun(f): FFun(Functions.mapSignature(f, transform));
|
||||||
},
|
},
|
||||||
|
access: f.access,
|
||||||
|
meta: switch f.meta {
|
||||||
|
case null: null;
|
||||||
|
case a: [for (m in a) {
|
||||||
|
name: m.name,
|
||||||
|
pos: m.pos,
|
||||||
|
params: [for (e in m.params) e.mapTypes(transform)],
|
||||||
|
}];
|
||||||
|
},
|
||||||
|
doc: f.doc,
|
||||||
}];
|
}];
|
||||||
return transform(switch ct {
|
return transform(switch ct {
|
||||||
case null: null;
|
|
||||||
case TParent(t): TParent(rec(t));
|
case TParent(t): TParent(rec(t));
|
||||||
#if haxe4
|
#if haxe4
|
||||||
case TNamed(n, t): TNamed(n, rec(t));
|
case TNamed(n, t): TNamed(n, rec(t));
|
||||||
|
|||||||
Reference in New Issue
Block a user