Skip to content

Commit a3ff1af

Browse files
Googlercopybara-github
authored andcommitted
[J2KT] Add test reproducing protected method visibility translation bug.
Reproduces problem with `protected` method translated as `public`, and `protected` override which is incorrectly translated as `protected` (should also be `public`). PiperOrigin-RevId: 926024096
1 parent c850271 commit a3ff1af

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

transpiler/javatests/com/google/j2cl/readable/java/j2kt/VisibilityModifiers.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ protected void protectedMethod() {}
5858
private void privateMethod() {}
5959
}
6060

61+
// TODO(b/519538678): Uncomment when fixed.
62+
// public static class ProtectedOverrideOfVisibilityWarningsSuppressed
63+
// extends VisibilityWarningsSuppressed.Public {
64+
// @Override
65+
// protected void protectedMethod() {}
66+
// }
67+
6168
@AutoValue
6269
abstract static class Value {
6370
@AutoValue.Builder
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2026 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package j2ktnotpassing;
17+
18+
public final class VisibilityModifiers {
19+
@SuppressWarnings("j2kt:visibility")
20+
public static class VisibilityWarningsSuppressed {
21+
public static class Public {
22+
// This one is translated as public
23+
protected void protectedMethod() {}
24+
}
25+
}
26+
27+
public static class ProtectedOverrideOfVisibilityWarningsSuppressed
28+
extends VisibilityWarningsSuppressed.Public {
29+
// TODO(b/519538678): This one is translated as protected, but should be public because it
30+
// overrides a public method.
31+
@Override
32+
protected void protectedMethod() {}
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Generated from "j2ktnotpassing/VisibilityModifiers.java"
2+
@file:Suppress(
3+
"ALWAYS_NULL",
4+
"PARAMETER_NAME_CHANGED_ON_OVERRIDE",
5+
"SENSELESS_COMPARISON",
6+
"UNCHECKED_CAST",
7+
"UNNECESSARY_LATEINIT",
8+
"UNNECESSARY_NOT_NULL_ASSERTION",
9+
"UNREACHABLE_CODE",
10+
"UNUSED_ANONYMOUS_PARAMETER",
11+
"UNUSED_PARAMETER",
12+
"UNUSED_VARIABLE",
13+
"USELESS_CAST",
14+
"VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL",
15+
"VARIABLE_WITH_REDUNDANT_INITIALIZER",
16+
"REDUNDANT_ELSE_IN_WHEN",
17+
"ACCIDENTAL_OVERRIDE")
18+
19+
package j2ktnotpassing
20+
21+
import javaemul.lang.*
22+
import j2ktnotpassing.VisibilityModifiers.VisibilityWarningsSuppressed.Public
23+
import kotlin.Suppress
24+
25+
class VisibilityModifiers {
26+
open class VisibilityWarningsSuppressed {
27+
open class Public {
28+
open fun protectedMethod() {}
29+
}
30+
}
31+
32+
open class ProtectedOverrideOfVisibilityWarningsSuppressed: Public() {
33+
protected override fun protectedMethod() {}
34+
}
35+
}

0 commit comments

Comments
 (0)