Skip to content

Commit 29237e3

Browse files
committed
added abstract from/to auto casting
1 parent 99a3509 commit 29237e3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

hscript/Checker.hx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ typedef CTypedef = {> CNamedType,
7777

7878
typedef CAbstract = {> CNamedType,
7979
var t : TType;
80+
var from : Array<TType>;
81+
var to : Array<TType>;
8082
}
8183

8284
class Completion {
@@ -233,13 +235,21 @@ class CheckerTypes {
233235
name : a.path,
234236
params : [],
235237
t : null,
238+
from : [],
239+
to : [],
236240
};
237241
addMeta(a,ta);
238242
for( p in a.params )
239243
ta.params.push(TParam(p));
240244
todo.push(function() {
241245
localParams = [for( t in ta.params ) a.path+"."+Checker.typeStr(t) => t];
242246
ta.t = makeXmlType(a.athis);
247+
for( f in a.from )
248+
if( f.field == null )
249+
ta.from.push(makeXmlType(f.t));
250+
for( t in a.to )
251+
if( t.field == null )
252+
ta.to.push(makeXmlType(t.t));
243253
localParams = null;
244254
});
245255
types.set(a.path, CTAbstract(ta));
@@ -722,6 +732,18 @@ class Checker {
722732
return true;
723733
case [TFun(_), TAbstract({ name : "haxe.Function" },_)]:
724734
return true;
735+
case [_, TAbstract(a, args)]:
736+
for( ft in a.from ) {
737+
var t = apply(ft,a.params,args);
738+
if( tryUnify(t1,t) )
739+
return true;
740+
}
741+
case [TAbstract(a, args), _]:
742+
for( tt in a.to ) {
743+
var t = apply(tt,a.params,args);
744+
if( tryUnify(t,t2) )
745+
return true;
746+
}
725747
default:
726748
}
727749
return typeEq(t1,t2);

0 commit comments

Comments
 (0)