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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1319703003: Handle cycles when infering static variables (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 2111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 VariableElement topLevel = 2122 VariableElement topLevel =
2123 getTopLevelVariable(unit, 'topLevel').name.staticElement; 2123 getTopLevelVariable(unit, 'topLevel').name.staticElement;
2124 VariableElement field = 2124 VariableElement field =
2125 getFieldInClass(unit, 'C', 'field').name.staticElement; 2125 getFieldInClass(unit, 'C', 'field').name.staticElement;
2126 2126
2127 computeResult(field, INFERRED_STATIC_VARIABLE); 2127 computeResult(field, INFERRED_STATIC_VARIABLE);
2128 InterfaceType stringType = context.typeProvider.stringType; 2128 InterfaceType stringType = context.typeProvider.stringType;
2129 expect(topLevel.type, stringType); 2129 expect(topLevel.type, stringType);
2130 expect(field.type, stringType); 2130 expect(field.type, stringType);
2131 } 2131 }
2132
2133 void test_perform_cycle() {
2134 AnalysisTarget source = newSource(
2135 '/test.dart',
2136 '''
2137 var piFirst = true;
2138 var pi = piFirst ? 3.14 : tau / 2;
2139 var tau = piFirst ? pi * 2 : 6.28;
2140 ''');
2141 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2142 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2143 VariableElement piFirst =
2144 getTopLevelVariable(unit, 'piFirst').name.staticElement;
2145 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement;
2146 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement;
2147
2148 computeResult(piFirst, INFERRED_STATIC_VARIABLE);
2149 expect(piFirst.type, context.typeProvider.boolType);
2150 expect(pi.type.isDynamic, isTrue);
2151 expect(tau.type.isDynamic, isTrue);
2152 }
2153
2154 void test_perform_null() {
2155 AnalysisTarget source = newSource(
2156 '/test.dart',
2157 '''
2158 var a = null;
2159 ''');
2160 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2161 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2162 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
2163
2164 computeResult(a, INFERRED_STATIC_VARIABLE);
2165 expect(a.type.isDynamic, isTrue);
2166 }
2132 } 2167 }
2133 2168
2134 @reflectiveTest 2169 @reflectiveTest
2135 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { 2170 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest {
2136 test_perform() { 2171 test_perform() {
2137 Source library = newSource( 2172 Source library = newSource(
2138 '/lib.dart', 2173 '/lib.dart',
2139 r''' 2174 r'''
2140 library lib; 2175 library lib;
2141 part 'part1.dart'; 2176 part 'part1.dart';
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
3048 /** 3083 /**
3049 * Fill [errorListener] with [result] errors in the current [task]. 3084 * Fill [errorListener] with [result] errors in the current [task].
3050 */ 3085 */
3051 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 3086 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
3052 List<AnalysisError> errors = task.outputs[result]; 3087 List<AnalysisError> errors = task.outputs[result];
3053 expect(errors, isNotNull, reason: result.name); 3088 expect(errors, isNotNull, reason: result.name);
3054 errorListener = new GatheringErrorListener(); 3089 errorListener = new GatheringErrorListener();
3055 errorListener.addAll(errors); 3090 errorListener.addAll(errors);
3056 } 3091 }
3057 } 3092 }
OLDNEW
« pkg/analyzer/lib/src/task/dart.dart ('K') | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698