Skip to content

Commit

Permalink
Properly propagate deprecation status from enclosing context into LE (e…
Browse files Browse the repository at this point in the history
…clipse-jdt#1460)

We should not emit deprecation warnings inside a LE if that features in a deprecated context itself

Fixes eclipse-jdt#1370
and its duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=562113
  • Loading branch information
srikanth-sankaran authored Oct 2, 2023
1 parent 983c3bf commit 7dc86b9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ public TypeBinding resolveType(BlockScope blockScope, boolean skipKosherCheck) {
blockScope.enclosingSourceType());
this.binding.typeVariables = Binding.NO_TYPE_VARIABLES;

MethodScope enm = this.scope.namedMethodScope();
MethodBinding enmb = enm == null ? null : enm.referenceMethodBinding();
if (enmb != null && enmb.isViewedAsDeprecated()) {
this.binding.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
this.binding.tagBits |= enmb.tagBits & TagBits.AnnotationTerminallyDeprecated;
}

boolean argumentsHaveErrors = false;
if (haveDescriptor) {
int parametersLength = this.descriptor.parameters.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,62 @@ public void test412555() {
true,
options);
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1370
// Deprecation warnings are not suppressed in lambdas of deprecated methods
public void testGH1370() {
Map options = getCompilerOptions();
options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR);
this.runNegativeTest(
false /* skipJavac */,
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError,
new String[] {
"X.java",
"""
public class X {
@Deprecated
static void deprecatedMethod(Object o) {}
}
""",
"Y.java",
"""
import java.util.List;
public class Y {
@Deprecated
void callDeprecated() {
X.deprecatedMethod(null); // no warning
List.of().forEach(X::deprecatedMethod); // no warning
List.of().forEach(o -> X.deprecatedMethod(o)); // warning
}
void callDeprecated2() {
X.deprecatedMethod(null);
List.of().forEach(X::deprecatedMethod);
List.of().forEach(o -> X.deprecatedMethod(o));
}
}
""",
},
"""
----------
1. ERROR in Y.java (at line 10)
X.deprecatedMethod(null);
^^^^^^^^^^^^^^^^^^^^^^
The method deprecatedMethod(Object) from the type X is deprecated
----------
2. ERROR in Y.java (at line 11)
List.of().forEach(X::deprecatedMethod);
^^^^^^^^^^^^^^^^^^^
The method deprecatedMethod(Object) from the type X is deprecated
----------
3. ERROR in Y.java (at line 12)
List.of().forEach(o -> X.deprecatedMethod(o));
^^^^^^^^^^^^^^^^^^^
The method deprecatedMethod(Object) from the type X is deprecated
----------
""",
null,
true,
options);
}
public static Class testClass() {
return Deprecated18Test.class;
}
Expand Down

0 comments on commit 7dc86b9

Please sign in to comment.