Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1842433002: When summarize AST, include local variables in loops and try-catch. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/summary_common.dart
diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart
index 0f43fcaca8520e91dee544dab126ee5c235e512e..954002d85439d7387dcf71bde75c4b2538c8bd47 100644
--- a/pkg/analyzer/test/src/summary/summary_common.dart
+++ b/pkg/analyzer/test/src/summary/summary_common.dart
@@ -4359,6 +4359,31 @@ get g {
}
}
+ test_executable_localVariables_catch() {
+ String code = r'''
+f() { // 1
+ try {
+ throw 42;
+ } on int catch (e, st) { // 2
+ print(e);
+ print(st);
+ } // 3
+} // 4
+''';
+ UnlinkedExecutable executable = serializeExecutableText(code);
+ List<UnlinkedVariable> variables = executable.localVariables;
+ expect(variables, hasLength(2));
+ {
+ UnlinkedVariable e = variables.singleWhere((v) => v.name == 'e');
+ _assertVariableVisible(code, e, 'on int catch (', '} // 3');
+ checkTypeRef(e.type, 'dart:core', 'dart:core', 'int');
+ }
+ {
+ UnlinkedVariable st = variables.singleWhere((v) => v.name == 'st');
+ _assertVariableVisible(code, st, 'on int catch (', '} // 3');
+ }
+ }
+
test_executable_localVariables_empty() {
UnlinkedExecutable executable = serializeExecutableText(r'''
f() {
@@ -4367,6 +4392,47 @@ f() {
expect(executable.localVariables, isEmpty);
}
+ test_executable_localVariables_forEachLoop() {
+ String code = r'''
+f() { // 1
+ for (int i in <int>[]) { // 2
+ print(i);
+ } // 3
+} // 4
+''';
+ UnlinkedExecutable executable = serializeExecutableText(code);
+ List<UnlinkedVariable> variables = executable.localVariables;
+ expect(variables, hasLength(1));
+ {
+ UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
+ _assertVariableVisible(code, i, 'for', '} // 3');
+ checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
+ }
+ }
+
+ test_executable_localVariables_forLoop() {
+ String code = r'''
+f() { // 1
+ for (int i = 0, j = 0; i < 10; i++, j++) { // 2
+ print(i);
+ } // 3
+} // 4
+''';
+ UnlinkedExecutable executable = serializeExecutableText(code);
+ List<UnlinkedVariable> variables = executable.localVariables;
+ expect(variables, hasLength(2));
+ {
+ UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
+ _assertVariableVisible(code, i, 'for', '} // 3');
+ checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
+ }
+ {
+ UnlinkedVariable i = variables.singleWhere((v) => v.name == 'j');
+ _assertVariableVisible(code, i, 'for', '} // 3');
+ checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
+ }
+ }
+
test_executable_localVariables_inConstructor() {
String code = r'''
class C {
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698