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

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

Issue 1314793005: Strong mode local variable inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments, add test, fix analyzer warnings 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) 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 runReflectiveTests(TypeProviderImplTest); 61 runReflectiveTests(TypeProviderImplTest);
62 runReflectiveTests(TypeResolverVisitorTest); 62 runReflectiveTests(TypeResolverVisitorTest);
63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest);
64 runReflectiveTests(ErrorResolverTest); 64 runReflectiveTests(ErrorResolverTest);
65 runReflectiveTests(HintCodeTest); 65 runReflectiveTests(HintCodeTest);
66 runReflectiveTests(MemberMapTest); 66 runReflectiveTests(MemberMapTest);
67 runReflectiveTests(NonHintCodeTest); 67 runReflectiveTests(NonHintCodeTest);
68 runReflectiveTests(SimpleResolverTest); 68 runReflectiveTests(SimpleResolverTest);
69 runReflectiveTests(StrictModeTest); 69 runReflectiveTests(StrictModeTest);
70 runReflectiveTests(TypePropagationTest); 70 runReflectiveTests(TypePropagationTest);
71 runReflectiveTests(StrongModeTypePropagationTest);
71 } 72 }
72 73
73 /** 74 /**
74 * The class `AnalysisContextFactory` defines utility methods used to create ana lysis contexts 75 * The class `AnalysisContextFactory` defines utility methods used to create ana lysis contexts
75 * for testing purposes. 76 * for testing purposes.
76 */ 77 */
77 class AnalysisContextFactory { 78 class AnalysisContextFactory {
78 static String _DART_MATH = "dart:math"; 79 static String _DART_MATH = "dart:math";
79 80
80 static String _DART_INTERCEPTORS = "dart:_interceptors"; 81 static String _DART_INTERCEPTORS = "dart:_interceptors";
(...skipping 13463 matching lines...) Expand 10 before | Expand all | Expand 10 after
13544 // assertion failure here should be a failure, in both "test_*" and 13545 // assertion failure here should be a failure, in both "test_*" and
13545 // "fail_*" tests. However, an assertion failure is success for the 13546 // "fail_*" tests. However, an assertion failure is success for the
13546 // purpose of "fail_*" tests, so without catching them here "fail_*" tests 13547 // purpose of "fail_*" tests, so without catching them here "fail_*" tests
13547 // can succeed by failing for the wrong reason. 13548 // can succeed by failing for the wrong reason.
13548 throw new JavaException("Unexexpected assertion failure: $exception"); 13549 throw new JavaException("Unexexpected assertion failure: $exception");
13549 } 13550 }
13550 } 13551 }
13551 } 13552 }
13552 13553
13553 @reflectiveTest 13554 @reflectiveTest
13555 class StrongModeTypePropagationTest extends TypePropagationTest {
13556 void _enterStrongMode() {
Paul Berry 2015/08/27 01:28:11 Consider renaming this method to setUp() and addin
Leaf 2015/08/27 18:15:26 This reveals an issue, actually. I made StrongMod
13557 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
13558 options.strongMode = true;
13559 resetWithOptions(options);
13560 }
13561
13562 void test_localVariableInference_constant() {
13563 _enterStrongMode();
13564 String code = r'''
13565 main() {
13566 var v = 3;
13567 return v; // marker
13568 }''';
13569 _assertPropagatedReturnType(code, typeProvider.intType, null);
13570 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13571 }
13572
13573 void test_localVariableInference_transitive_local() {
13574 _enterStrongMode();
13575 String code = r'''
13576 main() {
13577 var x = 3;
13578 var v = x;
13579 return v; // marker
13580 }''';
13581 _assertPropagatedReturnType(code, typeProvider.intType, null);
13582 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13583 }
13584
13585 void test_localVariableInference_transitive_list_local() {
13586 _enterStrongMode();
13587 String code = r'''
13588 main() {
13589 var x = <int>[3];
13590 var v = x[0];
13591 return v; // marker
13592 }''';
13593 _assertPropagatedReturnType(code, typeProvider.intType, null);
13594 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13595 }
13596
13597 void test_localVariableInference_transitive_toplevel_lexical() {
13598 _enterStrongMode();
13599 String code = r'''
13600 int x = 3;
13601 main() {
13602 var v = x;
13603 return v; // marker
13604 }
13605 ''';
13606 _assertPropagatedReturnType(code, typeProvider.intType, null);
13607 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13608 }
13609
13610 void test_localVariableInference_transitive_toplevel_reversed() {
13611 _enterStrongMode();
13612 String code = r'''
13613 main() {
13614 var v = x;
13615 return v; // marker
13616 }
13617 int x = 3;
13618 ''';
13619 _assertPropagatedReturnType(code, typeProvider.intType, null);
13620 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13621 }
13622
13623 void fail_localVariableInference_transitive_toplevel_inferred_lexical() {
13624 _enterStrongMode();
13625 String code = r'''
13626 final x = 3;
13627 main() {
13628 var v = x;
13629 return v; // marker
13630 }
13631 ''';
13632 _assertPropagatedReturnType(code, typeProvider.intType, null);
13633 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13634 }
13635
13636 void fail_localVariableInference_transitive_toplevel_inferred_reversed() {
13637 _enterStrongMode();
13638 String code = r'''
13639 main() {
13640 var v = x;
13641 return v; // marker
13642 }
13643 final x = 3;
13644 ''';
13645 _assertPropagatedReturnType(code, typeProvider.intType, null);
13646 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13647 }
13648
13649 void test_localVariableInference_transitive_field_lexical() {
13650 _enterStrongMode();
13651 String code = r'''
13652 class A {
13653 int x = 3;
13654 f() {
13655 var v = x;
13656 return v; // marker
13657 }
13658 }
13659 main() {
13660 }
13661 ''';
13662 _assertPropagatedReturnType(code, typeProvider.intType, null);
13663 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13664 }
13665
13666 void test_localVariableInference_transitive_field_reversed() {
13667 _enterStrongMode();
13668 String code = r'''
13669 class A {
13670 f() {
13671 var v = x;
13672 return v; // marker
13673 }
13674 int x = 3;
13675 }
13676 main() {
13677 }
13678 ''';
13679 _assertPropagatedReturnType(code, typeProvider.intType, null);
13680 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13681 }
13682
13683 void fail_localVariableInference_transitive_field_inferred_lexical() {
13684 _enterStrongMode();
13685 String code = r'''
13686 class A {
13687 final x = 3;
13688 f() {
13689 var v = x;
13690 return v; // marker
13691 }
13692 }
13693 main() {
13694 }
13695 ''';
13696 _assertPropagatedReturnType(code, typeProvider.intType, null);
13697 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13698 }
13699
13700 void fail_localVariableInference_transitive_field_inferred_reversed() {
13701 _enterStrongMode();
13702 String code = r'''
13703 class A {
13704 f() {
13705 var v = x;
13706 return v; // marker
13707 }
13708 final x = 3;
13709 }
13710 main() {
13711 }
13712 ''';
13713 _assertPropagatedReturnType(code, typeProvider.intType, null);
13714 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13715 }
13716
13717 void test_localVariableInference_declaredType_disabled() {
13718 _enterStrongMode();
13719 String code = r'''
13720 main() {
13721 dynamic v = 3;
13722 return v; // marker
13723 }''';
13724 _assertPropagatedReturnType(
13725 code, typeProvider.dynamicType, typeProvider.intType);
13726 _assertTypeOfMarkedExpression(
13727 code, typeProvider.dynamicType, typeProvider.intType);
13728 }
13729
13730 void test_localVariableInference_bottom_disabled() {
13731 _enterStrongMode();
13732 String code = r'''
13733 main() {
13734 var v = null;
13735 return v; // marker
13736 }''';
13737 _assertPropagatedReturnType(code, typeProvider.dynamicType, null);
13738 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null);
13739 }
13740
13741 void test_localVariableInference_noInitializer_disabled() {
13742 _enterStrongMode();
13743 String code = r'''
13744 main() {
13745 var v;
13746 v = 3;
13747 return v; // marker
13748 }''';
13749 _assertPropagatedReturnType(
13750 code, typeProvider.dynamicType, typeProvider.intType);
13751 _assertTypeOfMarkedExpression(
13752 code, typeProvider.dynamicType, typeProvider.intType);
13753 }
13754 }
13755
13756 @reflectiveTest
13554 class TypeProviderImplTest extends EngineTestCase { 13757 class TypeProviderImplTest extends EngineTestCase {
13555 void test_creation() { 13758 void test_creation() {
13556 // 13759 //
13557 // Create a mock library element with the types expected to be in dart:core. 13760 // Create a mock library element with the types expected to be in dart:core.
13558 // We cannot use either ElementFactory or TestTypeProvider (which uses 13761 // We cannot use either ElementFactory or TestTypeProvider (which uses
13559 // ElementFactory) because we side-effect the elements in ways that would 13762 // ElementFactory) because we side-effect the elements in ways that would
13560 // break other tests. 13763 // break other tests.
13561 // 13764 //
13562 InterfaceType objectType = _classElement("Object", null).type; 13765 InterfaceType objectType = _classElement("Object", null).type;
13563 InterfaceType boolType = _classElement("bool", objectType).type; 13766 InterfaceType boolType = _classElement("bool", objectType).type;
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
14327 // check propagated type 14530 // check propagated type
14328 FunctionType propagatedType = node.propagatedType as FunctionType; 14531 FunctionType propagatedType = node.propagatedType as FunctionType;
14329 expect(propagatedType.returnType, test.typeProvider.stringType); 14532 expect(propagatedType.returnType, test.typeProvider.stringType);
14330 } on AnalysisException catch (e, stackTrace) { 14533 } on AnalysisException catch (e, stackTrace) {
14331 thrownException[0] = new CaughtException(e, stackTrace); 14534 thrownException[0] = new CaughtException(e, stackTrace);
14332 } 14535 }
14333 } 14536 }
14334 return null; 14537 return null;
14335 } 14538 }
14336 } 14539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698