@@ -1438,9 +1438,33 @@ TEST_F(RuntimeTest, CollectAttributes) {
1438
1438
result = dictAtByStr (thread_, attributes, baz);
1439
1439
ASSERT_TRUE (result.isStr ());
1440
1440
EXPECT_TRUE (Str::cast (*result).equals (*baz));
1441
+
1442
+ // Bytecode for the snippet:
1443
+ //
1444
+ // def __init__(self):
1445
+ // self.foo = 100
1446
+ //
1447
+ // Manually add duplicate and useless EXTENDED_ARG intentionally to ensure
1448
+ // that collectAttributes can handle it.
1449
+ const byte bytecode2[] = {LOAD_CONST, 0 , EXTENDED_ARG, 0 , EXTENDED_ARG, 0 ,
1450
+ EXTENDED_ARG, 0 , LOAD_FAST, 0 , STORE_ATTR, 0 ,
1451
+ RETURN_VALUE, 0 };
1452
+ Code code2 (&scope, newCodeWithBytesConstsNamesLocals (bytecode2, consts, names,
1453
+ &locals));
1454
+
1455
+ attributes = runtime_->newDict ();
1456
+ runtime_->collectAttributes (code2, attributes);
1457
+
1458
+ // We should have collected a single attribute: 'foo'
1459
+ EXPECT_EQ (attributes.numItems (), 1 );
1460
+
1461
+ // Check that we collected 'foo'
1462
+ result = dictAtByStr (thread_, attributes, foo);
1463
+ ASSERT_TRUE (result.isStr ());
1464
+ EXPECT_TRUE (Str::cast (*result).equals (*foo));
1441
1465
}
1442
1466
1443
- TEST_F (RuntimeTest, CollectAttributesWithExtendedArg ) {
1467
+ TEST_F (RuntimeTest, CollectAttributesWithExtendedArgAccumulates ) {
1444
1468
HandleScope scope (thread_);
1445
1469
1446
1470
Str foo (&scope, runtime_->newStrFromCStr (" foo" ));
@@ -1461,22 +1485,16 @@ TEST_F(RuntimeTest, CollectAttributesWithExtendedArg) {
1461
1485
//
1462
1486
// There is an additional LOAD_FAST that is preceded by an EXTENDED_ARG
1463
1487
// that must be skipped.
1464
- const byte bytecode[] = {LOAD_CONST, 0 , EXTENDED_ARG, 1 , LOAD_FAST, 0 ,
1465
- STORE_ATTR, 1 , LOAD_CONST, 0 , LOAD_FAST, 0 ,
1466
- STORE_ATTR, 0 , RETURN_VALUE, 0 };
1488
+ const byte bytecode[] = {LOAD_CONST, 0 , EXTENDED_ARG, 1 , LOAD_FAST, 0 ,
1489
+ STORE_ATTR, 1 , LOAD_CONST, 0 , RETURN_VALUE, 0 };
1467
1490
Code code (&scope, newCodeWithBytesConstsNamesLocals (bytecode, consts, names,
1468
1491
&locals));
1469
1492
1470
1493
Dict attributes (&scope, runtime_->newDict ());
1471
1494
runtime_->collectAttributes (code, attributes);
1472
1495
1473
- // We should have collected a single attribute: 'foo'
1474
- EXPECT_EQ (attributes.numItems (), 1 );
1475
-
1476
- // Check that we collected 'foo'
1477
- Object result (&scope, dictAtByStr (thread_, attributes, foo));
1478
- ASSERT_TRUE (result.isStr ());
1479
- EXPECT_TRUE (Str::cast (*result).equals (*foo));
1496
+ // We should have collected no attributes because EXTENDED_ARG makes 0x0100
1497
+ EXPECT_EQ (attributes.numItems (), 0 );
1480
1498
}
1481
1499
1482
1500
TEST_F (RuntimeTest, GetTypeConstructor) {
0 commit comments