From 86750a3fcd678a95ce0ebf090ad81ab55dce5e5e Mon Sep 17 00:00:00 2001 From: lharker Date: Mon, 7 Aug 2023 10:33:11 -0700 Subject: [PATCH] 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 --- ...etizeStaticInheritanceForInliningTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java b/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java index 8207338caf1..31c53d9e3a3 100644 --- a/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java +++ b/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java @@ -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;")); + } }