diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java index 2632e5d89be..954d10ba735 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java @@ -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; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java index 9a048cc4196..1072a93d3cc 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java @@ -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; }