From a63bf9fb2549b38c1272f4bf46125f777c0ae590 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Wed, 1 Nov 2023 07:12:11 -0700 Subject: [PATCH] PUBLIC: Add a test demonstrating b/308614050 (bug with parameter casting). PiperOrigin-RevId: 578507433 --- .../bugpatterns/inlineme/InlinerTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java index ca15535c9db..d3af6550289 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java @@ -1228,6 +1228,48 @@ public void varArgs_b268215956() { .doTest(); } + @Test + public void paramCast_b308614050() { + refactoringTestHelper + .addInputLines( + "Client.java", + "package com.google.foo;", + "import com.google.errorprone.annotations.InlineMe;", + "public final class Client {", + " @InlineMe(", + " replacement = \"Client.after(value.doubleValue())\",", + " imports = {\"com.google.foo.Client\"})", + " public static void before(Long value) {", + " after(value.doubleValue());", + " }", + " public static void after(double value) {", + " // do nothing", + " }", + "}") + .expectUnchanged() + .addInputLines( + "Caller.java", + "import com.google.foo.Client;", + "public final class Caller {", + " public void doTest() {", + " Object value = 42L;", + " Client.before((Long) value);", + " }", + "}") + .addOutputLines( + "Caller.java", + "import com.google.foo.Client;", + "public final class Caller {", + " public void doTest() {", + " Object value = 42L;", + // TODO(b/308614050): this is a bug! you can't call doubleValue() on an Object! + " Client.after((Long) value.doubleValue());", + " }", + "}") + .allowBreakingChanges() + .doTest(); + } + private BugCheckerRefactoringTestHelper bugCheckerWithPrefixFlag(String prefix) { return BugCheckerRefactoringTestHelper.newInstance(Inliner.class, getClass()) .setArgs("-XepOpt:" + PREFIX_FLAG + "=" + prefix);