`InlineAndCollapsePropertiesTest`: Add test for incorrectly collapsing toString/valueOf from object literals
This test case shows that we're removing toString/valueOf functions explicitly defined in object literals, when we shouldn't be.
I'm submitting this now to document the current incorrect behavior of InlineAndCollapseProperties. I'll start working on a fix for this next.
@@ -2410,6 +2410,27 @@ public final class InlineAndCollapsePropertiesTest extends CompilerTestCase {
"class A {} var A$foo = 3; var obj$foo = class extends A{}; use(obj$foo.foo)");
}
+ @Test
+ public void testToStringValueOfInObjectLiteral() {
+ test(
+ lines(
+ "let z = {",
+ " toString() { return 'toString';},",
+ " valueOf() { return 'valueOf';},",
+ "};",
+ "var zAsString = z + \"\";"),
+ lines(
+ "var z$toString = function() {",
+ " return \"toString\";",
+ "};",
+ "var z$valueOf = function() {",
+ " return \"valueOf\";",
+ "};",
+ // TODO(b/223896059): CollapseProperties breaks references to toString/valueOf
+ "let z = {}",
+ "var zAsString = z + \"\";"));
+ }
+
@Test
public void testLoopInAliasChainOfTypedefConstructorProperty() {
test(
