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

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

Issue 2239613002: Issue 27053. Record errors in InferStaticVariableTypeTask and include them into unit errors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 analyzer.test.src.task.dart_test; 5 library analyzer.test.src.task.dart_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 2981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 2992 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2993 TopLevelVariableDeclaration declaration = unit.declarations[1]; 2993 TopLevelVariableDeclaration declaration = unit.declarations[1];
2994 FunctionExpression function = 2994 FunctionExpression function =
2995 declaration.variables.variables[0].initializer; 2995 declaration.variables.variables[0].initializer;
2996 BlockFunctionBody body = function.body; 2996 BlockFunctionBody body = function.body;
2997 ReturnStatement statement = body.block.statements[0]; 2997 ReturnStatement statement = body.block.statements[0];
2998 Expression expression = statement.expression; 2998 Expression expression = statement.expression;
2999 InterfaceType intType = context.typeProvider.intType; 2999 InterfaceType intType = context.typeProvider.intType;
3000 expect(expression.staticType, intType); 3000 expect(expression.staticType, intType);
3001 } 3001 }
3002
3003 test_staticModeHints_forStaticVariableInference() {
3004 context.analysisOptions =
3005 new AnalysisOptionsImpl.from(context.analysisOptions)
3006 ..strongModeHints = true;
3007 Source source = newSource(
3008 '/test.dart',
3009 r'''
3010 var V = [42];
3011 ''');
3012 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3013 computeResult(target, RESOLVED_UNIT9);
3014 expect(outputs[RESOLVED_UNIT9], isNotNull);
3015 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue);
3016 // An INFERRED_TYPE_LITERAL error should be generated.
3017 List<AnalysisError> errors = outputs[
3018 STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] as List<AnalysisError>;
3019 expect(errors, hasLength(1));
3020 expect(errors[0].errorCode, StrongModeCode.INFERRED_TYPE_LITERAL);
3021 }
3002 } 3022 }
3003 3023
3004 @reflectiveTest 3024 @reflectiveTest
3005 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest { 3025 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest {
3006 void test_getDeclaration_staticField() { 3026 void test_getDeclaration_staticField() {
3007 AnalysisTarget source = newSource( 3027 AnalysisTarget source = newSource(
3008 '/test.dart', 3028 '/test.dart',
3009 ''' 3029 '''
3010 class C { 3030 class C {
3011 var field = ''; 3031 var field = '';
(...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after
5852 /** 5872 /**
5853 * Fill [errorListener] with [result] errors in the current [task]. 5873 * Fill [errorListener] with [result] errors in the current [task].
5854 */ 5874 */
5855 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 5875 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
5856 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; 5876 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>;
5857 expect(errors, isNotNull, reason: result.name); 5877 expect(errors, isNotNull, reason: result.name);
5858 errorListener = new GatheringErrorListener(); 5878 errorListener = new GatheringErrorListener();
5859 errorListener.addAll(errors); 5879 errorListener.addAll(errors);
5860 } 5880 }
5861 } 5881 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698