From cb03b3ca2c0916da8b050c59ec5be5f1ead495a5 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 25 Nov 2025 10:34:56 -0800 Subject: [PATCH] [analysis_server] Ensure context messages have an integration test for legacy Fixes https://github.com/dart-lang/sdk/issues/44907 Change-Id: I2535f7ebf24da4abea21e32eff58087925d45345 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464540 Reviewed-by: Samuel Rawlins Reviewed-by: Brian Wilkerson Commit-Queue: Brian Wilkerson --- .../integration_test/analysis/error_test.dart | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/analysis_server/integration_test/analysis/error_test.dart b/pkg/analysis_server/integration_test/analysis/error_test.dart index cf7b681994d..07ef7380d19 100644 --- a/pkg/analysis_server/integration_test/analysis/error_test.dart +++ b/pkg/analysis_server/integration_test/analysis/error_test.dart @@ -118,6 +118,30 @@ void f() { expect(currentAnalysisErrors[fileToDeletePath], isNotNull); } + Future test_contextMessage() async { + var pathname = sourcePath('test.dart'); + writeFile(pathname, ''' +void f() { + x = 0; + int x = 1; + x; +}'''); + await standardAnalysisSetup(); + + await analysisFinished; + expect(currentAnalysisErrors[pathname], isList); + var errors = existingErrorsForFile(pathname); + var error = errors.single; + expect( + error.message, + "Local variable 'x' can't be referenced before it is declared.", + ); + expect( + error.contextMessages!.single.message, + "The declaration of 'x' is here.", + ); + } + Future test_detect_simple_error() async { var pathname = sourcePath('test.dart'); writeFile(pathname, '''