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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1477953002: Fix propagated argument element bug. This fixes #25040. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Alternate fix 2 Created 5 years 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_resolver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/context.dart' as newContext; 9 import 'package:analyzer/src/context/context.dart' as newContext;
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 12118 matching lines...) Expand 10 before | Expand all | Expand 10 after
12129 computeLibrarySourceErrors(source); 12129 computeLibrarySourceErrors(source);
12130 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 12130 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
12131 } 12131 }
12132 } 12132 }
12133 12133
12134 /** 12134 /**
12135 * Strong mode static analyzer end to end tests 12135 * Strong mode static analyzer end to end tests
12136 */ 12136 */
12137 @reflectiveTest 12137 @reflectiveTest
12138 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { 12138 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared {
12139 void fail_genericMethod_nested() {
12140 // TODO(jmesserly): this test currently fails because we incorrectly capture
12141 // S in FunctionTypeImpl.substitute. We should probably rename free
12142 // variables during substitution to avoid it.
12143 _resolveTestUnit(r'''
12144 class C<T> {
12145 /*=T*/ f/*<S>*/(/*=S*/ x) {
12146 new C<S>().f/*<int>*/(3);
12147 return null;
12148 }
12149 }
12150 ''');
12151 SimpleIdentifier f = _findIdentifier('f/*<int>*/(3);');
12152 expect(f.staticType.toString(), '(int) → S');
12153 }
12154
12139 void setUp() { 12155 void setUp() {
12140 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 12156 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
12141 options.strongMode = true; 12157 options.strongMode = true;
12142 resetWithOptions(options); 12158 resetWithOptions(options);
12143 } 12159 }
12144 12160
12145 void test_dynamicObjectGetter_hashCode() { 12161 void test_dynamicObjectGetter_hashCode() {
12146 String code = r''' 12162 String code = r'''
12147 main() { 12163 main() {
12148 dynamic a = null; 12164 dynamic a = null;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
12212 expect(e.type.toString(), '(E) → List<T>'); 12228 expect(e.type.toString(), '(E) → List<T>');
12213 12229
12214 SimpleIdentifier c = _findIdentifier('cOfString'); 12230 SimpleIdentifier c = _findIdentifier('cOfString');
12215 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; 12231 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type;
12216 expect(ft.toString(), '(String) → List<T>'); 12232 expect(ft.toString(), '(String) → List<T>');
12217 DartType t = e.typeParameters[0].type; 12233 DartType t = e.typeParameters[0].type;
12218 ft = ft.substitute2([typeProvider.intType], [t]); 12234 ft = ft.substitute2([typeProvider.intType], [t]);
12219 expect(ft.toString(), '(String) → List<int>'); 12235 expect(ft.toString(), '(String) → List<int>');
12220 } 12236 }
12221 12237
12222 void fail_genericMethod_nested() {
12223 // TODO(jmesserly): this test currently fails because we incorrectly capture
12224 // S in FunctionTypeImpl.substitute. We should probably rename free
12225 // variables during substitution to avoid it.
12226 _resolveTestUnit(r'''
12227 class C<T> {
12228 /*=T*/ f/*<S>*/(/*=S*/ x) {
12229 new C<S>().f/*<int>*/(3);
12230 return null;
12231 }
12232 }
12233 ''');
12234 SimpleIdentifier f = _findIdentifier('f/*<int>*/(3);');
12235 expect(f.staticType.toString(), '(int) → S');
12236 }
12237
12238 void test_genericMethod_functionTypedParameter() { 12238 void test_genericMethod_functionTypedParameter() {
12239 if (!AnalysisEngine.instance.useTaskModel) { 12239 if (!AnalysisEngine.instance.useTaskModel) {
12240 return; 12240 return;
12241 } 12241 }
12242 _resolveTestUnit(r''' 12242 _resolveTestUnit(r'''
12243 class C<E> { 12243 class C<E> {
12244 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; 12244 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null;
12245 } 12245 }
12246 main() { 12246 main() {
12247 C<String> cOfString; 12247 C<String> cOfString;
(...skipping 23 matching lines...) Expand all
12271 '''; 12271 ''';
12272 _resolveTestUnit(code); 12272 _resolveTestUnit(code);
12273 12273
12274 SimpleIdentifier identifier = _findIdentifier('foo'); 12274 SimpleIdentifier identifier = _findIdentifier('foo');
12275 VariableDeclaration declaration = 12275 VariableDeclaration declaration =
12276 identifier.getAncestor((node) => node is VariableDeclaration); 12276 identifier.getAncestor((node) => node is VariableDeclaration);
12277 expect(declaration.initializer.staticType.name, 'double'); 12277 expect(declaration.initializer.staticType.name, 'double');
12278 expect(declaration.initializer.propagatedType, isNull); 12278 expect(declaration.initializer.propagatedType, isNull);
12279 } 12279 }
12280 12280
12281 void test_pseudoGeneric_max_doubleDouble_prefixed() {
12282 String code = r'''
12283 import 'dart:math' as math;
12284 main() {
12285 var foo = math.max(1.0, 2.0);
12286 }
12287 ''';
12288 _resolveTestUnit(code);
12289
12290 SimpleIdentifier identifier = _findIdentifier('foo');
12291 VariableDeclaration declaration =
12292 identifier.getAncestor((node) => node is VariableDeclaration);
12293 expect(declaration.initializer.staticType.name, 'double');
12294 expect(declaration.initializer.propagatedType, isNull);
12295 }
12296
12281 void test_pseudoGeneric_max_doubleInt() { 12297 void test_pseudoGeneric_max_doubleInt() {
12282 String code = r''' 12298 String code = r'''
12283 import 'dart:math'; 12299 import 'dart:math';
12284 main() { 12300 main() {
12285 var foo = max(1.0, 2); 12301 var foo = max(1.0, 2);
12286 } 12302 }
12287 '''; 12303 ''';
12288 _resolveTestUnit(code); 12304 _resolveTestUnit(code);
12289 12305
12290 SimpleIdentifier identifier = _findIdentifier('foo'); 12306 SimpleIdentifier identifier = _findIdentifier('foo');
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
12338 _resolveTestUnit(code); 12354 _resolveTestUnit(code);
12339 12355
12340 SimpleIdentifier identifier = _findIdentifier('foo'); 12356 SimpleIdentifier identifier = _findIdentifier('foo');
12341 VariableDeclaration declaration = 12357 VariableDeclaration declaration =
12342 identifier.getAncestor((node) => node is VariableDeclaration); 12358 identifier.getAncestor((node) => node is VariableDeclaration);
12343 12359
12344 expect(declaration.initializer.staticType.toString(), "Future<String>"); 12360 expect(declaration.initializer.staticType.toString(), "Future<String>");
12345 expect(declaration.initializer.propagatedType, isNull); 12361 expect(declaration.initializer.propagatedType, isNull);
12346 } 12362 }
12347 12363
12364 void test_pseudoGeneric_then_prefixed() {
12365 String code = r'''
12366 import 'dart:async' as async;
12367 String toString(int x) => x.toString();
12368 main() {
12369 async.Future<int> bar = null;
12370 var foo = bar.then(toString);
12371 }
12372 ''';
12373 _resolveTestUnit(code);
12374
12375 SimpleIdentifier identifier = _findIdentifier('foo');
12376 VariableDeclaration declaration =
12377 identifier.getAncestor((node) => node is VariableDeclaration);
12378
12379 expect(declaration.initializer.staticType.toString(), "Future<String>");
12380 expect(declaration.initializer.propagatedType, isNull);
12381 }
12382
12348 void test_ternaryOperator_null_left() { 12383 void test_ternaryOperator_null_left() {
12349 String code = r''' 12384 String code = r'''
12350 main() { 12385 main() {
12351 var foo = (true) ? null : 3; 12386 var foo = (true) ? null : 3;
12352 } 12387 }
12353 '''; 12388 ''';
12354 _resolveTestUnit(code); 12389 _resolveTestUnit(code);
12355 12390
12356 SimpleIdentifier identifier = _findIdentifier('foo'); 12391 SimpleIdentifier identifier = _findIdentifier('foo');
12357 VariableDeclaration declaration = 12392 VariableDeclaration declaration =
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
12811 } 12846 }
12812 12847
12813 void test_getType_noScope() { 12848 void test_getType_noScope() {
12814 TypeOverrideManager manager = new TypeOverrideManager(); 12849 TypeOverrideManager manager = new TypeOverrideManager();
12815 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 12850 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
12816 } 12851 }
12817 } 12852 }
12818 12853
12819 @reflectiveTest 12854 @reflectiveTest
12820 class TypePropagationTest extends ResolverTestCase { 12855 class TypePropagationTest extends ResolverTestCase {
12856 void test_invocation_target_prefixed() {
12857 addNamedSource(
12858 '/helper.dart',
12859 '''
12860 library helper;
12861 int max(int x, int y) => 0;
12862 ''');
12863 String code = '''
12864 import 'helper.dart' as helper;
12865 main() {
12866 helper.max(10, 10); // marker
12867 }''';
12868 SimpleIdentifier methodName =
12869 _findMarkedIdentifier(code, "(10, 10); // marker");
12870 MethodInvocation methodInvoke = methodName.parent;
12871 expect(methodInvoke.methodName.staticElement, isNotNull);
12872 expect(methodInvoke.methodName.propagatedElement, isNull);
12873 }
12874
12821 void fail_mergePropagatedTypesAtJoinPoint_1() { 12875 void fail_mergePropagatedTypesAtJoinPoint_1() {
12822 // https://code.google.com/p/dart/issues/detail?id=19929 12876 // https://code.google.com/p/dart/issues/detail?id=19929
12823 _assertTypeOfMarkedExpression( 12877 _assertTypeOfMarkedExpression(
12824 r''' 12878 r'''
12825 f1(x) { 12879 f1(x) {
12826 var y = []; 12880 var y = [];
12827 if (x) { 12881 if (x) {
12828 y = 0; 12882 y = 0;
12829 } else { 12883 } else {
12830 y = ''; 12884 y = '';
(...skipping 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after
15224 15278
15225 void _resolveTestUnit(String code) { 15279 void _resolveTestUnit(String code) {
15226 testCode = code; 15280 testCode = code;
15227 testSource = addSource(testCode); 15281 testSource = addSource(testCode);
15228 LibraryElement library = resolve2(testSource); 15282 LibraryElement library = resolve2(testSource);
15229 assertNoErrors(testSource); 15283 assertNoErrors(testSource);
15230 verify([testSource]); 15284 verify([testSource]);
15231 testUnit = resolveCompilationUnit(testSource, library); 15285 testUnit = resolveCompilationUnit(testSource, library);
15232 } 15286 }
15233 } 15287 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698