Skip to content

Commit

Permalink
Repro bug in ConcretizeStaticInheritanceForInlining
Browse files Browse the repository at this point in the history
It's copying seemingly random static properties to other classes in some cases, because of a bug around Java null.

PiperOrigin-RevId: 554520757
  • Loading branch information
lauraharker authored and copybara-github committed Aug 7, 2023
1 parent b672e75 commit 86750a3
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,37 @@ public void testAddSingletonGetter() {
"$jscomp.inherits(Subclass, Example);",
"goog.addSingletonGetter(Subclass);"));
}

@Test
public void testNonQnameConstructor_doesntPolluteListOfAssignments() {
// Reproduce a pretty bad bug caused by accidentally reading/writing 'null' keys from a map.
test(
lines(
"const ns = {};",
"/** @constructor */",
"ns['NOT_A_NAME'] = function() {};",
"ns['NOT_A_NAME'].staticMethod = function() { alert(1); }",
"",
"/** @constructor */",
"const Example = function() {}",
"",
"/** @constructor @extends {Example} */",
"function Subclass() {}",
"$jscomp.inherits(Subclass, Example);"),
lines(
"const ns = {};",
"/** @constructor */",
"ns['NOT_A_NAME'] = function() {};",
"ns['NOT_A_NAME'].staticMethod = function() { alert(1); }",
"",
"/** @constructor */",
"const Example = function() {}",
"",
"/** @constructor @extends {Example} */",
"function Subclass() {}",
"$jscomp.inherits(Subclass, Example);",
// TODO(b/293320792) - stop producing this assignment, there's no
// actual Example.staticMethod.
"Subclass.staticMethod = Example.staticMethod;"));
}
}

0 comments on commit 86750a3

Please sign in to comment.