With summary2 FunctionTypedFormalParameter has type parameters.
This re-applies changes to tests from https://dart-review.googlesource.com/c/sdk/+/100620
R=brianwilkerson@google.com
Change-Id: If6721d2febb39b52277fdb39845bb2486cb6eb47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/declaration_resolver.dart b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
index 5048a17..81f10fc 100644
--- a/pkg/analyzer/lib/src/generated/declaration_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
@@ -437,7 +437,8 @@
@override
void visitTypeParameter(TypeParameter node) {
- if (node.parent.parent is FunctionTypedFormalParameter) {
+ if (node.parent.parent is FunctionTypedFormalParameter &&
+ !AnalysisDriver.useSummary2) {
// Work around dartbug.com/28515.
// TODO(paulberry): remove this once dartbug.com/28515 is fixed.
var element = new TypeParameterElementImpl.forNode(node.name);
diff --git a/pkg/analyzer/test/generated/compile_time_error_code.dart b/pkg/analyzer/test/generated/compile_time_error_code.dart
index 9006d01..e11ba55 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code.dart
@@ -6,6 +6,7 @@
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/error/error.dart';
+import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
@@ -1874,18 +1875,23 @@
}
test_genericFunctionTypedParameter() async {
- // Once dartbug.com/28515 is fixed, this syntax should no longer generate an
- // error.
- await assertErrorsInCode('''
+ var code = '''
void g(T f<T>(T x)) {}
-''', [
- // Due to dartbug.com/28515, some additional errors appear when using the
- // new analysis driver.
- error(StaticWarningCode.UNDEFINED_CLASS, 7, 1),
- error(
- CompileTimeErrorCode.GENERIC_FUNCTION_TYPED_PARAM_UNSUPPORTED, 7, 11),
- error(StaticWarningCode.UNDEFINED_CLASS, 14, 1),
- ]);
+''';
+ if (AnalysisDriver.useSummary2) {
+ await assertNoErrorsInCode(code);
+ } else {
+ // Once dartbug.com/28515 is fixed, this syntax should no longer generate an
+ // error.
+ await assertErrorsInCode(code, [
+ // Due to dartbug.com/28515, some additional errors appear when using the
+ // new analysis driver.
+ error(StaticWarningCode.UNDEFINED_CLASS, 7, 1),
+ error(CompileTimeErrorCode.GENERIC_FUNCTION_TYPED_PARAM_UNSUPPORTED, 7,
+ 11),
+ error(StaticWarningCode.UNDEFINED_CLASS, 14, 1),
+ ]);
+ }
}
test_implementsDeferredClass() async {
diff --git a/pkg/analyzer/test/generated/strong_mode_test.dart b/pkg/analyzer/test/generated/strong_mode_test.dart
index 3c538c8..4d44cbd 100644
--- a/pkg/analyzer/test/generated/strong_mode_test.dart
+++ b/pkg/analyzer/test/generated/strong_mode_test.dart
@@ -2698,8 +2698,12 @@
var stmts = body.block.statements;
for (ExpressionStatement stmt in stmts) {
MethodInvocation invoke = stmt.expression;
- ParameterizedType fType = invoke.staticInvokeType;
- expect(fType.typeArguments[0].toString(), 'T');
+ FunctionType fType = invoke.staticInvokeType;
+ if (AnalysisDriver.useSummary2) {
+ expect('$fType', '((T) → T, (T, T) → int, (T) → T) → void');
+ } else {
+ expect(fType.typeArguments[0].toString(), 'T');
+ }
}
}
@@ -3902,76 +3906,18 @@
}
@reflectiveTest
-class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared
- with StrongModeStaticTypeAnalyzer2TestCases {
+class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared {
+ void expectStaticInvokeType(String search, String type) {
+ var invocation = findIdentifier(search).parent as MethodInvocation;
+ expect(invocation.staticInvokeType.toString(), type);
+ }
+
void setUp() {
super.setUp();
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
resetWith(options: options);
}
- @failingTest
- @override
- test_genericFunction_parameter() {
- return super.test_genericFunction_parameter();
- }
-
- @failingTest
- @override
- test_genericMethod_functionExpressionInvocation_functionTypedParameter_explicit() {
- return super
- .test_genericMethod_functionExpressionInvocation_functionTypedParameter_explicit();
- }
-
- @failingTest
- @override
- test_genericMethod_functionExpressionInvocation_functionTypedParameter_inferred() {
- return super
- .test_genericMethod_functionExpressionInvocation_functionTypedParameter_inferred();
- }
-
- @failingTest
- @override
- test_genericMethod_functionInvocation_functionTypedParameter_explicit() {
- return super
- .test_genericMethod_functionInvocation_functionTypedParameter_explicit();
- }
-
- @failingTest
- @override
- test_genericMethod_functionInvocation_functionTypedParameter_inferred() {
- return super
- .test_genericMethod_functionInvocation_functionTypedParameter_inferred();
- }
-
- @failingTest
- @override
- test_genericMethod_functionTypedParameter_tearoff() {
- return super.test_genericMethod_functionTypedParameter_tearoff();
- }
-
- @override
- @failingTest
- test_genericMethod_nestedCaptureBounds() {
- // https://github.com/dart-lang/sdk/issues/30236
- return super.test_genericMethod_nestedCaptureBounds();
- }
-
- @override
- @failingTest
- test_genericMethod_tearoff_instantiated() {
- return super.test_genericMethod_tearoff_instantiated();
- }
-}
-
-/// Test cases for [StrongModeStaticTypeAnalyzer2Test]
-mixin StrongModeStaticTypeAnalyzer2TestCases
- implements StaticTypeAnalyzer2TestShared {
- void expectStaticInvokeType(String search, String type) {
- var invocation = findIdentifier(search).parent as MethodInvocation;
- expect(invocation.staticInvokeType.toString(), type);
- }
-
test_dynamicObjectGetter_hashCode() async {
String code = r'''
main() {
@@ -4053,15 +3999,13 @@
}
test_genericFunction_parameter() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
void g(T f<T>(T x)) {}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
- expectFunctionType('f', '<T>(T) → T',
- elementTypeParams: '[]', typeFormals: '[T]');
- SimpleIdentifier f = findIdentifier('f');
- ParameterElementImpl e = f.staticElement;
- FunctionType type = e.type;
+''');
+ var type = expectFunctionType2('f', '<T>(T) → T');
FunctionType ft = type.instantiate([typeProvider.stringType]);
expect(ft.toString(), '(String) → String');
}
@@ -4226,26 +4170,33 @@
}
test_genericMethod_functionExpressionInvocation_functionTypedParameter_explicit() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
void test<S>(T pf<T>(T e)) {
var paramCall = (pf)<int>(3);
}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
+''');
expectIdentifierType('paramCall', "int");
}
test_genericMethod_functionExpressionInvocation_functionTypedParameter_inferred() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
void test<S>(T pf<T>(T e)) {
var paramCall = (pf)(3);
}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
+''');
expectIdentifierType('paramCall', "int");
}
test_genericMethod_functionExpressionInvocation_inferred() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
class C<E> {
T f<T>(T e) => null;
@@ -4268,8 +4219,7 @@
var localCall = (lf)(3);
var paramCall = (pf)(3);
}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
+''');
expectIdentifierType('methodCall', "int");
expectIdentifierType('staticCall', "int");
expectIdentifierType('staticFieldCall', "int");
@@ -4312,22 +4262,26 @@
}
test_genericMethod_functionInvocation_functionTypedParameter_explicit() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
void test<S>(T pf<T>(T e)) {
var paramCall = pf<int>(3);
}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
+''');
expectIdentifierType('paramCall', "int");
}
test_genericMethod_functionInvocation_functionTypedParameter_inferred() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
void test<S>(T pf<T>(T e)) {
var paramCall = pf(3);
}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
+''');
expectIdentifierType('paramCall', "int");
}
@@ -4385,12 +4339,14 @@
}
test_genericMethod_functionTypedParameter_tearoff() async {
+ // TODO(paulberry): remove when dartbug.com/28515 fixed.
+ if (!AnalysisDriver.useSummary2) return;
+
await resolveTestUnit(r'''
void test<S>(T pf<T>(T e)) {
var paramTearOff = pf;
}
-''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed.
- );
+''');
expectIdentifierType('paramTearOff', "<T>(T) → T");
}
@@ -4501,6 +4457,7 @@
expectIdentifierType('f;', '<S₀>(S₀) → S');
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/30236')
test_genericMethod_nestedCaptureBounds() async {
await resolveTestUnit(r'''
class C<T> {
@@ -4710,6 +4667,7 @@
expectIdentifierType('paramTearOff', "<T>(T) → T");
}
+ @failingTest
test_genericMethod_tearoff_instantiated() async {
await resolveTestUnit(r'''
class C<E> {