@@ -306,6 +306,67 @@ describe("dereference", () => {
306306 expect ( regions [ 0 ] . length ) . toEqual ( Data . fromNumber ( 32 ) ) ;
307307 } ) ;
308308
309+ it ( "scopes defined variables to their `in`" , async ( ) => {
310+ const pointer : Pointer = {
311+ define : { slot : "0x00" } ,
312+ in : {
313+ group : [
314+ {
315+ define : { slot : { $sum : [ "slot" , 1 ] } } ,
316+ in : { location : "storage" , slot : "slot" , name : "a" } ,
317+ } ,
318+ {
319+ location : "storage" ,
320+ slot : { $sum : [ "slot" , 2 ] } ,
321+ name : "b" ,
322+ } ,
323+ ] ,
324+ } ,
325+ } ;
326+
327+ const cursor = await dereference ( pointer ) ;
328+
329+ const { regions } = await cursor . view ( state ) ;
330+
331+ expect ( regions . map ( ( { name } ) => name ) ) . toEqual ( [ "a" , "b" ] ) ;
332+ expect ( regions [ 0 ] ) . toMatchObject ( { slot : Data . fromNumber ( 1 ) } ) ;
333+ expect ( regions [ 1 ] ) . toMatchObject ( { slot : Data . fromNumber ( 2 ) } ) ;
334+ } ) ;
335+
336+ it ( "scopes variables defined inside referenced templates" , async ( ) => {
337+ const pointer : Pointer = {
338+ define : { slot : "0x00" } ,
339+ in : {
340+ templates : {
341+ shifted : {
342+ expect : [ "slot" ] ,
343+ for : {
344+ define : { slot : { $sum : [ "slot" , 1 ] } } ,
345+ in : { location : "storage" , slot : "slot" , name : "a" } ,
346+ } ,
347+ } ,
348+ } ,
349+ in : {
350+ group : [
351+ { template : "shifted" } ,
352+ {
353+ location : "storage" ,
354+ slot : { $sum : [ "slot" , 2 ] } ,
355+ name : "b" ,
356+ } ,
357+ ] ,
358+ } ,
359+ } ,
360+ } ;
361+
362+ const cursor = await dereference ( pointer ) ;
363+
364+ const { regions } = await cursor . view ( state ) ;
365+
366+ expect ( regions [ 0 ] ) . toMatchObject ( { slot : Data . fromNumber ( 1 ) } ) ;
367+ expect ( regions [ 1 ] ) . toMatchObject ( { slot : Data . fromNumber ( 2 ) } ) ;
368+ } ) ;
369+
309370 it ( "works for templates" , async ( ) => {
310371 const templates : Pointer . Templates = {
311372 "memory-range" : {
0 commit comments