- if (target instanceof Trap.TrapScope && key.equals("cascade")) {
- Trap.TrapScope ts = (Trap.TrapScope)target;
- t = ts.t.next;
- ts.cascadeHappened = true;
- while (t != null && t.f.numFormalArgs == 0) t = t.next;
- if (t == null) { target = ts.t.trapee; key = ts.t.name; }
-
- } else if (target instanceof Trap.TrapScope && key.equals(((Trap.TrapScope)target).t.name)) {
- throw je("tried to put to " + key + " inside a trap it owns; use cascade instead");
-
- } else if (target instanceof JS) {
+ Trap.TrapScope ts = null;
+ if (target instanceof JSScope && key.equals("cascade")) {
+ JSScope p = (JSScope)target; // search the scope-path for the trap
+ if (target instanceof Trap.TrapScope) {
+ ts = (Trap.TrapScope)target;
+ } else {
+ while (ts == null && p.getParentScope() != null) {
+ p = p.getParentScope();
+ if (p instanceof Trap.TrapScope) ts = (Trap.TrapScope)p;
+ }
+ }
+ if(ts != null) {
+ t = ts.t.next;
+ ts.cascadeHappened = true;
+ while (t != null && t.f.numFormalArgs == 0) t = t.next;
+ if (t == null) { target = ts.t.trapee; key = ts.t.name; }
+ }
+ }
+ if(ts == null) {