@@ -52,9 +52,8 @@ public class Procedure implements Cloneable {
5252 private Map <String , IVariable > varList ;
5353 private final Map <String , Mixed > originals = new HashMap <>();
5454 private final List <IVariable > varIndex = new ArrayList <>();
55- private final List <Boolean > isVarArg ;
5655 private ParseTree tree ;
57- private CClassType returnType ;
56+ private LeftHandSideType returnType ;
5857 private boolean possiblyConstant = false ;
5958 private SmartComment procComment ;
6059
@@ -64,7 +63,7 @@ public class Procedure implements Cloneable {
6463 */
6564 private final Target definedAt ;
6665
67- public Procedure (String name , CClassType returnType , List <IVariable > varList , List < Boolean > isVarArg ,
66+ public Procedure (String name , LeftHandSideType returnType , List <IVariable > varList ,
6867 SmartComment procComment ,
6968 ParseTree tree , Target t ) {
7069 this .name = name ;
@@ -96,7 +95,6 @@ public Procedure(String name, CClassType returnType, List<IVariable> varList, Li
9695 //we can be sure that we cannot inline this in any way.
9796 this .possiblyConstant = checkPossiblyConstant (tree );
9897 this .returnType = returnType ;
99- this .isVarArg = isVarArg ;
10098 }
10199
102100 private boolean checkPossiblyConstant (ParseTree tree ) {
@@ -222,7 +220,7 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
222220 CArray vararg = null ;
223221 for (varInd = 0 ; varInd < args .size (); varInd ++) {
224222 Mixed c = args .get (varInd );
225- arguments .push (c , t );
223+ arguments .push (c , t , env );
226224 if (this .varIndex .size () > varInd
227225 || (!this .varIndex .isEmpty ()
228226 && this .varIndex .get (this .varIndex .size () - 1 ).getDefinedType ().isVariadicType ())) {
@@ -234,7 +232,8 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
234232 var = this .varIndex .get (this .varIndex .size () - 1 );
235233 if (vararg == null ) {
236234 vararg = new CArray (t , GenericParameters .emptyBuilder (CArray .TYPE )
237- .addParameter (var .getDefinedType ()).build (t , env ), env );
235+ .addParameter (var .getDefinedType ().getVarargsBaseType (env ))
236+ .build (t , env ), env );
238237 try {
239238 env .getEnv (GlobalEnv .class ).GetVarList ().set (new IVariable (CArray .TYPE ,
240239 var .getVariableName (), vararg , c .getTarget ()));
@@ -254,7 +253,7 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
254253
255254 // Type check vararg parameter.
256255 if (var .getDefinedType ().isVariadicType ()) {
257- if (InstanceofUtil .isInstanceof (c . typeof ( env ) , var .getDefinedType ().getVarargsBaseType (), env )) {
256+ if (InstanceofUtil .isInstanceof (c , var .getDefinedType ().getVarargsBaseType (env ), env )) {
258257 vararg .push (c , t , env );
259258 continue ;
260259 } else {
@@ -265,7 +264,7 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
265264 }
266265
267266 // Type check non-vararg parameter.
268- if (InstanceofUtil .isInstanceof (c . typeof ( env ) , var .getDefinedType (), env )) {
267+ if (InstanceofUtil .isInstanceof (c , var .getDefinedType (), env )) {
269268 try {
270269 env .getEnv (GlobalEnv .class ).GetVarList ().set (new IVariable (var .getDefinedType (),
271270 var .getVariableName (), c , c .getTarget (), env ));
@@ -321,12 +320,12 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
321320 } catch (FunctionReturnException e ) {
322321 // Normal exit
323322 Mixed ret = e .getReturn ();
324- if (returnType .equals (Auto .TYPE )) {
323+ if (returnType .equals (Auto .LHSTYPE )) {
325324 return ret ;
326325 }
327- if (returnType .equals (CVoid .TYPE ) != ret .equals (CVoid .VOID )
326+ if (returnType .equals (CVoid .TYPE . asLeftHandSideType () ) != ret .equals (CVoid .VOID )
328327 || !ret .equals (CNull .NULL ) && !ret .equals (CVoid .VOID )
329- && !InstanceofUtil .isInstanceof (ret . typeof ( env ) , returnType , env )) {
328+ && !InstanceofUtil .isInstanceof (ret , returnType , env )) {
330329 throw new CRECastException ("Expected procedure \" " + name + "\" to return a value of type "
331330 + returnType .val () + " but a value of type " + ret .typeof (env ) + " was returned instead" ,
332331 ret .getTarget ());
@@ -351,7 +350,7 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
351350 // If we got here, then there was no return value. This is fine, but only for returnType void or auto.
352351 // TODO: Once strong typing is implemented at a compiler level, this should be removed to increase runtime
353352 // performance.
354- if (!(returnType .equals (Auto .TYPE ) || returnType .equals (CVoid .TYPE ))) {
353+ if (!(returnType .equals (Auto .LHSTYPE ) || returnType .equals (CVoid .TYPE . asLeftHandSideType () ))) {
355354 throw new CRECastException ("Expecting procedure \" " + name + "\" to return a value of type " + returnType .val () + ","
356355 + " but no value was returned." , tree .getTarget ());
357356 }
@@ -379,7 +378,7 @@ public void definitelyNotConstant() {
379378 }
380379
381380 public LeftHandSideType getReturnType () {
382- return returnType . asLeftHandSideType () ;
381+ return returnType ;
383382 }
384383
385384 public List <LeftHandSideType > getParameterTypes () {
0 commit comments