88import liquidjava .diagnostics .errors .ArgumentMismatchError ;
99import liquidjava .diagnostics .errors .LJError ;
1010import liquidjava .diagnostics .errors .NotFoundError ;
11+ import liquidjava .diagnostics .errors .NotFoundError .Kind ;
1112import liquidjava .processor .context .Context ;
1213import liquidjava .processor .context .GhostFunction ;
1314import liquidjava .processor .facade .AliasDTO ;
1415import liquidjava .rj_language .ast .formatter .ExpressionFormatter ;
1516import liquidjava .rj_language .ast .typing .TypeInfer ;
1617import liquidjava .rj_language .visitors .ExpressionVisitor ;
1718import liquidjava .utils .Utils ;
18- import liquidjava .utils .constants .Keys ;
1919import spoon .reflect .factory .Factory ;
2020import spoon .reflect .reference .CtTypeReference ;
2121
@@ -199,34 +199,33 @@ private void auxSubstituteState(Map<String, Expression> subMap, String[] toChang
199199 public Expression changeAlias (Map <String , AliasDTO > alias , Context ctx , Factory f ) throws LJError {
200200 Expression e = clone ();
201201 if (this instanceof AliasInvocation ai ) {
202- if (alias .containsKey (ai .name )) { // object state
203- AliasDTO dto = alias .get (ai .name );
204- // check argument count
205- if (children .size () != dto .getVarNames ().size ()) {
202+ if (!alias .containsKey (ai .name ))
203+ throw new NotFoundError (ai .getName (), Kind .ALIAS , alias .keySet ());
204+ AliasDTO dto = alias .get (ai .name );
205+ // check argument count
206+ if (children .size () != dto .getVarNames ().size ()) {
207+ String msg = String .format ("Wrong number of arguments in alias invocation '%s': expected %d, got %d" ,
208+ ai .name , dto .getVarNames ().size (), children .size ());
209+ throw new ArgumentMismatchError (msg );
210+ }
211+ Expression sub = dto .getExpression ().clone ();
212+ for (int i = 0 ; i < children .size (); i ++) {
213+ Expression varExp = new Var (dto .getVarNames ().get (i ));
214+ String varType = dto .getVarTypes ().get (i );
215+ Expression aliasExp = children .get (i );
216+
217+ // check argument types
218+ boolean compatible = TypeInfer .checkCompatibleType (varType , aliasExp , ctx , f );
219+ if (!compatible ) {
206220 String msg = String .format (
207- "Wrong number of arguments in alias invocation '%s': expected %d, got %d" , ai .name ,
208- dto .getVarNames ().size (), children .size ());
221+ "Argument '%s' and parameter '%s' of alias '%s' types are incompatible: expected %s, got %s" ,
222+ aliasExp , dto .getVarNames ().get (i ), ai .name , varType ,
223+ TypeInfer .getType (ctx , f , aliasExp ).get ().getQualifiedName ());
209224 throw new ArgumentMismatchError (msg );
210225 }
211- Expression sub = dto .getExpression ().clone ();
212- for (int i = 0 ; i < children .size (); i ++) {
213- Expression varExp = new Var (dto .getVarNames ().get (i ));
214- String varType = dto .getVarTypes ().get (i );
215- Expression aliasExp = children .get (i );
216-
217- // check argument types
218- boolean compatible = TypeInfer .checkCompatibleType (varType , aliasExp , ctx , f );
219- if (!compatible ) {
220- String msg = String .format (
221- "Argument '%s' and parameter '%s' of alias '%s' types are incompatible: expected %s, got %s" ,
222- aliasExp , dto .getVarNames ().get (i ), ai .name , varType ,
223- TypeInfer .getType (ctx , f , aliasExp ).get ().getQualifiedName ());
224- throw new ArgumentMismatchError (msg );
225- }
226- sub = sub .substitute (varExp , aliasExp );
227- }
228- e = sub ;
226+ sub = sub .substitute (varExp , aliasExp );
229227 }
228+ e = sub ;
230229 }
231230 e .auxChangeAlias (alias , ctx , f );
232231 return e ;
@@ -237,7 +236,7 @@ private void auxChangeAlias(Map<String, AliasDTO> alias, Context ctx, Factory f)
237236 for (int i = 0 ; i < children .size (); i ++) {
238237 if (children .get (i )instanceof AliasInvocation ai ) {
239238 if (!alias .containsKey (ai .name ))
240- throw new NotFoundError (ai .getName (), Keys .ALIAS );
239+ throw new NotFoundError (ai .getName (), Kind .ALIAS , alias . keySet () );
241240 AliasDTO dto = alias .get (ai .name );
242241 // check argument count
243242 if (ai .children .size () != dto .getVarNames ().size ()) {
0 commit comments