@@ -220,7 +220,6 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
220220 || (!this .varIndex .isEmpty ()
221221 && this .varIndex .get (this .varIndex .size () - 1 ).getDefinedType ().isVarargs ())) {
222222 IVariable var ;
223- boolean isVarArg = false ;
224223 if (varInd < this .varIndex .size () - 1
225224 || !this .varIndex .get (this .varIndex .size () - 1 ).getDefinedType ().isVarargs ()) {
226225 var = this .varIndex .get (varInd );
@@ -232,21 +231,33 @@ public Mixed execute(List<Mixed> args, Environment oldEnv, Target t) {
232231 env .getEnv (GlobalEnv .class ).GetVarList ().set (new IVariable (CArray .TYPE ,
233232 var .getVariableName (), vararg , c .getTarget ()));
234233 }
235- isVarArg = true ;
236234 }
235+
236+ // Type check "void" value.
237237 if (c instanceof CVoid
238238 && !(var .getDefinedType ().equals (Auto .TYPE ) || var .getDefinedType ().equals (CVoid .TYPE ))) {
239239 throw new CRECastException ("Procedure \" " + name + "\" expects a value of type "
240240 + var .getDefinedType ().val () + " in argument " + (varInd + 1 ) + ", but"
241241 + " a void value was found instead." , c .getTarget ());
242- } else if ((!(c instanceof CVoid ) && c instanceof CNull ) || var .getDefinedType ().equals (Auto .TYPE )
243- || InstanceofUtil .isInstanceof (c .typeof (), var .getDefinedType (), env )) {
244- if (isVarArg ) {
242+ }
243+
244+ // Type check vararg parameter.
245+ if (var .getDefinedType ().isVarargs ()) {
246+ if (InstanceofUtil .isInstanceof (c .typeof (), var .getDefinedType ().getVarargsBaseType (), env )) {
245247 vararg .push (c , t );
248+ continue ;
246249 } else {
247- env .getEnv (GlobalEnv .class ).GetVarList ().set (new IVariable (var .getDefinedType (),
248- var .getVariableName (), c , c .getTarget ()));
250+ throw new CRECastException ("Procedure \" " + name + "\" expects a value of type "
251+ + var .getDefinedType ().val () + " in argument " + (varInd + 1 ) + ", but"
252+ + " a value of type " + c .typeof () + " was found instead." , c .getTarget ());
249253 }
254+ }
255+
256+ // Type check non-vararg parameter.
257+ if (InstanceofUtil .isInstanceof (c .typeof (), var .getDefinedType (), env )) {
258+ env .getEnv (GlobalEnv .class ).GetVarList ().set (new IVariable (var .getDefinedType (),
259+ var .getVariableName (), c , c .getTarget ()));
260+ continue ;
250261 } else {
251262 throw new CRECastException ("Procedure \" " + name + "\" expects a value of type "
252263 + var .getDefinedType ().val () + " in argument " + (varInd + 1 ) + ", but"
0 commit comments