From 15a9003bade84d263b8f46feefa22a3738b2f416 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 10 Sep 2021 12:25:32 -0700 Subject: [PATCH 1/2] constructor tearoffs testing --- test/end2end/model_special_cases_test.dart | 46 +++++++++++++++++++ .../lib/constructor_tearoffs.dart | 18 ++++++++ 2 files changed, 64 insertions(+) diff --git a/test/end2end/model_special_cases_test.dart b/test/end2end/model_special_cases_test.dart index e953a06ee4..636b947060 100644 --- a/test/end2end/model_special_cases_test.dart +++ b/test/end2end/model_special_cases_test.dart @@ -228,6 +228,52 @@ void main() { expect(referenceLookup(A, 'new'), equals(MatchingLinkResult(null))); expect(referenceLookup(At, 'new'), equals(MatchingLinkResult(null))); }); + + test('constant rendering', () { + TopLevelVariable aFunc, + aFuncParams, + aTearOffDefaultConstructor, + aTearOffNonDefaultConstructor, + aTearOffNonDefaultConstructorInt, + aTearOffDefaultConstructorArgs; + TopLevelVariable aTearOffDefaultConstructorTypedef, + aTearOffDefaultConstructorArgsTypedef; + aFunc = + constructorTearoffs.constants.firstWhere((c) => c.name == 'aFunc'); + aFuncParams = constructorTearoffs.constants + .firstWhere((c) => c.name == 'aFuncParams'); + aTearOffDefaultConstructor = constructorTearoffs.constants + .firstWhere((c) => c.name == 'aTearOffDefaultConstructor'); + aTearOffNonDefaultConstructor = constructorTearoffs.constants + .firstWhere((c) => c.name == 'aTearOffNonDefaultConstructor'); + aTearOffNonDefaultConstructorInt = constructorTearoffs.constants + .firstWhere((c) => c.name == 'aTearOffNonDefaultConstructorInt'); + aTearOffDefaultConstructorArgs = constructorTearoffs.constants + .firstWhere((c) => c.name == 'aTearOffDefaultConstructorArgs'); + aTearOffDefaultConstructorTypedef = constructorTearoffs.constants + .firstWhere((c) => c.name == 'aTearOffDefaultConstructorTypedef'); + aTearOffDefaultConstructorArgsTypedef = constructorTearoffs.constants + .firstWhere( + (c) => c.name == 'aTearOffDefaultConstructorArgsTypedef'); + + expect(aFunc.constantValue, equals('func')); + expect(aFuncParams.constantValue, equals('funcTypeParams')); + // Does not work @ analyzer 2.2 + //expect(aFuncWithArgs.constantValue, equals('funcTypeParams<String, int>')); + + expect(aTearOffDefaultConstructor.constantValue, equals('F.new')); + expect(aTearOffNonDefaultConstructor.constantValue, + equals('F.alternative')); + expect(aTearOffNonDefaultConstructorInt.constantValue, + equals('F<int>.alternative')); + expect(aTearOffDefaultConstructorArgs.constantValue, + equals('F<String>.new')); + + expect(aTearOffDefaultConstructorTypedef.constantValue, + equals('Fstring.new')); + expect(aTearOffDefaultConstructorArgsTypedef.constantValue, + equals('Ft<String>.new')); + }); }, skip: !_constructorTearoffsAllowed.allows(utils.platformVersion)); }); diff --git a/testing/test_package_experiments/lib/constructor_tearoffs.dart b/testing/test_package_experiments/lib/constructor_tearoffs.dart index 722f4e4bde..e27c41d839 100644 --- a/testing/test_package_experiments/lib/constructor_tearoffs.dart +++ b/testing/test_package_experiments/lib/constructor_tearoffs.dart @@ -46,6 +46,8 @@ class F { F() { print('I too am a valid constructor invocation with this feature.'); } + + F.alternative() {} } typedef Ft = F; @@ -59,3 +61,19 @@ typedef NotAClass = Function; /// Mixins don't have constructors either, so disallow `M.new`. mixin M on C { } + +void func() {} +void funcTypeParams(T something, U different) {} + +const aFunc = func; +const aFuncParams = funcTypeParams; +// TODO(jcollins-g): does not work @ analyzer 2.2 +//const aFuncWithArgs = funcTypeParams; + +const aTearOffDefaultConstructor = F.new; +const aTearOffNonDefaultConstructor = F.alternative; +const aTearOffNonDefaultConstructorInt = F.alternative; +const aTearOffDefaultConstructorArgs = F.new; + +const aTearOffDefaultConstructorTypedef = Fstring.new; +const aTearOffDefaultConstructorArgsTypedef = Ft.new; \ No newline at end of file From 90e89bd07fa9ec76b5abb2bc51570ad818a1cc14 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 10 Sep 2021 12:51:33 -0700 Subject: [PATCH 2/2] another construct that analyzer doesn't like --- test/end2end/model_special_cases_test.dart | 11 ++++------- .../lib/constructor_tearoffs.dart | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/end2end/model_special_cases_test.dart b/test/end2end/model_special_cases_test.dart index 636b947060..58f982265d 100644 --- a/test/end2end/model_special_cases_test.dart +++ b/test/end2end/model_special_cases_test.dart @@ -236,8 +236,7 @@ void main() { aTearOffNonDefaultConstructor, aTearOffNonDefaultConstructorInt, aTearOffDefaultConstructorArgs; - TopLevelVariable aTearOffDefaultConstructorTypedef, - aTearOffDefaultConstructorArgsTypedef; + TopLevelVariable aTearOffDefaultConstructorTypedef; aFunc = constructorTearoffs.constants.firstWhere((c) => c.name == 'aFunc'); aFuncParams = constructorTearoffs.constants @@ -252,9 +251,6 @@ void main() { .firstWhere((c) => c.name == 'aTearOffDefaultConstructorArgs'); aTearOffDefaultConstructorTypedef = constructorTearoffs.constants .firstWhere((c) => c.name == 'aTearOffDefaultConstructorTypedef'); - aTearOffDefaultConstructorArgsTypedef = constructorTearoffs.constants - .firstWhere( - (c) => c.name == 'aTearOffDefaultConstructorArgsTypedef'); expect(aFunc.constantValue, equals('func')); expect(aFuncParams.constantValue, equals('funcTypeParams')); @@ -271,8 +267,9 @@ void main() { expect(aTearOffDefaultConstructorTypedef.constantValue, equals('Fstring.new')); - expect(aTearOffDefaultConstructorArgsTypedef.constantValue, - equals('Ft<String>.new')); + // Does not work @ analyzer 2.2 + //expect(aTearOffDefaultConstructorArgsTypedef.constantValue, + // equals('Ft<String>.new')); }); }, skip: !_constructorTearoffsAllowed.allows(utils.platformVersion)); }); diff --git a/testing/test_package_experiments/lib/constructor_tearoffs.dart b/testing/test_package_experiments/lib/constructor_tearoffs.dart index e27c41d839..eb6d4b50bf 100644 --- a/testing/test_package_experiments/lib/constructor_tearoffs.dart +++ b/testing/test_package_experiments/lib/constructor_tearoffs.dart @@ -76,4 +76,6 @@ const aTearOffNonDefaultConstructorInt = F.alternative; const aTearOffDefaultConstructorArgs = F.new; const aTearOffDefaultConstructorTypedef = Fstring.new; -const aTearOffDefaultConstructorArgsTypedef = Ft.new; \ No newline at end of file + +// TODO(jcollins-g): does not work @ analyzer 2.2 +//const aTearOffDefaultConstructorArgsTypedef = Ft.new; \ No newline at end of file