Skip to content

Parameter/variable name lookup confusion #659

@opeongo

Description

@opeongo

As I was putting together a test script for #655 I noticed a problem with parameter/variable name lookups. The following script fails at line 23 with the error message:
Attempt to resolve method: add() on undefined variable or class name: c.ylds : at Line: 23

test1(String c) {  //change String c to String d and it works!
   return this;
}

container() {
   System.err.println("allocate container");
   ylds = new ArrayList();
   work() {
      System.err.println("working");
   }
   return this;
}

c = null;
for (int i=0; i<2; i++) {
   for (int j=0; j<10; j++) {
      if (j%5 == 0) {
         if (c != null) {
            c.work();
         }
         c = container();
      }
      c.ylds.add(test1("hello"));  // line 23
   }
}

However, if I change the formal parameter name in the test1 method from c to d the script will work successfully.

What am I missing here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions