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

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

Issue 2640143007: Issue 28100. Implement new strong mode instantiate to bound rules in analyzer. (Closed)
Patch Set: Fixes for review comments. Created 3 years, 11 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.generated.strong_mode_test; 5 library analyzer.test.generated.strong_mode_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 check("f2", _isListOf(_isInt)); 1292 check("f2", _isListOf(_isInt));
1293 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type))); 1293 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type)));
1294 } 1294 }
1295 } 1295 }
1296 1296
1297 /** 1297 /**
1298 * Strong mode static analyzer end to end tests 1298 * Strong mode static analyzer end to end tests
1299 */ 1299 */
1300 @reflectiveTest 1300 @reflectiveTest
1301 class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared { 1301 class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared {
1302 void expectStaticInvokeType(String search, String type) {
1303 var invocation = findIdentifier(search).parent as MethodInvocation;
1304 expect(invocation.staticInvokeType.toString(), type);
1305 }
1306
1302 fail_genericMethod_tearoff_instantiated() async { 1307 fail_genericMethod_tearoff_instantiated() async {
1303 await resolveTestUnit(r''' 1308 await resolveTestUnit(r'''
1304 class C<E> { 1309 class C<E> {
1305 /*=T*/ f/*<T>*/(E e) => null; 1310 /*=T*/ f/*<T>*/(E e) => null;
1306 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; 1311 static /*=T*/ g/*<T>*/(/*=T*/ e) => null;
1307 static final h = g; 1312 static final h = g;
1308 } 1313 }
1309 1314
1310 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; 1315 /*=T*/ topF/*<T>*/(/*=T*/ e) => null;
1311 var topG = topF; 1316 var topG = topF;
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 '''; 1957 ''';
1953 await resolveTestUnit(code, noErrors: false); 1958 await resolveTestUnit(code, noErrors: false);
1954 expectIdentifierType('ai', "A<dynamic>"); 1959 expectIdentifierType('ai', "A<dynamic>");
1955 expectIdentifierType('bi', "B<num>"); 1960 expectIdentifierType('bi', "B<num>");
1956 expectIdentifierType('ci', "C<int, B<int>, B<dynamic>>"); 1961 expectIdentifierType('ci', "C<int, B<int>, B<dynamic>>");
1957 expectIdentifierType('aa', "A<dynamic>"); 1962 expectIdentifierType('aa', "A<dynamic>");
1958 expectIdentifierType('bb', "B<num>"); 1963 expectIdentifierType('bb', "B<num>");
1959 expectIdentifierType('cc', "C<int, B<int>, B<dynamic>>"); 1964 expectIdentifierType('cc', "C<int, B<int>, B<dynamic>>");
1960 } 1965 }
1961 1966
1967 test_instantiateToBounds_class_error_recursion() async {
1968 String code = r'''
1969 class C<T0 extends List<T1>, T1 extends List<T0>> {}
1970 C c;
1971 ''';
1972 await resolveTestUnit(code, noErrors: false);
1973 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]);
1974 expectIdentifierType('c;', 'C<dynamic, dynamic>');
1975 }
1976
1977 test_instantiateToBounds_class_error_recursion_self() async {
1978 String code = r'''
1979 class C<T extends C<T>> {}
1980 C c;
1981 ''';
1982 await resolveTestUnit(code, noErrors: false);
1983 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]);
1984 expectIdentifierType('c;', 'C<dynamic>');
1985 }
1986
1987 test_instantiateToBounds_class_error_recursion_self2() async {
1988 String code = r'''
1989 class A<E> {}
1990 class C<T extends A<T>> {}
1991 C c;
1992 ''';
1993 await resolveTestUnit(code, noErrors: false);
1994 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]);
1995 expectIdentifierType('c;', 'C<dynamic>');
1996 }
1997
1998 test_instantiateToBounds_class_ok_referenceOther_after() async {
1999 String code = r'''
2000 class C<T0 extends T1, T1 extends int> {}
2001 C c;
2002 ''';
2003 await resolveTestUnit(code);
2004 assertNoErrors(testSource);
2005 expectIdentifierType('c;', 'C<int, int>');
2006 }
2007
2008 test_instantiateToBounds_class_ok_referenceOther_after2() async {
2009 String code = r'''
2010 class C<T0 extends Map<T1, T1>, T1 extends int> {}
2011 C c;
2012 ''';
2013 await resolveTestUnit(code);
2014 assertNoErrors(testSource);
2015 expectIdentifierType('c;', 'C<Map<int, int>, int>');
2016 }
2017
2018 test_instantiateToBounds_class_ok_referenceOther_before() async {
2019 String code = r'''
2020 class C<T0 extends int, T1 extends T0> {}
2021 C c;
2022 ''';
2023 await resolveTestUnit(code);
2024 assertNoErrors(testSource);
2025 expectIdentifierType('c;', 'C<int, int>');
2026 }
2027
2028 test_instantiateToBounds_class_ok_referenceOther_multi() async {
2029 String code = r'''
2030 class C<T0 extends Map<T1, T2>, T1 extends List<T2>, T2 extends int> {}
2031 C c;
2032 ''';
2033 await resolveTestUnit(code);
2034 assertNoErrors(testSource);
2035 expectIdentifierType('c;', 'C<Map<List<int>, int>, List<int>, int>');
2036 }
2037
2038 test_instantiateToBounds_class_ok_simpleBounds() async {
2039 String code = r'''
2040 class A<T> {}
2041 class B<T extends num> {}
2042 class C<T extends List<int>> {}
2043
2044 void main() {
2045 A a;
2046 B b;
2047 C c;
2048 }
2049 ''';
2050 await resolveTestUnit(code);
2051 assertNoErrors(testSource);
2052 expectIdentifierType('a;', 'A<dynamic>');
2053 expectIdentifierType('b;', 'B<num>');
2054 expectIdentifierType('c;', 'C<List<int>>');
2055 }
2056
2057 /**
2058 * See https://github.com/dart-lang/sdk/issues/27725
2059 *
2060 * TypeParameterMember.== is not implemented
2061 */
2062 @failingTest
2063 test_instantiateToBounds_method_ok_referenceOther_before() async {
2064 String code = r'''
2065 class C<T> {
2066 void m<S0 extends T, S1 extends List<S0>>(S0 p0, S1 p1) {}
2067
2068 void main() {
2069 m(null, null);
2070 }
2071 }
2072 ''';
2073 await resolveTestUnit(code);
2074 assertNoErrors(testSource);
2075 expectStaticInvokeType('m(null', '(T, List<T>) → void');
2076 }
2077
2078 test_instantiateToBounds_method_ok_simpleBounds() async {
2079 String code = r'''
2080 class C<T> {
2081 void m<S extends T>(S p0) {}
2082
2083 void main() {
2084 m(null);
2085 }
2086 }
2087 ''';
2088 await resolveTestUnit(code);
2089 assertNoErrors(testSource);
2090 expectStaticInvokeType('m(null)', '(T) → void');
2091 }
2092
1962 test_notInstantiatedBound_direct() async { 2093 test_notInstantiatedBound_direct() async {
1963 String code = r''' 2094 String code = r'''
1964 class A<T> {} 2095 class A<T> {}
1965 class C<T extends A> {} 2096 class C<T extends A> {}
1966 '''; 2097 ''';
1967 await resolveTestUnit(code, noErrors: false); 2098 await resolveTestUnit(code, noErrors: false);
1968 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]); 2099 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]);
1969 } 2100 }
1970 2101
1971 test_notInstantiatedBound_indirect() async { 2102 test_notInstantiatedBound_indirect() async {
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 main() { 2575 main() {
2445 var v = x; 2576 var v = x;
2446 v; // marker 2577 v; // marker
2447 } 2578 }
2448 int x = 3; 2579 int x = 3;
2449 '''; 2580 ''';
2450 await assertPropagatedAssignedType(code, typeProvider.intType, null); 2581 await assertPropagatedAssignedType(code, typeProvider.intType, null);
2451 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); 2582 await assertTypeOfMarkedExpression(code, typeProvider.intType, null);
2452 } 2583 }
2453 } 2584 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698