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

Unified Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 1124433007: Fix constant evaluation logic for String.length. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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
Index: pkg/analyzer/test/generated/all_the_rest_test.dart
diff --git a/pkg/analyzer/test/generated/all_the_rest_test.dart b/pkg/analyzer/test/generated/all_the_rest_test.dart
index e16bff6bcaef5012f81762d55a1c375fd35f0296..06dad179988e719434dabd705cdcd0d59e8c193f 100644
--- a/pkg/analyzer/test/generated/all_the_rest_test.dart
+++ b/pkg/analyzer/test/generated/all_the_rest_test.dart
@@ -2077,6 +2077,34 @@ const c_num = const C<num>();''');
expect(ConstantValueComputer.isValidPublicSymbol("foo.void"), isFalse);
}
+ void test_length_of_improperly_typed_string_expression() {
+ // Since type annotations are ignored in unchecked mode, the improper
+ // types on s1 and s2 shouldn't prevent us from evaluating i to
+ // 'alpha'.length.
+ CompilationUnit compilationUnit = resolveSource('''
+const int s1 = 'alpha';
+const int s2 = 'beta';
+const int i = (true ? s1 : s2).length;
+''');
+ ConstTopLevelVariableElementImpl element =
+ findTopLevelDeclaration(compilationUnit, 'i').element;
+ EvaluationResultImpl result = element.evaluationResult;
+ expect(_assertValidInt(result), 5);
+ }
+
+ void test_length_of_improperly_typed_string_identifier() {
+ // Since type annotations are ignored in unchecked mode, the improper type
+ // on s shouldn't prevent us from evaluating i to 'alpha'.length.
+ CompilationUnit compilationUnit = resolveSource('''
+const int s = 'alpha';
+const int i = s.length;
+''');
+ ConstTopLevelVariableElementImpl element =
+ findTopLevelDeclaration(compilationUnit, 'i').element;
+ EvaluationResultImpl result = element.evaluationResult;
+ expect(_assertValidInt(result), 5);
+ }
+
void test_symbolLiteral_void() {
CompilationUnit compilationUnit =
resolveSource("const voidSymbol = #void;");
« no previous file with comments | « pkg/analyzer/lib/src/generated/constant.dart ('k') | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698