From c53f70509c34db8ecc69cf1bfa015d78889c2777 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Thu, 8 Dec 2022 15:02:04 +0000 Subject: [PATCH] [dds/dap] Filter private getters from debug views These will fail unless the current stack frame happens to be in the library that declares them, which results in a lot of exceptions being shown in variable views. Fixes https://github.com/Dart-Code/Dart-Code/issues/4296. Change-Id: I5919e391f25a08920dcdf1bf648526d175af00f1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274040 Commit-Queue: Ben Konyi Reviewed-by: Ben Konyi --- pkg/dds/lib/src/dap/protocol_converter.dart | 4 ++- .../dap/integration/debug_variables_test.dart | 32 ++++++------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/pkg/dds/lib/src/dap/protocol_converter.dart b/pkg/dds/lib/src/dap/protocol_converter.dart index ab7574bc303..b34eb018d01 100644 --- a/pkg/dds/lib/src/dap/protocol_converter.dart +++ b/pkg/dds/lib/src/dap/protocol_converter.dart @@ -592,7 +592,9 @@ class ProtocolConverter { f.json?['_kind'] == 'GetterFunction' && !(f.isStatic ?? false) && !(f.isConst ?? false)); - getterNames.addAll(instanceFields.map((f) => f.name!)); + getterNames.addAll(instanceFields + .map((f) => f.name!) + .where((name) => !name.startsWith('_'))); } classRef = classResponse.superClass; diff --git a/pkg/dds/test/dap/integration/debug_variables_test.dart b/pkg/dds/test/dap/integration/debug_variables_test.dart index 25894eb979b..939b46c7d29 100644 --- a/pkg/dds/test/dap/integration/debug_variables_test.dart +++ b/pkg/dds/test/dap/integration/debug_variables_test.dart @@ -123,13 +123,17 @@ void main(List args) { ); }); - test('includes variable getters when evaluateGettersInDebugViews=true', + test('includes public getters when evaluateGettersInDebugViews=true', () async { final client = dap.client; final testFile = dap.createTestFile(''' void main(List args) { - final myVariable = DateTime(2000, 1, 1); + final myVariable = A(); print('Hello!'); $breakpointMarker +} +class A { + String get publicString => ''; + String get _privateString => ''; } '''); final breakpointLine = lineWith(testFile, breakpointMarker); @@ -145,28 +149,12 @@ void main(List args) { await client.expectLocalVariable( stop.threadId!, expectedName: 'myVariable', - expectedDisplayString: 'DateTime', + expectedDisplayString: 'A', expectedVariables: ''' - day: 1, eval: myVariable.day - hour: 0, eval: myVariable.hour - isUtc: false, eval: myVariable.isUtc - microsecond: 0, eval: myVariable.microsecond - millisecond: 0, eval: myVariable.millisecond - minute: 0, eval: myVariable.minute - month: 1, eval: myVariable.month - runtimeType: Type (DateTime), eval: myVariable.runtimeType - second: 0, eval: myVariable.second - timeZoneOffset: Duration, eval: myVariable.timeZoneOffset - weekday: 6, eval: myVariable.weekday - year: 2000, eval: myVariable.year + publicString: "", eval: myVariable.publicString + runtimeType: Type (A), eval: myVariable.runtimeType ''', - ignore: { - // Don't check fields that may very based on timezone as it'll make - // these tests fragile, and this isn't really what's being tested. - 'timeZoneName', - 'microsecondsSinceEpoch', - 'millisecondsSinceEpoch', - }, + ignorePrivate: false, ); });