From ae999eae7e61072ad964a43f622fa930ce1179f7 Mon Sep 17 00:00:00 2001 From: Nizar Benalla Date: Fri, 17 May 2024 06:39:53 +0000 Subject: [PATCH] 8129418: JShell: better highlighting of errors in imports on demand Reviewed-by: jlahoda --- .../share/classes/com/sun/tools/javac/comp/Check.java | 2 +- test/langtools/jdk/jshell/ImportTest.java | 5 ++--- test/langtools/tools/javac/7129225/NegTest.out | 2 +- test/langtools/tools/javac/7129225/TestImportStar.out | 2 +- .../tools/javac/importChecks/ImportIsFullyQualified.out | 2 +- .../tools/javac/importChecks/ImportsObservable.out | 2 +- .../tools/javac/modules/ConvenientAccessErrorsTest.java | 6 +++--- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index d98aad1e9d8..fc96eaa0be1 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -4428,7 +4428,7 @@ public class Check { TypeSymbol tsym = imp.qualid.selected.type.tsym; if (tsym.kind == PCK && tsym.members().isEmpty() && !(Feature.IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES.allowedInSource(source) && tsym.exists())) { - log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym)); + log.error(DiagnosticFlag.RESOLVE_ERROR, imp.qualid.selected.pos(), Errors.DoesntExist(tsym)); } } } diff --git a/test/langtools/jdk/jshell/ImportTest.java b/test/langtools/jdk/jshell/ImportTest.java index b8f3f1ee5d0..0e1dbfead96 100644 --- a/test/langtools/jdk/jshell/ImportTest.java +++ b/test/langtools/jdk/jshell/ImportTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8141415 + * @bug 8141415 8129418 * @summary Test imports * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main @@ -80,12 +80,11 @@ public class ImportTest extends KullaTesting { assertEval("abs(cos(PI / 2)) < 0.00001;", "true"); } - @Test(enabled = false) // TODO 8129418 public void testUnknownPackage() { assertDeclareFail("import unknown.qqq;", new ExpectedDiagnostic("compiler.err.doesnt.exist", 7, 18, 14, -1, -1, Diagnostic.Kind.ERROR)); assertDeclareFail("import unknown.*;", - new ExpectedDiagnostic("compiler.err.doesnt.exist", 7, 15, 7, -1, -1, Diagnostic.Kind.ERROR)); + new ExpectedDiagnostic("compiler.err.doesnt.exist", 7, 14, 7, -1, -1, Diagnostic.Kind.ERROR)); } public void testBogusImportIgnoredInFuture() { diff --git a/test/langtools/tools/javac/7129225/NegTest.out b/test/langtools/tools/javac/7129225/NegTest.out index d6fbd22adc3..53ceaa4cb9a 100644 --- a/test/langtools/tools/javac/7129225/NegTest.out +++ b/test/langtools/tools/javac/7129225/NegTest.out @@ -1,2 +1,2 @@ -TestImportStar.java:16:1: compiler.err.doesnt.exist: xxx +TestImportStar.java:16:8: compiler.err.doesnt.exist: xxx 1 error diff --git a/test/langtools/tools/javac/7129225/TestImportStar.out b/test/langtools/tools/javac/7129225/TestImportStar.out index 86ff8933138..352c0848392 100644 --- a/test/langtools/tools/javac/7129225/TestImportStar.out +++ b/test/langtools/tools/javac/7129225/TestImportStar.out @@ -1,4 +1,4 @@ - compiler.note.proc.messager: RUNNING - lastRound = false -TestImportStar.java:16:1: compiler.err.doesnt.exist: xxx +TestImportStar.java:16:8: compiler.err.doesnt.exist: xxx - compiler.note.proc.messager: RUNNING - lastRound = true 1 error diff --git a/test/langtools/tools/javac/importChecks/ImportIsFullyQualified.out b/test/langtools/tools/javac/importChecks/ImportIsFullyQualified.out index 33e7d2f71c3..89495c2b93d 100644 --- a/test/langtools/tools/javac/importChecks/ImportIsFullyQualified.out +++ b/test/langtools/tools/javac/importChecks/ImportIsFullyQualified.out @@ -1,2 +1,2 @@ -ImportIsFullyQualified.java:11:1: compiler.err.doesnt.exist: JobAttributes +ImportIsFullyQualified.java:11:8: compiler.err.doesnt.exist: JobAttributes 1 error diff --git a/test/langtools/tools/javac/importChecks/ImportsObservable.out b/test/langtools/tools/javac/importChecks/ImportsObservable.out index e6b6e51e4bb..28ba84c6aa4 100644 --- a/test/langtools/tools/javac/importChecks/ImportsObservable.out +++ b/test/langtools/tools/javac/importChecks/ImportsObservable.out @@ -1,2 +1,2 @@ -ImportsObservable.java:9:1: compiler.err.doesnt.exist: javax +ImportsObservable.java:9:8: compiler.err.doesnt.exist: javax 1 error diff --git a/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java b/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java index cf06bd06dfe..24c2b045800 100644 --- a/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java +++ b/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java @@ -799,7 +799,7 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase { .getOutputLines(Task.OutputKind.DIRECT); List expected = Arrays.asList( - "Test.java:1:31: compiler.err.doesnt.exist: ma", + "Test.java:1:38: compiler.err.doesnt.exist: ma", "1 error"); if (!expected.equals(log)) @@ -827,7 +827,7 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase { .getOutputLines(Task.OutputKind.DIRECT); List expected = Arrays.asList( - "Test.java:1:15: compiler.err.doesnt.exist: ma", + "Test.java:1:22: compiler.err.doesnt.exist: ma", "1 error"); if (!expected.equals(log)) @@ -861,7 +861,7 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase { .getOutputLines(Task.OutputKind.DIRECT); List expected = Arrays.asList( - "Test.java:1:15: compiler.err.doesnt.exist: ma", + "Test.java:1:22: compiler.err.doesnt.exist: ma", "1 error"); if (!expected.equals(log))