Skip to content

Commit 86750a3

Browse files
lauraharkercopybara-github
authored andcommitted
Repro bug in ConcretizeStaticInheritanceForInlining
It's copying seemingly random static properties to other classes in some cases, because of a bug around Java null. PiperOrigin-RevId: 554520757
1 parent b672e75 commit 86750a3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,37 @@ public void testAddSingletonGetter() {
625625
"$jscomp.inherits(Subclass, Example);",
626626
"goog.addSingletonGetter(Subclass);"));
627627
}
628+
629+
@Test
630+
public void testNonQnameConstructor_doesntPolluteListOfAssignments() {
631+
// Reproduce a pretty bad bug caused by accidentally reading/writing 'null' keys from a map.
632+
test(
633+
lines(
634+
"const ns = {};",
635+
"/** @constructor */",
636+
"ns['NOT_A_NAME'] = function() {};",
637+
"ns['NOT_A_NAME'].staticMethod = function() { alert(1); }",
638+
"",
639+
"/** @constructor */",
640+
"const Example = function() {}",
641+
"",
642+
"/** @constructor @extends {Example} */",
643+
"function Subclass() {}",
644+
"$jscomp.inherits(Subclass, Example);"),
645+
lines(
646+
"const ns = {};",
647+
"/** @constructor */",
648+
"ns['NOT_A_NAME'] = function() {};",
649+
"ns['NOT_A_NAME'].staticMethod = function() { alert(1); }",
650+
"",
651+
"/** @constructor */",
652+
"const Example = function() {}",
653+
"",
654+
"/** @constructor @extends {Example} */",
655+
"function Subclass() {}",
656+
"$jscomp.inherits(Subclass, Example);",
657+
// TODO(b/293320792) - stop producing this assignment, there's no
658+
// actual Example.staticMethod.
659+
"Subclass.staticMethod = Example.staticMethod;"));
660+
}
628661
}

0 commit comments

Comments
 (0)