@@ -333,3 +333,38 @@ class test_t3(struct):
333333 test2 = test_t3 .from_bytes (memory )
334334
335335 self .assertNotEqual (test1 , test2 )
336+
337+ def test_struct_member_name_collision (self ):
338+ # Ensure that we can inflate structs with an attribute named "size"
339+ class test_t (struct ):
340+ size : c_int
341+ a : c_long
342+ b : ptr = ptr_to_self ()
343+
344+ memory = b""
345+ memory += (1337 ).to_bytes (4 , "little" )
346+ memory += (13371337 ).to_bytes (8 , "little" )
347+ memory += (4 + 8 + 8 ).to_bytes (8 , "little" )
348+
349+ test = test_t .from_bytes (memory )
350+
351+ self .assertEqual (test .size .value , 1337 )
352+ self .assertEqual (test .a .value , 13371337 )
353+ self .assertEqual (test .b .unwrap ().address , 4 + 8 + 8 )
354+ self .assertEqual (test .address , 0x0 )
355+
356+ # Ensure that we can inflate nested structs with an attribute named "size"
357+ class test_t2 (struct ):
358+ size : test_t
359+ a : c_long
360+
361+ memory += (0xdeadbeef ).to_bytes (8 , "little" )
362+
363+ test2 = test_t2 .from_bytes (memory )
364+
365+ self .assertEqual (test2 .size .size .value , 1337 )
366+ self .assertEqual (test2 .size .a .value , 13371337 )
367+ self .assertEqual (test2 .size .b .unwrap ().address , 4 + 8 + 8 )
368+ self .assertEqual (test2 .size .address , 0x0 )
369+ self .assertEqual (test2 .a .value , 0xdeadbeef )
370+ self .assertEqual (test2 .address , 0x0 )
0 commit comments