Bug 566418 - [15] Unused warning for implicit construtor with a
static record usage

Change-Id: I66028468f16cf4918e02d37494aa91f69f58e127
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
index 0761bc4..60d8856 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
@@ -33,7 +33,7 @@
 	static {
 //		TESTS_NUMBERS = new int [] { 40 };
 //		TESTS_RANGE = new int[] { 1, -1 };
-//		TESTS_NAMES = new String[] { "testBug566063"};
+//		TESTS_NAMES = new String[] { "testBug566418_001"};
 	}
 
 	public static Class<?> testClass() {
@@ -7729,4 +7729,41 @@
 			"Illegal modifier for the interface I; only public & abstract are permitted\n" +
 			"----------\n");
 }
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public void testBug566418_001() {
+	Map options = getCompilerOptions();
+	options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
+	options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+	options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+	this.runNegativeTest(
+	new String[] {
+			"X.java",
+			"public class X {\n"+
+			" static void foo() {\n"+
+			"   record R() {\n"+
+			"     static int create(int lo) {\n"+
+			"       return lo;\n"+
+			"     }\n"+
+			"   }\n"+
+			"   System.out.println(R.create(0));\n"+
+			"   }\n"+
+			"   Zork();\n"+
+			"}",
+		},
+	"----------\n" +
+	"1. ERROR in X.java (at line 10)\n" +
+	"	Zork();\n" +
+	"	^^^^^^\n" +
+	"Return type for the method is missing\n" +
+	"----------\n" +
+	"2. ERROR in X.java (at line 10)\n" +
+	"	Zork();\n" +
+	"	^^^^^^\n" +
+	"This method requires a body instead of a semicolon\n" +
+	"----------\n",
+		null,
+		true,
+		options
+	);
+}
 }
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index 9027be4..e03607f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -104,7 +104,8 @@
 			// otherwise default super constructor exists, so go ahead and complain unused.
 		}
 		// complain unused
-		this.scope.problemReporter().unusedPrivateConstructor(this);
+		if ((this.bits & ASTNode.IsImplicit) == 0)
+			this.scope.problemReporter().unusedPrivateConstructor(this);
 	}
 
 	// check constructor recursion, once all constructor got resolved