Skip to content

Commit a1d6080

Browse files
committed
added type check for @:forward and 'is' operator
1 parent 196e2c2 commit a1d6080

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

hscript/Checker.hx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ class CheckerTypes {
284284
ta.to.push(makeXmlType(t.t));
285285
for( m in a.meta )
286286
if( m.name == ":forward" && m.params != null ) {
287+
if( m.params.length == 0 )
288+
ta.forwards.set("*", true);
287289
for( i in m.params )
288290
ta.forwards.set(i, true);
289291
}
@@ -1037,8 +1039,11 @@ class Checker {
10371039
#if hscriptPos
10381040
case TAbstract(a, pl) if( a.impl != null ):
10391041
var cf = a.impl.statics.get(f);
1040-
if( cf == null )
1042+
if( cf == null ) {
1043+
if( a.forwards.exists("*") )
1044+
return getField(apply(a.t, a.params, pl), f, e, forWrite);
10411045
return null;
1046+
}
10421047
var acc = mk(null,e);
10431048
var impl = resolveGlobal(a.impl.name,acc,Value);
10441049
if( impl == null )
@@ -1266,9 +1271,9 @@ class Checker {
12661271
expr.e = acc;
12671272
switch( t ) {
12681273
case TInst(c,_):
1269-
return TAnon([for( f in c.statics ) { name : f.name, t : f.t, opt : false }]);
1274+
return TType({ name : "#"+c.name, params : [], t : TAnon([for( f in c.statics ) { name : f.name, t : f.t, opt : false }]) },[]);
12701275
case TEnum(e,_):
1271-
return TAnon([for( f in e.constructors ) { name : f.name, t : f.args == null ? t : TFun(f.args,t), opt : false }]);
1276+
return TType({ name : "#"+e.name, params : [], t : TAnon([for( f in e.constructors ) { name : f.name, t : f.args == null ? t : TFun(f.args,t), opt : false }]) },[]);
12721277
default:
12731278
throw "assert";
12741279
}
@@ -1619,6 +1624,16 @@ class Checker {
16191624
if( tryUnify(t1,t2) )
16201625
return t2;
16211626
unify(t2,t1,e2); // error
1627+
case "is":
1628+
typeExpr(e1,Value);
1629+
var ct = typeExpr(e2,Value);
1630+
switch( ct ) {
1631+
case TType(t,_) if( t.name.charCodeAt(0) == "#".code ):
1632+
// type check
1633+
default:
1634+
error("Should be a type",e2);
1635+
}
1636+
return TBool;
16221637
default:
16231638
if( op.charCodeAt(op.length-1) == "=".code ) {
16241639
var t = typeExpr(mk(EBinop(op.substr(0,op.length-1),e1,e2),expr),withType);

0 commit comments

Comments
 (0)