@@ -327,6 +327,7 @@ class Checker {
327
327
var currentFunType : TType ;
328
328
var isCompletion : Bool ;
329
329
var allowDefine : Bool ;
330
+ var hasReturn : Bool ;
330
331
public var allowAsync : Bool ;
331
332
public var allowReturn : Null <TType >;
332
333
public var allowGlobalsDefine : Bool ;
@@ -337,10 +338,10 @@ class Checker {
337
338
this .types = types ;
338
339
}
339
340
340
- public function setGlobals ( cl : CClass ) {
341
+ public function setGlobals ( cl : CClass , allowPrivate = false ) {
341
342
while ( true ) {
342
343
for ( f in cl .fields )
343
- if ( f .isPublic )
344
+ if ( f .isPublic || allowPrivate )
344
345
setGlobal (f .name , f .params .length == 0 ? f .t : TLazy (function () return apply (f .t ,f .params ,[for ( i in 0 ... f .params .length ) makeMono ()])));
345
346
if ( cl .superClass == null )
346
347
break ;
@@ -367,6 +368,10 @@ class Checker {
367
368
return globals ;
368
369
}
369
370
371
+ public dynamic function onTopDownEnum ( en : CEnum , field : String ) {
372
+ return false ;
373
+ }
374
+
370
375
function typeArgs ( args : Array <Argument >, pos : Expr ) {
371
376
return [for ( i in 0 ... args .length ) {
372
377
var a = args [i ];
@@ -709,7 +714,7 @@ class Checker {
709
714
default : throw " assert" ;
710
715
}
711
716
}
712
- if ( ! typeEq (f1 .t ,f2 .t ) )
717
+ if ( ! typeEq (apply ( f1 .t , cl1 . params , pl1 ) ,f2 .t ) )
713
718
return false ;
714
719
}
715
720
return true ;
@@ -815,6 +820,9 @@ class Checker {
815
820
case TAnon (fl ):
816
821
for ( f in fl )
817
822
fields .push ({ name : f .name , t : f .t });
823
+ case TFun (args , ret ):
824
+ if ( isCompletion )
825
+ fields .push ({ name : " bind" , t : TFun (args ,TVoid ) });
818
826
default :
819
827
}
820
828
return fields ;
@@ -956,7 +964,19 @@ class Checker {
956
964
case " trace" :
957
965
return TDynamic ;
958
966
default :
959
- if ( isCompletion ) return TDynamic ;
967
+ switch ( withType ) {
968
+ case WithType (et = TEnum (e , args )):
969
+ for ( c in e .constructors )
970
+ if ( c .name == v ) {
971
+ if ( onTopDownEnum (e ,v ) ) {
972
+ var ct = c .args == null ? et : TFun (c .args , et );
973
+ return apply (ct , e .params , args );
974
+ }
975
+ break ;
976
+ }
977
+ default :
978
+ }
979
+ if ( isCompletion ) return TDynamic ;
960
980
error (" Unknown identifier " + v , expr );
961
981
}
962
982
case EBlock (el ):
@@ -977,7 +997,29 @@ class Checker {
977
997
case EParent (e ):
978
998
return typeExpr (e ,withType );
979
999
case ECall (e , params ):
980
- var ft = typeExpr (e , Value );
1000
+ switch ( edef (e ) ) {
1001
+ case EField (val , " bind" ):
1002
+ var ft = typeExpr (val , Value );
1003
+ switch ( ft ) {
1004
+ case TFun (args ,ret ):
1005
+ var remainArgs = args .copy ();
1006
+ for ( p in params ) {
1007
+ var a = remainArgs .shift ();
1008
+ if ( a == null ) {
1009
+ error (" Too many arguments" , p );
1010
+ return TFun ([], ret );
1011
+ }
1012
+ typeExprWith (p , a .t );
1013
+ }
1014
+ return TFun (remainArgs , ret );
1015
+ default :
1016
+ }
1017
+ default :
1018
+ }
1019
+ var ft = typeExpr (e , switch ( [edef (e ),withType ] ) {
1020
+ case [EIdent (_ ),WithType (TEnum (_ ))]: withType ;
1021
+ default : Value ;
1022
+ });
981
1023
switch ( follow (ft ) ) {
982
1024
case TFun (args , ret ):
983
1025
for ( i in 0 ... params .length ) {
@@ -1047,6 +1089,7 @@ class Checker {
1047
1089
return TVoid ;
1048
1090
case EReturn (v ):
1049
1091
var et = v == null ? TVoid : typeExpr (v , allowReturn == null ? Value : WithType (allowReturn ));
1092
+ hasReturn = true ;
1050
1093
if ( allowReturn == null )
1051
1094
error (" Return not allowed here" , expr );
1052
1095
else
@@ -1089,8 +1132,10 @@ class Checker {
1089
1132
var locals = saveLocals ();
1090
1133
var oldRet = allowReturn ;
1091
1134
var oldGDef = allowDefine ;
1135
+ var oldHasRet = hasReturn ;
1092
1136
allowReturn = tret ;
1093
1137
allowDefine = false ;
1138
+ hasReturn = false ;
1094
1139
var withArgs = null ;
1095
1140
if ( name != null && ! withType .match (WithType (follow (_ ) => TFun (_ ))) ) {
1096
1141
var ev = events .get (name );
@@ -1115,8 +1160,11 @@ class Checker {
1115
1160
if ( withArgs != null && targs .length < withArgs .length )
1116
1161
error (" Missing " + (withArgs .length - targs .length )+ " arguments (" + [for ( i in targs .length ... withArgs .length ) typeStr (withArgs [i ].t )].join (" ," )+ " )" , expr );
1117
1162
typeExpr (body ,NoValue );
1163
+ if ( ! hasReturn && ! tryUnify (tret , TVoid ) )
1164
+ error (" Missing return " + typeStr (tret ), expr );
1118
1165
allowDefine = oldGDef ;
1119
1166
allowReturn = oldRet ;
1167
+ hasReturn = oldHasRet ;
1120
1168
this .locals = locals ;
1121
1169
if ( ft == null ) {
1122
1170
ft = TFun (targs , tret );
@@ -1284,7 +1332,8 @@ class Checker {
1284
1332
case TAbstract (a , args ):
1285
1333
// special case : we allow unconditional access
1286
1334
// to an abstract iterator() underlying value (eg: ArrayProxy)
1287
- ft = getField (apply (a .t ,a .params ,args )," iterator" ,it );
1335
+ var at = apply (a .t ,a .params ,args );
1336
+ return getIteratorType (it , at );
1288
1337
default :
1289
1338
}
1290
1339
if ( ft != null )
0 commit comments