From 5430e686807911940bf2412e65def9567f69c7d3 Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Thu, 28 Nov 2024 09:10:30 +0000 Subject: [PATCH] Remove unnecessary leftover `@dart=2.19` from tests. Change-Id: I6d5e15ff2d432202618fbc490969a65a9181816d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396281 Reviewed-by: Nicholas Shahan Commit-Queue: Lasse Nielsen --- pkg/expect/lib/static_type_helper.dart | 14 +- pkg/test_runner/lib/src/test_file.dart | 3 +- tests/language/async/switch_test.dart | 78 ++- .../call/method_as_cast_legacy_test.dart | 39 ++ tests/language/call/method_as_cast_test.dart | 5 +- ..._implicit_invoke_instance_legacy_test.dart | 57 +++ .../method_implicit_invoke_instance_test.dart | 5 +- ...hod_implicit_invoke_local_legacy_test.dart | 44 ++ ...it_invoke_local_runtime_1_legacy_test.dart | 39 ++ ..._implicit_invoke_local_runtime_1_test.dart | 5 +- ...it_invoke_local_runtime_2_legacy_test.dart | 39 ++ ..._implicit_invoke_local_runtime_2_test.dart | 5 +- ...it_invoke_local_runtime_3_legacy_test.dart | 39 ++ ..._implicit_invoke_local_runtime_3_test.dart | 5 +- ...it_invoke_local_runtime_4_legacy_test.dart | 39 ++ ..._implicit_invoke_local_runtime_4_test.dart | 5 +- ...icit_invoke_local_runtime_legacy_test.dart | 39 ++ ...od_implicit_invoke_local_runtime_test.dart | 5 +- .../method_implicit_invoke_local_test.dart | 17 +- .../method_implicit_invoke_static_test.dart | 5 +- ...method_implicit_invoke_top_level_test.dart | 5 +- tests/language/call/method_is_check_test.dart | 5 +- .../map_hashcode_override2_legacy_test.dart | 56 +++ .../const/map_hashcode_override2_test.dart | 4 +- .../map_hashcode_override_legacy_test.dart | 43 ++ .../const/map_hashcode_override_test.dart | 5 +- .../set_hashcode_override2_legacy_test.dart | 47 ++ .../const/set_hashcode_override2_test.dart | 3 +- tests/language/const/switch2_legacy_test.dart | 26 + tests/language/const/switch2_test.dart | 1 + ...> inheritance_constraints_error_test.dart} | 5 - ...ritance_constraints_legacy_error_test.dart | 45 ++ .../inheritance_constraints_legacy_lib.dart | 10 + .../deferred/inheritance_constraints_lib.dart | 9 +- .../inheritance_constraints_runtime_test.dart | 43 -- .../enhanced_enums_subtype_error_test.dart | 11 +- ...anced_enums_subtype_legacy_error_test.dart | 46 ++ tests/language/mixin/illegal_object_test.dart | 4 +- .../mixin/invalid_inheritance1_test.dart | 30 +- ...nvalid_override_in_mixin_runtime_test.dart | 29 -- .../mixin/invalid_override_in_mixin_test.dart | 33 -- tests/language/mixin/is_test.dart | 8 +- tests/language/mixin/issue10216_2_test.dart | 8 +- tests/language/mixin/issue10216_test.dart | 12 +- .../mixin/method_override_runtime_test.dart | 166 ------- .../language/mixin/method_override_test.dart | 44 +- tests/language/mixin/method_test.dart | 8 +- tests/language/mixin/mixin2_test.dart | 10 +- tests/language/mixin/mixin3_test.dart | 16 +- tests/language/mixin/mixin4_test.dart | 8 +- tests/language/mixin/mixin5_test.dart | 10 +- tests/language/mixin/mixin6_test.dart | 10 +- tests/language/mixin/mixin7_test.dart | 10 +- tests/language/mixin/mixin_bound2_test.dart | 11 +- tests/language/mixin/mixin_bound_test.dart | 9 +- tests/language/mixin/mixin_test.dart | 8 +- .../mixin/mixin_type_arguments_test.dart | 14 +- .../mixin/named_constructor_test.dart | 6 +- tests/language/mixin/naming_test.dart | 10 +- tests/language/mixin/only_for_rti_test.dart | 8 +- .../mixin/override_regression_test.dart | 8 +- tests/language/mixin/prefix_lib.dart | 4 +- tests/language/mixin/prefix_test.dart | 4 - tests/language/mixin/proto_test.dart | 6 +- .../language/mixin/recursive_mixin_test.dart | 9 +- tests/language/mixin/regress_11398_test.dart | 8 +- tests/language/mixin/regress_13688_test.dart | 6 +- .../regress_flutter_55345_const_test.dart | 6 +- .../mixin/regress_flutter_55345_test.dart | 6 +- tests/language/mixin/substitution_test.dart | 6 +- tests/language/mixin/super_2_test.dart | 6 +- .../mixin/super_bound_runtime_test.dart | 33 -- tests/language/mixin/super_bound_test.dart | 8 +- .../mixin/super_constructor2_test.dart | 6 +- .../mixin/super_constructor_default_test.dart | 6 +- .../super_constructor_multiple_test.dart | 8 +- .../mixin/super_constructor_named_test.dart | 6 +- .../super_constructor_positionals_test.dart | 6 +- .../mixin/super_constructor_test.dart | 6 +- tests/language/mixin/super_use_test.dart | 12 +- .../mixin/superclass_runtime_test.dart | 129 ----- tests/language/mixin/superclass_test.dart | 8 +- .../mixin/supertype_subclass2_test.dart | 32 -- .../mixin/supertype_subclass_error_test.dart | 42 ++ .../mixin/supertype_subclass_test.dart | 32 -- tests/language/mixin/this_use_test.dart | 10 +- .../language/mixin/type_parameter1_test.dart | 8 +- .../language/mixin/type_parameter2_test.dart | 8 +- .../language/mixin/type_parameter3_test.dart | 8 +- .../language/mixin/type_parameter4_test.dart | 6 +- .../language/mixin/type_parameter5_test.dart | 10 +- .../language/mixin/type_parameter6_test.dart | 6 +- ...rameter_inference_previous_mixin_test.dart | 23 +- .../mixin/type_parameter_inference_test.dart | 45 +- .../type_parameters_errors_runtime_test.dart | 30 -- .../mixin/type_parameters_errors_test.dart | 6 +- .../type_parameters_mixin_extends_test.dart | 6 +- .../mixin/type_parameters_mixin_test.dart | 27 +- .../mixin/type_parameters_simple_test.dart | 8 +- .../type_parameters_super_extends_test.dart | 27 +- .../mixin/type_parameters_super_test.dart | 6 +- tests/language/mixin/type_variable_test.dart | 32 +- .../mixin/typedef_constructor_test.dart | 6 +- .../const_constructor_error_test.dart | 30 ++ .../const_constructor_legacy_error_test.dart | 32 ++ .../const_constructor_legacy_test.dart | 73 +++ .../const_constructor_test.dart | 24 +- ...nst_constructor_with_field_error_test.dart | 78 +++ ...structor_with_field_legacy_error_test.dart | 80 ++++ ...st_constructor_with_field_legacy_test.dart | 77 +++ .../const_constructor_with_field_test.dart | 33 +- .../optional_named_parameters_error_test.dart | 13 + ...al_named_parameters_legacy_error_test.dart | 16 + ...optional_named_parameters_legacy_test.dart | 38 ++ .../optional_named_parameters_test.dart | 9 +- ...onal_positional_parameters_error_test.dart | 12 + ...sitional_parameters_legacy_error_test.dart | 16 + ...nal_positional_parameters_legacy_test.dart | 38 ++ .../optional_positional_parameters_test.dart | 9 +- ...in_declaration_constructor_error_test.dart | 99 ++++ ...aration_constructor_legacy_error_test.dart | 66 +++ .../mixin_declaration_factory_test.dart | 47 +- ...ation_inference_valid_B00_legacy_test.dart | 44 ++ ..._declaration_inference_valid_B00_test.dart | 6 +- ...ation_inference_valid_B01_legacy_test.dart | 44 ++ ..._declaration_inference_valid_B01_test.dart | 8 +- ...ation_inference_valid_B10_legacy_test.dart | 44 ++ ..._declaration_inference_valid_B10_test.dart | 6 +- ...ation_inference_valid_B11_legacy_test.dart | 44 ++ ..._declaration_inference_valid_B11_test.dart | 8 +- ...ation_inference_valid_C00_legacy_test.dart | 44 ++ ..._declaration_inference_valid_C00_test.dart | 6 +- ...ation_inference_valid_C01_legacy_test.dart | 44 ++ ..._declaration_inference_valid_C01_test.dart | 8 +- ...ation_inference_valid_C02_legacy_test.dart | 44 ++ ..._declaration_inference_valid_C02_test.dart | 6 +- ...ation_inference_valid_C10_legacy_test.dart | 44 ++ ..._declaration_inference_valid_C10_test.dart | 6 +- ...ation_inference_valid_C11_legacy_test.dart | 44 ++ ..._declaration_inference_valid_C11_test.dart | 8 +- ...ation_inference_valid_C12_legacy_test.dart | 44 ++ ..._declaration_inference_valid_C12_test.dart | 6 +- ..._valid_mixin_applications_legacy_test.dart | 448 ++++++++++++++++++ ...ference_valid_mixin_applications_test.dart | 8 +- ...on_invalid_override_legacy_error_test.dart | 81 ++++ ...xin_declaration_invalid_override_test.dart | 29 +- .../super_bound_runtime_test.dart | 30 -- .../mixin_legacy/superclass_runtime_test.dart | 94 ---- .../usage_object_error_test.dart | 30 +- .../usage_object_legacy_error_test.dart | 56 +++ .../inherit_static_errors_legacy_test.dart | 45 ++ .../null/inherit_static_errors_test.dart | 38 +- .../mixin_exception_throw_legacy_test.dart | 29 ++ .../private/mixin_exception_throw_test.dart | 8 +- tests/language/private/other_mixin2.dart | 6 +- .../regress/regress18713_legacy_test.dart | 37 ++ tests/language/regress/regress18713_test.dart | 6 +- tests/language/regress/regress22666_test.dart | 14 - tests/language/regress/regress23914_test.dart | 17 - .../regress/regress26230_legacy_test.dart | 50 ++ tests/language/regress/regress26230_test.dart | 10 +- .../regress/regress27957_legacy_test.dart | 20 + tests/language/regress/regress27957_test.dart | 6 +- .../regress/regress29949_legacy_test.dart | 17 + tests/language/regress/regress29949_test.dart | 8 +- .../regress/regress30669_legacy_test.dart | 40 ++ tests/language/regress/regress30669_test.dart | 6 +- .../regress/regress32267_legacy_test.dart | 25 + tests/language/regress/regress32267_test.dart | 6 +- .../regress/regress32353_legacy_test.dart | 39 ++ tests/language/regress/regress32353_test.dart | 8 +- .../regress/regress32372_legacy_test.dart | 20 + tests/language/regress/regress32372_test.dart | 6 +- ...est.dart => regress34235_legacy_test.dart} | 11 +- tests/language/regress/regress34235_test.dart | 13 +- .../regress/regress34488_legacy_test.dart | 52 ++ tests/language/regress/regress34488_test.dart | 33 +- .../regress/regress34877_legacy_test.dart | 26 + tests/language/regress/regress34877_test.dart | 6 +- .../regress/regress65278_legacy_test.dart | 32 ++ tests/language/regress/regress65278_test.dart | 6 +- tests/language/super/mixin_legacy_test.dart | 25 + tests/language/super/mixin_test.dart | 6 +- .../super/no_such_method4_legacy_test.dart | 26 + .../no_such_method4_runtime_legacy_test.dart | 26 + .../super/no_such_method4_runtime_test.dart | 12 +- .../language/super/no_such_method4_test.dart | 7 +- .../super/no_such_method5_legacy_test.dart | 24 + .../no_such_method5_runtime_legacy_test.dart} | 20 +- .../super/no_such_method5_runtime_test.dart | 16 +- .../language/super/no_such_method5_test.dart | 9 +- .../covariance_legacy_test.dart | 89 ++++ .../covariance_test.dart | 6 +- .../language/switch/bad_case_legacy_test.dart | 47 ++ tests/language/switch/bad_case_test.dart | 3 +- ...xpression_with_assignment_legacy_test.dart | 35 ++ .../case_expression_with_assignment_test.dart | 3 +- .../case_fallthrough_legacy_error_test.dart | 317 +++++++++++++ .../switch/case_fallthrough_test.dart | 242 ++++++++++ tests/language/switch/case_legacy_test.dart | 69 +++ tests/language/switch/case_test.dart | 1 + tests/language/switch/case_warn_test.dart | 222 --------- .../language/switch/fallthru_legacy_test.dart | 33 ++ tests/language/switch/fallthru_test.dart | 1 + .../assignable_expression_legacy_test.dart | 113 +++++ .../unsorted/assignable_expression_test.dart | 8 +- tests/language/unsorted/deny_listed_test.dart | 84 ---- .../vm/regress_32971_legacy_test.dart | 38 ++ tests/language/vm/regress_32971_test.dart | 6 +- ...gress_33040_instantiation_legacy_test.dart | 38 ++ .../vm/regress_33040_instantiation_test.dart | 6 +- .../vm/regression_38231_legacy_test.dart | 128 +++++ tests/language/vm/regression_38231_test.dart | 6 +- .../generalized_void_syntax_legacy_test.dart | 148 ++++++ .../void/generalized_void_syntax_test.dart | 6 +- 215 files changed, 4650 insertions(+), 1882 deletions(-) create mode 100644 tests/language/call/method_as_cast_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_instance_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_local_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_local_runtime_1_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_local_runtime_2_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_local_runtime_3_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_local_runtime_4_legacy_test.dart create mode 100644 tests/language/call/method_implicit_invoke_local_runtime_legacy_test.dart create mode 100644 tests/language/const/map_hashcode_override2_legacy_test.dart create mode 100644 tests/language/const/map_hashcode_override_legacy_test.dart create mode 100644 tests/language/const/set_hashcode_override2_legacy_test.dart create mode 100644 tests/language/const/switch2_legacy_test.dart rename tests/language/deferred/{inheritance_constraints_test.dart => inheritance_constraints_error_test.dart} (85%) create mode 100644 tests/language/deferred/inheritance_constraints_legacy_error_test.dart create mode 100644 tests/language/deferred/inheritance_constraints_legacy_lib.dart delete mode 100644 tests/language/deferred/inheritance_constraints_runtime_test.dart create mode 100644 tests/language/enum/enhanced_enums_subtype_legacy_error_test.dart delete mode 100644 tests/language/mixin/invalid_override_in_mixin_runtime_test.dart delete mode 100644 tests/language/mixin/invalid_override_in_mixin_test.dart delete mode 100644 tests/language/mixin/method_override_runtime_test.dart delete mode 100644 tests/language/mixin/super_bound_runtime_test.dart delete mode 100644 tests/language/mixin/superclass_runtime_test.dart delete mode 100644 tests/language/mixin/supertype_subclass2_test.dart create mode 100644 tests/language/mixin/supertype_subclass_error_test.dart delete mode 100644 tests/language/mixin/supertype_subclass_test.dart delete mode 100644 tests/language/mixin/type_parameters_errors_runtime_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/const_constructor_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/const_constructor_legacy_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/const_constructor_legacy_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/const_constructor_with_field_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/optional_named_parameters_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/optional_positional_parameters_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_error_test.dart create mode 100644 tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_constructor_error_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_constructor_legacy_error_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_legacy_test.dart create mode 100644 tests/language/mixin_declaration/mixin_declaration_invalid_override_legacy_error_test.dart delete mode 100644 tests/language/mixin_legacy/super_bound_runtime_test.dart delete mode 100644 tests/language/mixin_legacy/superclass_runtime_test.dart create mode 100644 tests/language/nonfunction_type_aliases/usage_object_legacy_error_test.dart create mode 100644 tests/language/null/inherit_static_errors_legacy_test.dart create mode 100644 tests/language/private/mixin_exception_throw_legacy_test.dart create mode 100644 tests/language/regress/regress18713_legacy_test.dart delete mode 100644 tests/language/regress/regress22666_test.dart delete mode 100644 tests/language/regress/regress23914_test.dart create mode 100644 tests/language/regress/regress26230_legacy_test.dart create mode 100644 tests/language/regress/regress27957_legacy_test.dart create mode 100644 tests/language/regress/regress29949_legacy_test.dart create mode 100644 tests/language/regress/regress30669_legacy_test.dart create mode 100644 tests/language/regress/regress32267_legacy_test.dart create mode 100644 tests/language/regress/regress32353_legacy_test.dart create mode 100644 tests/language/regress/regress32372_legacy_test.dart rename tests/language/regress/{regress34235_runtime_test.dart => regress34235_legacy_test.dart} (67%) create mode 100644 tests/language/regress/regress34488_legacy_test.dart create mode 100644 tests/language/regress/regress34877_legacy_test.dart create mode 100644 tests/language/regress/regress65278_legacy_test.dart create mode 100644 tests/language/super/mixin_legacy_test.dart create mode 100644 tests/language/super/no_such_method4_legacy_test.dart create mode 100644 tests/language/super/no_such_method4_runtime_legacy_test.dart create mode 100644 tests/language/super/no_such_method5_legacy_test.dart rename tests/language/{mixin_legacy/type_parameters_errors_runtime_test.dart => super/no_such_method5_runtime_legacy_test.dart} (56%) create mode 100644 tests/language/superinterface_variance/covariance_legacy_test.dart create mode 100644 tests/language/switch/bad_case_legacy_test.dart create mode 100644 tests/language/switch/case_expression_with_assignment_legacy_test.dart create mode 100644 tests/language/switch/case_fallthrough_legacy_error_test.dart create mode 100644 tests/language/switch/case_fallthrough_test.dart create mode 100644 tests/language/switch/case_legacy_test.dart delete mode 100644 tests/language/switch/case_warn_test.dart create mode 100644 tests/language/switch/fallthru_legacy_test.dart create mode 100644 tests/language/unsorted/assignable_expression_legacy_test.dart delete mode 100644 tests/language/unsorted/deny_listed_test.dart create mode 100644 tests/language/vm/regress_32971_legacy_test.dart create mode 100644 tests/language/vm/regress_33040_instantiation_legacy_test.dart create mode 100644 tests/language/vm/regression_38231_legacy_test.dart create mode 100644 tests/language/void/generalized_void_syntax_legacy_test.dart diff --git a/pkg/expect/lib/static_type_helper.dart b/pkg/expect/lib/static_type_helper.dart index cb81a52c563..463052c9ffd 100644 --- a/pkg/expect/lib/static_type_helper.dart +++ b/pkg/expect/lib/static_type_helper.dart @@ -17,7 +17,7 @@ Object? context(T x) => x; T contextType(Object? result) => result as T; extension StaticType on T { - /// Check the static type. + /// Check the static type against another type wrt. sub- and supertype. /// /// Use as follows (assuming `e` has static type `num`): /// ```dart @@ -45,6 +45,18 @@ extension StaticType on T { callback(); return this; } + + /// The static type as a `Type` object. + /// + /// Can be used for doing "same type" equality checks, like + /// ```dart + /// Expect(typeOf(), value.functionName.staticType); + /// ``` + /// The [Type.operator==] distinguishes some types that are equivalent + /// wrt. super- and sub-typing, like `dynamic` and `Object?`. + /// It also performs normalization, so `typeOf> == Object`, + /// even if they differ as static types. + Type get staticType => T; } /// Invokes [callback] with the static type of [value]. diff --git a/pkg/test_runner/lib/src/test_file.dart b/pkg/test_runner/lib/src/test_file.dart index f9a90e148f8..adcc01f5468 100644 --- a/pkg/test_runner/lib/src/test_file.dart +++ b/pkg/test_runner/lib/src/test_file.dart @@ -64,6 +64,8 @@ abstract class _TestFileBase { /// The parsed error expectation markers in this test, if it is a static /// error test. + /// + /// If empty, the test is not a static error test. final List expectedErrors; /// The name of the multitest section this file corresponds to if it was @@ -358,7 +360,6 @@ class TestFile extends _TestFileBase { result .addAll(_parseExpectations(uriString, alreadyParsed: alreadyParsed)); } - return result; } diff --git a/tests/language/async/switch_test.dart b/tests/language/async/switch_test.dart index f6a42c39a1c..7db611bf44d 100644 --- a/tests/language/async/switch_test.dart +++ b/tests/language/async/switch_test.dart @@ -19,7 +19,6 @@ foo1(int a) async { case 2: k += a; return k + 2; - default: k = 2; //# withDefault: ok } return k; } @@ -34,7 +33,6 @@ foo2(Future a) async { case 2: k += await a; return k + 2; - default: k = 2; //# withDefault: ok } return k; } @@ -48,7 +46,6 @@ foo3(int a) async { case 2: k += a; return k + 2; - default: k = 2; //# withDefault: ok } return k; } @@ -62,7 +59,64 @@ foo4(value) async { case 2: k += 2; return 2 + k; - default: k = 2; //# withDefault: ok + } + return k; +} + +foo1WithDefault(int a) async { + int k = 0; + switch (a) { + case 1: + await 3; + k += 1; + break; + case 2: + k += a; + return k + 2; + default: k = 2; + } + return k; +} + +foo2WithDefault(Future a) async { + int k = 0; + switch (await a) { + case 1: + await 3; + k += 1; + break; + case 2: + k += await a; + return k + 2; + default: k = 2; + } + return k; +} + +foo3WithDefault(int a) async { + int k = 0; + switch (a) { + case 1: + k += 1; + break; + case 2: + k += a; + return k + 2; + default: k = 2; + } + return k; +} + +foo4WithDefault(value) async { + int k = 0; + switch (await value) { + case 1: + k += 1; + break; + case 2: + k += 2; + return 2 + k; + default: k = 2; } return k; } @@ -72,20 +126,20 @@ Future futureOf(int a) async => await a; Future test() async { Expect.equals(1, await foo1(1)); Expect.equals(4, await foo1(2)); - Expect.equals(2, await foo1(3)); //# withDefault: ok - Expect.equals(0, await foo1(3)); //# none: ok + Expect.equals(2, await foo1WithDefault(3)); + Expect.equals(0, await foo1(3)); Expect.equals(1, await foo2(futureOf(1))); Expect.equals(4, await foo2(futureOf(2))); - Expect.equals(2, await foo2(futureOf(3))); //# withDefault: ok - Expect.equals(0, await foo2(futureOf(3))); //# none: ok + Expect.equals(2, await foo2WithDefault(futureOf(3))); + Expect.equals(0, await foo2(futureOf(3))); Expect.equals(1, await foo3(1)); Expect.equals(4, await foo3(2)); - Expect.equals(2, await foo3(3)); //# withDefault: ok - Expect.equals(0, await foo3(3)); //# none: ok + Expect.equals(2, await foo3WithDefault(3)); + Expect.equals(0, await foo3(3)); Expect.equals(1, await foo4(futureOf(1))); Expect.equals(4, await foo4(futureOf(2))); - Expect.equals(2, await foo4(futureOf(3))); //# withDefault: ok - Expect.equals(0, await foo4(futureOf(3))); //# none: ok + Expect.equals(2, await foo4WithDefault(futureOf(3))); + Expect.equals(0, await foo4(futureOf(3))); } void main() { diff --git a/tests/language/call/method_as_cast_legacy_test.dart b/tests/language/call/method_as_cast_legacy_test.dart new file mode 100644 index 00000000000..e55e500d5f3 --- /dev/null +++ b/tests/language/call/method_as_cast_legacy_test.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class B {} + +class C { + B call(B b) => b; +} + +class D implements Function { + B call(B b) => b; +} + +typedef B BToB(B x); + +typedef Object NullToObject(Null x); + +main() { + // The presence of a `.call` method does not cause class `C` to become a + // subtype of any function type. + C c = new C(); + Expect.throwsTypeError(() => c as BToB); //# 01: ok + Expect.throwsTypeError(() => c as NullToObject); //# 02: ok + Expect.throwsTypeError(() => c as Function); //# 03: ok + + // The same goes for class `D`: `implements Function` is ignored in Dart 2. + D d = new D(); + Expect.throwsTypeError(() => d as BToB); //# 04: ok + Expect.throwsTypeError(() => d as NullToObject); //# 05: ok + Expect.throwsTypeError(() => d as Function); //# 06: ok +} diff --git a/tests/language/call/method_as_cast_test.dart b/tests/language/call/method_as_cast_test.dart index e55e500d5f3..e873ff26cc9 100644 --- a/tests/language/call/method_as_cast_test.dart +++ b/tests/language/call/method_as_cast_test.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -15,7 +12,7 @@ class C { B call(B b) => b; } -class D implements Function { +class D { B call(B b) => b; } diff --git a/tests/language/call/method_implicit_invoke_instance_legacy_test.dart b/tests/language/call/method_implicit_invoke_instance_legacy_test.dart new file mode 100644 index 00000000000..1ee5c138d4a --- /dev/null +++ b/tests/language/call/method_implicit_invoke_instance_legacy_test.dart @@ -0,0 +1,57 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +class D { + C1 c1 = new C1(); + dynamic d1 = new C1(); + C2 c2 = new C2(); + dynamic d2 = new C2(); + + void test() { + // Implicitly invokes c1.call(1) + Expect.equals(c1(1), 2); //# 01: ok + // Implicitly invokes d1.call(1) + Expect.equals(d1(1), 2); //# 02: ok + // Implicitly invokes c2.call(1) + Expect.equals(c2(1), 2); //# 03: ok + // Implicitly invokes d2.call(1) + Expect.equals(d2(1), 2); //# 04: ok + } +} + +main() { + new D().test(); + // Implicitly invokes D.c1.call(1) + Expect.equals(new D().c1(1), 2); //# 05: ok + // Implicitly invokes D.d1.call(1) + Expect.equals(new D().d1(1), 2); //# 06: ok + // Implicitly invokes D.c2.call(1) + Expect.equals(new D().c2(1), 2); //# 07: ok + // Implicitly invokes D.d2.call(1) + Expect.equals(new D().d2(1), 2); //# 08: ok + D d = new D(); + // Implicitly invokes d.c1.call(1) + Expect.equals(d.c1(1), 2); //# 09: ok + // Implicitly invokes d.d1.call(1) + Expect.equals(d.d1(1), 2); //# 10: ok + // Implicitly invokes d.c2.call(1) + Expect.equals(d.c2(1), 2); //# 11: ok + // Implicitly invokes d.d2.call(1) + Expect.equals(d.d2(1), 2); //# 12: ok +} diff --git a/tests/language/call/method_implicit_invoke_instance_test.dart b/tests/language/call/method_implicit_invoke_instance_test.dart index 1ee5c138d4a..bf6020afb70 100644 --- a/tests/language/call/method_implicit_invoke_instance_test.dart +++ b/tests/language/call/method_implicit_invoke_instance_test.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -13,7 +10,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_local_legacy_test.dart b/tests/language/call/method_implicit_invoke_local_legacy_test.dart new file mode 100644 index 00000000000..377fb1d074d --- /dev/null +++ b/tests/language/call/method_implicit_invoke_local_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +main() { + C1 c1 = new C1(); + // Implicitly invokes c1.call(1) + Expect.equals(c1(1), 2); + dynamic d1 = c1; + // Implicitly invokes d1.call(1) + Expect.equals(d1(1), 2); + C2 c2 = new C2(); + // Implicitly invokes c2.call(1) + Expect.equals(c2(1), 2); + dynamic d2 = c2; + // Implicitly invokes d2.call(1) + Expect.equals(d2(1), 2); + // Cannot invoke with the wrong signature. + c2(); + // ^ + // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS + //^^ + // [cfe] Too few positional arguments: 1 required, 0 given. + c2(3, 4); + // ^ + // [analyzer] COMPILE_TIME_ERROR.EXTRA_POSITIONAL_ARGUMENTS + //^^^^^^ + // [cfe] Too many positional arguments: 1 allowed, but 2 found. +} diff --git a/tests/language/call/method_implicit_invoke_local_runtime_1_legacy_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_1_legacy_test.dart new file mode 100644 index 00000000000..e3fb601e35b --- /dev/null +++ b/tests/language/call/method_implicit_invoke_local_runtime_1_legacy_test.dart @@ -0,0 +1,39 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +main() { + C1 c1 = new C1(); + // Implicitly invokes c1.call(1) + Expect.equals(c1(1), 2); + dynamic d1 = c1; + // Implicitly invokes d1.call(1) + + C2 c2 = new C2(); + // Implicitly invokes c2.call(1) + + dynamic d2 = c2; + // Implicitly invokes d2.call(1) + + // Cannot invoke with the wrong signature. + + +} diff --git a/tests/language/call/method_implicit_invoke_local_runtime_1_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_1_test.dart index e3fb601e35b..c7e29a861f6 100644 --- a/tests/language/call/method_implicit_invoke_local_runtime_1_test.dart +++ b/tests/language/call/method_implicit_invoke_local_runtime_1_test.dart @@ -5,9 +5,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -16,7 +13,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_local_runtime_2_legacy_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_2_legacy_test.dart new file mode 100644 index 00000000000..b54d62b64c9 --- /dev/null +++ b/tests/language/call/method_implicit_invoke_local_runtime_2_legacy_test.dart @@ -0,0 +1,39 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +main() { + C1 c1 = new C1(); + // Implicitly invokes c1.call(1) + + dynamic d1 = c1; + // Implicitly invokes d1.call(1) + Expect.equals(d1(1), 2); + C2 c2 = new C2(); + // Implicitly invokes c2.call(1) + + dynamic d2 = c2; + // Implicitly invokes d2.call(1) + + // Cannot invoke with the wrong signature. + + +} diff --git a/tests/language/call/method_implicit_invoke_local_runtime_2_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_2_test.dart index b54d62b64c9..d8ceef60b47 100644 --- a/tests/language/call/method_implicit_invoke_local_runtime_2_test.dart +++ b/tests/language/call/method_implicit_invoke_local_runtime_2_test.dart @@ -5,9 +5,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -16,7 +13,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_local_runtime_3_legacy_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_3_legacy_test.dart new file mode 100644 index 00000000000..3ddf191ac89 --- /dev/null +++ b/tests/language/call/method_implicit_invoke_local_runtime_3_legacy_test.dart @@ -0,0 +1,39 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +main() { + C1 c1 = new C1(); + // Implicitly invokes c1.call(1) + + dynamic d1 = c1; + // Implicitly invokes d1.call(1) + + C2 c2 = new C2(); + // Implicitly invokes c2.call(1) + Expect.equals(c2(1), 2); + dynamic d2 = c2; + // Implicitly invokes d2.call(1) + + // Cannot invoke with the wrong signature. + + +} diff --git a/tests/language/call/method_implicit_invoke_local_runtime_3_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_3_test.dart index 3ddf191ac89..b9f966fa5c3 100644 --- a/tests/language/call/method_implicit_invoke_local_runtime_3_test.dart +++ b/tests/language/call/method_implicit_invoke_local_runtime_3_test.dart @@ -5,9 +5,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -16,7 +13,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_local_runtime_4_legacy_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_4_legacy_test.dart new file mode 100644 index 00000000000..25f74b5157c --- /dev/null +++ b/tests/language/call/method_implicit_invoke_local_runtime_4_legacy_test.dart @@ -0,0 +1,39 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +main() { + C1 c1 = new C1(); + // Implicitly invokes c1.call(1) + + dynamic d1 = c1; + // Implicitly invokes d1.call(1) + + C2 c2 = new C2(); + // Implicitly invokes c2.call(1) + + dynamic d2 = c2; + // Implicitly invokes d2.call(1) + Expect.equals(d2(1), 2); + // Cannot invoke with the wrong signature. + + +} diff --git a/tests/language/call/method_implicit_invoke_local_runtime_4_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_4_test.dart index 25f74b5157c..e6febe2320d 100644 --- a/tests/language/call/method_implicit_invoke_local_runtime_4_test.dart +++ b/tests/language/call/method_implicit_invoke_local_runtime_4_test.dart @@ -5,9 +5,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -16,7 +13,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_local_runtime_legacy_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_legacy_test.dart new file mode 100644 index 00000000000..a36bff3cef9 --- /dev/null +++ b/tests/language/call/method_implicit_invoke_local_runtime_legacy_test.dart @@ -0,0 +1,39 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Implements Function which is not allowed in Dart 3. +// @dart=2.19 + +// Dart test program to test arithmetic operations. + +import "package:expect/expect.dart"; + +class C1 { + int call(int i) => 2 * i; +} + +class C2 implements Function { + int call(int i) => 2 * i; +} + +main() { + C1 c1 = new C1(); + // Implicitly invokes c1.call(1) + + dynamic d1 = c1; + // Implicitly invokes d1.call(1) + + C2 c2 = new C2(); + // Implicitly invokes c2.call(1) + + dynamic d2 = c2; + // Implicitly invokes d2.call(1) + + // Cannot invoke with the wrong signature. + + +} diff --git a/tests/language/call/method_implicit_invoke_local_runtime_test.dart b/tests/language/call/method_implicit_invoke_local_runtime_test.dart index a36bff3cef9..aff570c4af2 100644 --- a/tests/language/call/method_implicit_invoke_local_runtime_test.dart +++ b/tests/language/call/method_implicit_invoke_local_runtime_test.dart @@ -5,9 +5,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -16,7 +13,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_local_test.dart b/tests/language/call/method_implicit_invoke_local_test.dart index 377fb1d074d..40444198c1f 100644 --- a/tests/language/call/method_implicit_invoke_local_test.dart +++ b/tests/language/call/method_implicit_invoke_local_test.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -13,10 +10,6 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { - int call(int i) => 2 * i; -} - main() { C1 c1 = new C1(); // Implicitly invokes c1.call(1) @@ -24,19 +17,13 @@ main() { dynamic d1 = c1; // Implicitly invokes d1.call(1) Expect.equals(d1(1), 2); - C2 c2 = new C2(); - // Implicitly invokes c2.call(1) - Expect.equals(c2(1), 2); - dynamic d2 = c2; - // Implicitly invokes d2.call(1) - Expect.equals(d2(1), 2); // Cannot invoke with the wrong signature. - c2(); + c1(); // ^ // [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS //^^ // [cfe] Too few positional arguments: 1 required, 0 given. - c2(3, 4); + c1(3, 4); // ^ // [analyzer] COMPILE_TIME_ERROR.EXTRA_POSITIONAL_ARGUMENTS //^^^^^^ diff --git a/tests/language/call/method_implicit_invoke_static_test.dart b/tests/language/call/method_implicit_invoke_static_test.dart index e70876019f5..7bf0c69f7cd 100644 --- a/tests/language/call/method_implicit_invoke_static_test.dart +++ b/tests/language/call/method_implicit_invoke_static_test.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -13,7 +10,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_implicit_invoke_top_level_test.dart b/tests/language/call/method_implicit_invoke_top_level_test.dart index 8e0c7838cf6..8dea8132196 100644 --- a/tests/language/call/method_implicit_invoke_top_level_test.dart +++ b/tests/language/call/method_implicit_invoke_top_level_test.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -13,7 +10,7 @@ class C1 { int call(int i) => 2 * i; } -class C2 implements Function { +class C2 { int call(int i) => 2 * i; } diff --git a/tests/language/call/method_is_check_test.dart b/tests/language/call/method_is_check_test.dart index ebe6a261984..e866362a4b2 100644 --- a/tests/language/call/method_is_check_test.dart +++ b/tests/language/call/method_is_check_test.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Implements Function which is not allowed in Dart 3. -// @dart=2.19 - // Dart test program to test arithmetic operations. import "package:expect/expect.dart"; @@ -15,7 +12,7 @@ class C { B call(B b) => b; } -class D implements Function { +class D { B call(B b) => b; } diff --git a/tests/language/const/map_hashcode_override2_legacy_test.dart b/tests/language/const/map_hashcode_override2_legacy_test.dart new file mode 100644 index 00000000000..d526da1a06f --- /dev/null +++ b/tests/language/const/map_hashcode_override2_legacy_test.dart @@ -0,0 +1,56 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +import 'package:expect/expect.dart'; + +/// Returns its argument. +/// +/// Prevents static optimizations and inlining. +@pragma('vm:never-inline') +@pragma('dart2js:noInline') +dynamic getValueNonOptimized(dynamic x) { + // DateTime.now() cannot be predicted statically, never equal to 42. + if (DateTime.now().millisecondsSinceEpoch == 42) { + return getValueNonOptimized(2); + } + return x; +} + +class MyClass { + final int n; + + const MyClass(this.n); + + int get hashCode => super.hashCode + 1; +} + +main() { + const constInstance = MyClass(1); + final nonConstInstance = MyClass(1); + + const constMap = {MyClass(1): 11}; + final nonConstMap = {constInstance: 11}; + final nonConstMap2 = {nonConstInstance: 11}; + + // operator== is _not_ overridden, so instances are not equal. + Expect.notEquals(constInstance, nonConstInstance); + + Expect.isTrue(constMap.containsKey(getValueNonOptimized(constInstance))); + Expect.isFalse(constMap.containsKey(getValueNonOptimized(nonConstInstance))); + Expect.isTrue(nonConstMap.containsKey(getValueNonOptimized(constInstance))); + Expect.isFalse( + nonConstMap.containsKey(getValueNonOptimized(nonConstInstance))); + Expect.isFalse(nonConstMap2.containsKey(getValueNonOptimized(constInstance))); + Expect.isTrue( + nonConstMap2.containsKey(getValueNonOptimized(nonConstInstance))); + + Expect.equals(11, constMap[getValueNonOptimized(constInstance)]); + Expect.isNull(constMap[getValueNonOptimized(nonConstInstance)]); + Expect.equals(11, nonConstMap[getValueNonOptimized(constInstance)]); + Expect.isNull(nonConstMap[getValueNonOptimized(nonConstInstance)]); + Expect.isNull(nonConstMap2[getValueNonOptimized(constInstance)]); + Expect.equals(11, nonConstMap2[getValueNonOptimized(nonConstInstance)]); +} diff --git a/tests/language/const/map_hashcode_override2_test.dart b/tests/language/const/map_hashcode_override2_test.dart index d526da1a06f..efc9ac1cc64 100644 --- a/tests/language/const/map_hashcode_override2_test.dart +++ b/tests/language/const/map_hashcode_override2_test.dart @@ -1,7 +1,9 @@ // Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// + +// Checks that a const map can have a key which overrides `hashCode`. +// Overriding `hashCode` in const map keys was made an error in Dart 3.0. // @dart=2.19 import 'package:expect/expect.dart'; diff --git a/tests/language/const/map_hashcode_override_legacy_test.dart b/tests/language/const/map_hashcode_override_legacy_test.dart new file mode 100644 index 00000000000..061f5707699 --- /dev/null +++ b/tests/language/const/map_hashcode_override_legacy_test.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +import 'package:expect/expect.dart'; + +/// Returns its argument. +/// +/// Prevents static optimizations and inlining. +@pragma('vm:never-inline') +@pragma('dart2js:noInline') +dynamic getValueNonOptimized(dynamic x) { + // DateTime.now() cannot be predicted statically, never equal to 42. + if (DateTime.now().millisecondsSinceEpoch == 42) { + return getValueNonOptimized(2); + } + return x; +} + +class Nasty { + final int n; + + const Nasty(this.n); + + int get hashCode { + throw "Evil hashCode"; + } +} + +main() { + // Test that when using an instance of a custom class as a key in a const Map, + // its hash code is computed as its identity hash, and even if the class + // overrides `hashCode`, that `hashCode` implementation is not called. + final map = const {1: 42, 'foo': 499, 2: 'bar', Nasty(1): 'baz'}; + Expect.equals(42, map[getValueNonOptimized(1.0)]); + Expect.equals( + 499, map[getValueNonOptimized(new String.fromCharCodes('foo'.runes))]); + Expect.equals('bar', map[getValueNonOptimized(2)]); + Expect.isNull(map[getValueNonOptimized(Nasty(1))]); + Expect.equals('baz', map[getValueNonOptimized(const Nasty(1))]); +} diff --git a/tests/language/const/map_hashcode_override_test.dart b/tests/language/const/map_hashcode_override_test.dart index 061f5707699..7032fa4ff26 100644 --- a/tests/language/const/map_hashcode_override_test.dart +++ b/tests/language/const/map_hashcode_override_test.dart @@ -1,7 +1,10 @@ // Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// + +// Checks what happens if a const map can has a key which overrides `hashCode` +// in a nasty way. +// Overriding `hashCode` in const map keys was made an error in Dart 3.0. // @dart=2.19 import 'package:expect/expect.dart'; diff --git a/tests/language/const/set_hashcode_override2_legacy_test.dart b/tests/language/const/set_hashcode_override2_legacy_test.dart new file mode 100644 index 00000000000..92b5c7b7ee4 --- /dev/null +++ b/tests/language/const/set_hashcode_override2_legacy_test.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +import 'package:expect/expect.dart'; + +/// Returns its argument. +/// +/// Prevents static optimizations and inlining. +@pragma('vm:never-inline') +@pragma('dart2js:noInline') +dynamic getValueNonOptimized(dynamic x) { + // DateTime.now() cannot be predicted statically, never equal to 42. + if (DateTime.now().millisecondsSinceEpoch == 42) { + return getValueNonOptimized(2); + } + return x; +} + +class MyClass { + final int n; + + const MyClass(this.n); + + int get hashCode => super.hashCode + 1; +} + +main() { + const constInstance = MyClass(1); + final nonConstInstance = MyClass(1); + + const constSet = {MyClass(1)}; + final nonConstSet = {constInstance}; + final nonConstSet2 = {nonConstInstance}; + + // operator== is _not_ overridden, so instances are not equal. + Expect.notEquals(constInstance, nonConstInstance); + + Expect.isTrue(constSet.contains(getValueNonOptimized(constInstance))); + Expect.isFalse(constSet.contains(getValueNonOptimized(nonConstInstance))); + Expect.isTrue(nonConstSet.contains(getValueNonOptimized(constInstance))); + Expect.isFalse(nonConstSet.contains(getValueNonOptimized(nonConstInstance))); + Expect.isFalse(nonConstSet2.contains(getValueNonOptimized(constInstance))); + Expect.isTrue(nonConstSet2.contains(getValueNonOptimized(nonConstInstance))); +} diff --git a/tests/language/const/set_hashcode_override2_test.dart b/tests/language/const/set_hashcode_override2_test.dart index 92b5c7b7ee4..b113614d2de 100644 --- a/tests/language/const/set_hashcode_override2_test.dart +++ b/tests/language/const/set_hashcode_override2_test.dart @@ -1,7 +1,8 @@ // Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// + +// Overriding `hashCode` in const set elements was made an error in Dart 3.0. // @dart=2.19 import 'package:expect/expect.dart'; diff --git a/tests/language/const/switch2_legacy_test.dart b/tests/language/const/switch2_legacy_test.dart new file mode 100644 index 00000000000..94e33200254 --- /dev/null +++ b/tests/language/const/switch2_legacy_test.dart @@ -0,0 +1,26 @@ +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +import 'package:expect/expect.dart'; + +void main() { + var a = [1, 2, 3][2]; + switch (a) { + case 0.0: + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IS_NOT_SWITCH_EXPRESSION_SUBTYPE + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS + // ^ + // [cfe] Type 'double' of the case expression is not a subtype of type 'int' of this switch expression. + // ^ + // [cfe] Case expression '0.0' does not have a primitive operator '=='. + print("illegal"); + break; + case 1: + print("OK"); + } +} diff --git a/tests/language/const/switch2_test.dart b/tests/language/const/switch2_test.dart index 94e33200254..4db783f5a26 100644 --- a/tests/language/const/switch2_test.dart +++ b/tests/language/const/switch2_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // +// Tests pre-pattern legacy behavior. // @dart=2.19 import 'package:expect/expect.dart'; diff --git a/tests/language/deferred/inheritance_constraints_test.dart b/tests/language/deferred/inheritance_constraints_error_test.dart similarity index 85% rename from tests/language/deferred/inheritance_constraints_test.dart rename to tests/language/deferred/inheritance_constraints_error_test.dart index decffb1cfc8..f9bf5b80858 100644 --- a/tests/language/deferred/inheritance_constraints_test.dart +++ b/tests/language/deferred/inheritance_constraints_error_test.dart @@ -2,11 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; import "inheritance_constraints_lib.dart" deferred as lib; diff --git a/tests/language/deferred/inheritance_constraints_legacy_error_test.dart b/tests/language/deferred/inheritance_constraints_legacy_error_test.dart new file mode 100644 index 00000000000..868cff64a45 --- /dev/null +++ b/tests/language/deferred/inheritance_constraints_legacy_error_test.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; +import "inheritance_constraints_legacy_lib.dart" deferred as lib; + +class Foo {} + +class Foo2 extends D {} + +class A extends lib.Foo {} +// ^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DEFERRED_CLASS +// [cfe] Classes can't extend deferred classes. + +class B implements lib.Foo {} +// ^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DEFERRED_CLASS +// [cfe] Classes and mixins can't implement deferred classes. + +class C1 {} + +class C = C1 with lib.Foo; +// ^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DEFERRED_CLASS +// [cfe] Classes can't mix in deferred mixins. + +class D { + D(); + factory D.factory() = lib.Foo2; +// ^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.REDIRECT_TO_INVALID_RETURN_TYPE +// [cfe] The constructor function type 'Foo2 Function()' isn't a subtype of 'D Function()'. +} + +void main() { + new A(); + new B(); + new C(); + new D.factory(); +} diff --git a/tests/language/deferred/inheritance_constraints_legacy_lib.dart b/tests/language/deferred/inheritance_constraints_legacy_lib.dart new file mode 100644 index 00000000000..6e3f723c69a --- /dev/null +++ b/tests/language/deferred/inheritance_constraints_legacy_lib.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test using classes as mixins. +// @dart=2.19 + +class Foo {} + +class Foo2 {} diff --git a/tests/language/deferred/inheritance_constraints_lib.dart b/tests/language/deferred/inheritance_constraints_lib.dart index 23f4ebcfcf1..da114670650 100644 --- a/tests/language/deferred/inheritance_constraints_lib.dart +++ b/tests/language/deferred/inheritance_constraints_lib.dart @@ -2,11 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 +mixin class Foo {} -class Foo {} - -class Foo2 {} +mixin class Foo2 {} diff --git a/tests/language/deferred/inheritance_constraints_runtime_test.dart b/tests/language/deferred/inheritance_constraints_runtime_test.dart deleted file mode 100644 index cba85ac9dad..00000000000 --- a/tests/language/deferred/inheritance_constraints_runtime_test.dart +++ /dev/null @@ -1,43 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "package:expect/expect.dart"; -import "inheritance_constraints_lib.dart" deferred as lib; - -mixin class Foo {} - -class Foo2 extends D {} - -class A extends - - Foo {} - -class B - implements - - Foo {} - -class C1 {} - -class C = C1 - with - - Foo; - -class D { - D(); - factory D.factory() = - - Foo2; -} - -void main() { - new A(); - new B(); - new C(); - new D.factory(); -} diff --git a/tests/language/enum/enhanced_enums_subtype_error_test.dart b/tests/language/enum/enhanced_enums_subtype_error_test.dart index 14b9c789c72..0c351deab55 100644 --- a/tests/language/enum/enhanced_enums_subtype_error_test.dart +++ b/tests/language/enum/enhanced_enums_subtype_error_test.dart @@ -2,11 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 - // Test errors required by new enhanced enum syntax. // Classes which implement `Enum`, but are not `enum` declarations, @@ -40,6 +35,8 @@ abstract class AbstractImplementsWithValues implements Enum { } abstract class AbstractExtendsWithValues extends Enum { +// ^ +// [cfe] The class 'Enum' can't be extended outside of its library because it's an interface class. int get values => 42; // ^^^^^^ // [analyzer] COMPILE_TIME_ERROR.ILLEGAL_ENUM_VALUES @@ -54,6 +51,8 @@ abstract class AbstractImplementsWithIndex implements Enum { } abstract class AbstractExtendsWithIndex extends Enum { +// ^ +// [cfe] The class 'Enum' can't be extended outside of its library because it's an interface class. int get index => 42; // ^^^^^ // [analyzer] COMPILE_TIME_ERROR.ILLEGAL_CONCRETE_ENUM_MEMBER @@ -163,6 +162,7 @@ abstract class MixesInEnum with MyEnum { // ^^^^^^ // [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS // [cfe] The class 'MyEnum' can't be used as a mixin because it extends a class other than 'Object'. + // [cfe] The class 'MyEnum' can't be used as a mixin because it isn't a mixin class nor a mixin. } mixin MixinImplementsEnum implements MyEnum { @@ -194,6 +194,7 @@ enum EnumMixesInEnum with MyEnum { // ^^^^^^ // [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS // [cfe] The class 'MyEnum' can't be used as a mixin because it extends a class other than 'Object'. + // [cfe] The class 'MyEnum' can't be used as a mixin because it isn't a mixin class nor a mixin. e1; } diff --git a/tests/language/enum/enhanced_enums_subtype_legacy_error_test.dart b/tests/language/enum/enhanced_enums_subtype_legacy_error_test.dart new file mode 100644 index 00000000000..939914ee1bb --- /dev/null +++ b/tests/language/enum/enhanced_enums_subtype_legacy_error_test.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Tests using a class as mixin. +// @dart=2.19 + +// Test errors required by new enhanced enum syntax, when used as a mixin. +// Not usable a mixin, even in language version that allows mixing in a class. + +class MixesInEnum with Enum { + // ^ + // [cfe] Non-abstract class 'MixesInEnum' has 'Enum' as a superinterface. + // [cfe] The non-abstract class 'MixesInEnum' is missing implementations for these members: + // ^^^^ + // [analyzer] COMPILE_TIME_ERROR.CONCRETE_CLASS_HAS_ENUM_SUPERINTERFACE +} + +// Currently no error, it's a simple class with no constructors that extends +// `Object`. (No reason to allow, will not be allowed in Dart 3.0.) +abstract class AbstractMixesInEnum with Enum {} + +abstract class MixesInMyEnum with MyEnum { + // ^ + // [cfe] 'MyEnum' is an enum and can't be extended or implemented. + // [cfe] Can't use 'MyEnum' as a mixin because it has constructors. + // ^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS + // [cfe] The class 'MyEnum' can't be used as a mixin because it extends a class other than 'Object'. +} + +enum EnumMixesInEnum with MyEnum { + // ^ + // [cfe] 'MyEnum' is an enum and can't be extended or implemented. + // [cfe] Can't use 'MyEnum' as a mixin because it has constructors. + // ^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS + // [cfe] The class 'MyEnum' can't be used as a mixin because it extends a class other than 'Object'. + e1; +} + +void main() {} + +enum MyEnum { + e1; +} diff --git a/tests/language/mixin/illegal_object_test.dart b/tests/language/mixin/illegal_object_test.dart index 1156580bca3..a1fbb614a5c 100644 --- a/tests/language/mixin/illegal_object_test.dart +++ b/tests/language/mixin/illegal_object_test.dart @@ -2,9 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. +// Tests pre-3.0 behavior. // @dart=2.19 // Object has a non-trivial constructor and hence cannot be used as mixin. diff --git a/tests/language/mixin/invalid_inheritance1_test.dart b/tests/language/mixin/invalid_inheritance1_test.dart index 725d4862fcd..3939bc686ed 100644 --- a/tests/language/mixin/invalid_inheritance1_test.dart +++ b/tests/language/mixin/invalid_inheritance1_test.dart @@ -2,13 +2,27 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// Formatting can break multitests, so don't format them. -// dart format off +class C1 extends Object with Malformed {} +// ^ +// [cfe] The type 'Malformed' can't be mixed in. +// ^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS +// [cfe] Type 'Malformed' not found. -class C extends Object - with Malformed // //# 01: compile-time error - with T // //# 02: compile-time error - with T // //# 03: compile-time error -{} +class C2 extends Object with T {} +// ^ +// [cfe] The type 'T' can't be mixed in. +// ^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS +// [cfe] The type variable 'T' can't be used as supertype. -main() => new C(); +class C3 extends Object with T {} +// ^ +// [cfe] The type 'T' can't be mixed in. +// ^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_OF_NON_CLASS +// ^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_TYPE_ARGUMENTS +// [cfe] Can't use type arguments with type variable 'T'. + +void main() {} \ No newline at end of file diff --git a/tests/language/mixin/invalid_override_in_mixin_runtime_test.dart b/tests/language/mixin/invalid_override_in_mixin_runtime_test.dart deleted file mode 100644 index 0f1c994fe9e..00000000000 --- a/tests/language/mixin/invalid_override_in_mixin_runtime_test.dart +++ /dev/null @@ -1,29 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -import 'package:expect/expect.dart'; - -class A { - -} - -class C extends Object with A { - test() { - print("Hello from test"); - } -} - -main() { - C c = new C(); - c.test(); - dynamic cc = c; - Expect.throwsNoSuchMethodError(() => cc.doesntExist()); -} diff --git a/tests/language/mixin/invalid_override_in_mixin_test.dart b/tests/language/mixin/invalid_override_in_mixin_test.dart deleted file mode 100644 index 75103d92133..00000000000 --- a/tests/language/mixin/invalid_override_in_mixin_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -import 'package:expect/expect.dart'; - -class A { - noSuchMethod() {} -//^^^^^^^^^^^^ -// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE -// [cfe] The method 'A.noSuchMethod' has fewer positional arguments than those of overridden method 'Object.noSuchMethod'. -} - -class C extends Object with A { -// ^ -// [cfe] Applying the mixin 'A' to 'Object' introduces an erroneous override of 'noSuchMethod'. -// ^ -// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE - test() { - print("Hello from test"); - } -} - -main() { - C c = new C(); - c.test(); - dynamic cc = c; - Expect.throwsNoSuchMethodError(() => cc.doesntExist()); -} diff --git a/tests/language/mixin/is_test.dart b/tests/language/mixin/is_test.dart index f62b7165f96..485fd1dcf9b 100644 --- a/tests/language/mixin/is_test.dart +++ b/tests/language/mixin/is_test.dart @@ -2,17 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class S {} -class M1 {} +mixin M1 {} -class M2 {} +mixin M2 {} class C = S with M1; class D = S with M1, M2; diff --git a/tests/language/mixin/issue10216_2_test.dart b/tests/language/mixin/issue10216_2_test.dart index afb04af44db..12f0a883d7d 100644 --- a/tests/language/mixin/issue10216_2_test.dart +++ b/tests/language/mixin/issue10216_2_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class M1 = Object with M0; +mixin class M1 = Object with M0; class M2 = Object with M1; -class M0 { +mixin M0 { foo() => 42; } diff --git a/tests/language/mixin/issue10216_test.dart b/tests/language/mixin/issue10216_test.dart index 75950d25459..206c0412b09 100644 --- a/tests/language/mixin/issue10216_test.dart +++ b/tests/language/mixin/issue10216_test.dart @@ -1,11 +1,7 @@ -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class A { @@ -14,14 +10,14 @@ class A { class B extends A with M1, M2, M3 {} -class M1 {} +mixin M1 {} -class M2 { +mixin M2 { plain(x) => 'P $x'; bar(x, [y]) => '$y,$x'; } -class M3 {} +mixin M3 {} makeB() { return [new A(), new B()].last as B; diff --git a/tests/language/mixin/method_override_runtime_test.dart b/tests/language/mixin/method_override_runtime_test.dart deleted file mode 100644 index 6311d219d78..00000000000 --- a/tests/language/mixin/method_override_runtime_test.dart +++ /dev/null @@ -1,166 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -// Signature conformance test. -abstract class CII { - int id(int x); -} - -class CSI { - String id(int x) => "$x"; -} - -class CIS { - int id(String x) => 0; -} - -class CTT { - T id(T x) => x; -} - -// Wrong return type. - - -// Wrong argument type. - - - -// Similar as the above but using an instantiated class instead. -abstract class C5 = CII with CTT; -abstract class C6 extends CII with CTT {} - - - -// Named parameters -abstract class NIIx { - int? id({int? x}) => x; -} - -class NIIxy { - int? id({int? x, int? y}) => y; -} - -class NIIy { - int? id({int? y}) => y; -} - -class NII { - int? id(int? x) => x; -} - -// It's OK to introduce more named parameters. -abstract class N1 = NIIx with NIIxy; -abstract class N2 extends NIIx with NIIxy {} -// It's NOT OK to rename named parameters. - - -// It's NOT OK to drop named parameters. - - - -class NBABxy { - B? id ({A? x, B? y}) => y; -} - -class NTTy { - T? id({T? y}) => y; -} - -class NTTx { - T? id(T? x) => x; -} - -// Same as above but with generic classes. -abstract class N7 = NIIx with NBABxy; -abstract class N8 extends NIIx with NBABxy {} - - - - - - - -// Optional positional parameters -abstract class OII { - int? id([int? x]) => x; -} - -class OIII { - int? id([int? x, int? y]) => y; -} - -class OIIy { - int? id([int? y]) => y; -} - -class PII { - int? id(int? x) => x; -} - -// It's OK to introduce more optional parameters. -abstract class O1 = OII with OIII; -abstract class O2 extends OII with OIII {} -// It's OK to rename optional parameters. -abstract class O3 = OII with OIIy; -abstract class O4 extends OII with OIIy {} -// It's NOT OK to drop optional parameters. - - - -class OBAB { - B? id ([A? x, B? y]) => y; -} - -class OTTy { - T? id([T? y]) => y; -} - -class PTT { - T? id(T? x) => x; -} - -// Same as above but with generic classes. -abstract class O7 = OII with OBAB; -abstract class O8 extends OII with OBAB {} - - -abstract class O11 = OII with OTTy; -abstract class O12 extends OII with OTTy {} - - - -// More tests with generic classes. -abstract class GTTnum { - T id(x); -} - -class MTTnum { - T id(x) => x; -} - -class MTTint { - T id(x) => x; -} - -class MTT { - T id(x) => x; -} - -class MTTnumR { - T id(x) => x; -} -class G1 = GTTnum with MTTnum; - - - - - -void main() {} diff --git a/tests/language/mixin/method_override_test.dart b/tests/language/mixin/method_override_test.dart index 31e39ceba73..9e96fc61a8f 100644 --- a/tests/language/mixin/method_override_test.dart +++ b/tests/language/mixin/method_override_test.dart @@ -2,24 +2,20 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Signature conformance test. -abstract class CII { +abstract mixin class CII { int id(int x); } -class CSI { +mixin CSI { String id(int x) => "$x"; } -class CIS { +mixin CIS { int id(String x) => 0; } -class CTT { +mixin CTT { T id(T x) => x; } @@ -67,15 +63,15 @@ abstract class NIIx { int? id({int? x}) => x; } -class NIIxy { +mixin NIIxy { int? id({int? x, int? y}) => y; } -class NIIy { +mixin NIIy { int? id({int? y}) => y; } -class NII { +mixin NII { int? id(int? x) => x; } @@ -107,15 +103,15 @@ abstract class N6 extends NIIx with NII {} // ^^^ // [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE -class NBABxy { +mixin NBABxy { B? id ({A? x, B? y}) => y; } -class NTTy { +mixin NTTy { T? id({T? y}) => y; } -class NTTx { +mixin NTTx { T? id(T? x) => x; } @@ -158,15 +154,15 @@ abstract class OII { int? id([int? x]) => x; } -class OIII { +mixin OIII { int? id([int? x, int? y]) => y; } -class OIIy { +mixin OIIy { int? id([int? y]) => y; } -class PII { +mixin PII { int? id(int? x) => x; } @@ -188,15 +184,15 @@ abstract class O6 extends OII with PII {} // ^^^ // [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE -class OBAB { +mixin OBAB { B? id ([A? x, B? y]) => y; } -class OTTy { +mixin OTTy { T? id([T? y]) => y; } -class PTT { +mixin PTT { T? id(T? x) => x; } @@ -231,19 +227,19 @@ abstract class GTTnum { T id(x); } -class MTTnum { +mixin MTTnum { T id(x) => x; } -class MTTint { +mixin MTTint { T id(x) => x; } -class MTT { +mixin MTT { T id(x) => x; } -class MTTnumR { +mixin MTTnumR { T id(x) => x; } class G1 = GTTnum with MTTnum; diff --git a/tests/language/mixin/method_test.dart b/tests/language/mixin/method_test.dart index 1fc61694679..e689fe1694a 100644 --- a/tests/language/mixin/method_test.dart +++ b/tests/language/mixin/method_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class S { @@ -13,11 +9,11 @@ class S { baz() => "S-baz"; } -class M1 { +mixin M1 { bar() => "M1-bar"; } -class M2 { +mixin M2 { bar() => "M2-bar"; baz() => "M2-baz"; fez() => "M2-fez"; diff --git a/tests/language/mixin/mixin2_test.dart b/tests/language/mixin/mixin2_test.dart index 156819d5659..e9ba93d21f4 100644 --- a/tests/language/mixin/mixin2_test.dart +++ b/tests/language/mixin/mixin2_test.dart @@ -2,23 +2,19 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class M { +mixin M { t() { return T; } } -class A = Object with M; +mixin class A = Object with M; class B = Object with A; -class C = Object with M>; +mixin class C = Object with M>; class D = Object with C>; diff --git a/tests/language/mixin/mixin3_test.dart b/tests/language/mixin/mixin3_test.dart index be51a66b232..7dcef0f4f51 100644 --- a/tests/language/mixin/mixin3_test.dart +++ b/tests/language/mixin/mixin3_test.dart @@ -2,29 +2,25 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class M { +mixin M { t() { return T; } } -class A = Object with M>; +mixin class A = Object with M>; class B0 = Object with A>; -class B1 = Object with A>; +mixin class B1 = Object with A>; class C0 extends B0 {} class C1 extends B1 {} -class A2 = Object with M>; +mixin class A2 = Object with M>; class B2 = Object with A2, List>; @@ -34,13 +30,13 @@ class C2 extends B2 {} class C3 extends B3 {} -class N { +mixin N { q() { return 42; } } -class O = Object with N; +mixin class O = Object with N; class P = Object with O; diff --git a/tests/language/mixin/mixin4_test.dart b/tests/language/mixin/mixin4_test.dart index 27d5b55baf1..4d3d67a2f98 100644 --- a/tests/language/mixin/mixin4_test.dart +++ b/tests/language/mixin/mixin4_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class I {} @@ -14,13 +10,13 @@ class J {} class S {} -class M { +mixin M { t() { return T; } } -class A = Object with M> implements I; +mixin class A = Object with M> implements I; class C = S with A> implements J; diff --git a/tests/language/mixin/mixin5_test.dart b/tests/language/mixin/mixin5_test.dart index 91c1cbc7391..62ad13ad88f 100644 --- a/tests/language/mixin/mixin5_test.dart +++ b/tests/language/mixin/mixin5_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class I {} @@ -16,15 +12,15 @@ class K {} class S {} -class M { +mixin M { m() { return T; } } -class A = Object with M> implements I; +mixin class A = Object with M> implements I; -class B = Object with A> implements J; +mixin class B = Object with A> implements J; class C = S> with B> implements K; diff --git a/tests/language/mixin/mixin6_test.dart b/tests/language/mixin/mixin6_test.dart index a5c6989551c..604b5b78586 100644 --- a/tests/language/mixin/mixin6_test.dart +++ b/tests/language/mixin/mixin6_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class I {} @@ -16,15 +12,15 @@ class K {} class S {} -class M { +mixin M { m() { return T; } } -class A = Object with M> implements I; +mixin class A = Object with M> implements I; -class B = Object with A> implements J; +mixin class B = Object with A> implements J; class C = S> with B implements K; // B is raw. diff --git a/tests/language/mixin/mixin7_test.dart b/tests/language/mixin/mixin7_test.dart index b2240df8bc6..d8707a42d75 100644 --- a/tests/language/mixin/mixin7_test.dart +++ b/tests/language/mixin/mixin7_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class I {} @@ -16,15 +12,15 @@ class K {} class S {} -class M { +mixin M { m() { return T; } } -class A = Object with M implements I; // M is raw. +mixin class A = Object with M implements I; // M is raw. -class B = Object with A implements J; // A is raw. +mixin class B = Object with A implements J; // A is raw. class C = S> with B implements K; // B is raw. diff --git a/tests/language/mixin/mixin_bound2_test.dart b/tests/language/mixin/mixin_bound2_test.dart index da4a5d8873a..00a38248d19 100644 --- a/tests/language/mixin/mixin_bound2_test.dart +++ b/tests/language/mixin/mixin_bound2_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class I {} @@ -16,15 +12,16 @@ class K {} class S, V> {} -class M> { +mixin M> { m() { return T; } } -class A> = Object with M> implements I; +mixin class A> = + Object with M> implements I; -class B> = Object with A> implements J; +mixin class B> = Object with A> implements J; class C = S, T> with B> implements K; diff --git a/tests/language/mixin/mixin_bound_test.dart b/tests/language/mixin/mixin_bound_test.dart index 41dd1c28a94..1c2a7161109 100644 --- a/tests/language/mixin/mixin_bound_test.dart +++ b/tests/language/mixin/mixin_bound_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class I {} @@ -14,13 +10,14 @@ class J {} class S, V> {} -class M> { +mixin M> { t() { return T; } } -class A = Object with M> implements I; +mixin class A = + Object with M> implements I; class C = S, T> with A> implements J; diff --git a/tests/language/mixin/mixin_test.dart b/tests/language/mixin/mixin_test.dart index ae39319485e..5b08053d965 100644 --- a/tests/language/mixin/mixin_test.dart +++ b/tests/language/mixin/mixin_test.dart @@ -2,17 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class M1 { +mixin M1 { foo() => 42; } -class M2 = Object with M1; +mixin class M2 = Object with M1; class S {} diff --git a/tests/language/mixin/mixin_type_arguments_test.dart b/tests/language/mixin/mixin_type_arguments_test.dart index 19e5388e970..0561e1b6808 100644 --- a/tests/language/mixin/mixin_type_arguments_test.dart +++ b/tests/language/mixin/mixin_type_arguments_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import 'package:expect/expect.dart' show Expect; @pragma("vm:entry-point") // Prevent obfuscation @@ -27,27 +23,27 @@ class E {} class F {} @pragma("vm:entry-point") // Prevent obfuscation -class M1 { +mixin M1 { Type m1() => M1; } @pragma("vm:entry-point") // Prevent obfuscation -class M2 { +mixin M2 { Type m2() => M2; } @pragma("vm:entry-point") // Prevent obfuscation -class M3 { +mixin M3 { Type m3() => M3; } @pragma("vm:entry-point") // Prevent obfuscation -class M4 { +mixin M4 { Type m4() => M4; } @pragma("vm:entry-point") // Prevent obfuscation -class M5 { +mixin M5 { Type m5() => M5; } diff --git a/tests/language/mixin/named_constructor_test.dart b/tests/language/mixin/named_constructor_test.dart index ecdd4fee1c5..237986f16f5 100644 --- a/tests/language/mixin/named_constructor_test.dart +++ b/tests/language/mixin/named_constructor_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; var calls = []; -abstract class A { +mixin A { bool _done = true; var a = calls.add('A()') as dynamic; } diff --git a/tests/language/mixin/naming_test.dart b/tests/language/mixin/naming_test.dart index a736fbb9b23..08921c0dee3 100644 --- a/tests/language/mixin/naming_test.dart +++ b/tests/language/mixin/naming_test.dart @@ -2,19 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class S {} -class M1 {} +mixin M1 {} -class M2 {} +mixin M2 {} -class M3 {} +mixin M3 {} class C = S with M1, M2, M3; diff --git a/tests/language/mixin/only_for_rti_test.dart b/tests/language/mixin/only_for_rti_test.dart index 856814061cf..5a6b58b4235 100644 --- a/tests/language/mixin/only_for_rti_test.dart +++ b/tests/language/mixin/only_for_rti_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class Tester { @@ -18,13 +14,13 @@ abstract class A = B with C; class B {} -class C {} +mixin C {} class X extends Y with Z {} class Y {} -class Z {} +mixin Z {} main() { // Classes A and X are only used as generic arguments. diff --git a/tests/language/mixin/override_regression_test.dart b/tests/language/mixin/override_regression_test.dart index 6036a0090b3..f77b7b9b4c4 100644 --- a/tests/language/mixin/override_regression_test.dart +++ b/tests/language/mixin/override_regression_test.dart @@ -2,20 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class C0 { +mixin class C0 { int m1() => 5; int m2() => m1(); } class C1 = Object with C0; -class D { +mixin D { int m1() => 7; } diff --git a/tests/language/mixin/prefix_lib.dart b/tests/language/mixin/prefix_lib.dart index b188a891445..de2b17e05d8 100644 --- a/tests/language/mixin/prefix_lib.dart +++ b/tests/language/mixin/prefix_lib.dart @@ -4,8 +4,8 @@ library mixin_prefix_lib; -import "dart:convert"; +import "dart:convert" as convert; mixin MixinClass { - String bar() => json.encode({'a': 1}); + String bar() => convert.jsonEncode({'a': 1}); } diff --git a/tests/language/mixin/prefix_test.dart b/tests/language/mixin/prefix_test.dart index d40f55ee1fb..59eb4427904 100644 --- a/tests/language/mixin/prefix_test.dart +++ b/tests/language/mixin/prefix_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Regression test for issue 11891. import "package:expect/expect.dart"; diff --git a/tests/language/mixin/proto_test.dart b/tests/language/mixin/proto_test.dart index 6b57a4fa01e..4780a543bb3 100644 --- a/tests/language/mixin/proto_test.dart +++ b/tests/language/mixin/proto_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Tests that a program in csp mode doesn't access the prototype chain // on platforms that don't support direct access to __proto__. // This test is most useful with --csp and on a platform that doesn't support @@ -20,7 +16,7 @@ class A { bar() => 22; } -class B { +mixin class B { var y; foo() => 42; } diff --git a/tests/language/mixin/recursive_mixin_test.dart b/tests/language/mixin/recursive_mixin_test.dart index 358b60cd886..43428407748 100644 --- a/tests/language/mixin/recursive_mixin_test.dart +++ b/tests/language/mixin/recursive_mixin_test.dart @@ -2,20 +2,17 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 +// Tests #31290 import "package:expect/expect.dart"; -class A { +mixin A { bool foo(T x) => true; } class B extends Object with A, C {} -// Tests #31290 -class C {} +mixin C {} main() { var b = new B(); diff --git a/tests/language/mixin/regress_11398_test.dart b/tests/language/mixin/regress_11398_test.dart index 1b329af27f6..8f93106c0e1 100644 --- a/tests/language/mixin/regress_11398_test.dart +++ b/tests/language/mixin/regress_11398_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; void main() { @@ -26,11 +22,11 @@ abstract class Delegate { String invoke(String value); } -abstract class DelegateMixin { +mixin DelegateMixin { String invoke(String value) => value; } -abstract class HasValueMixin implements Delegate { +mixin HasValueMixin implements Delegate { String _value = ''; set value(String value) { _value = invoke(value); diff --git a/tests/language/mixin/regress_13688_test.dart b/tests/language/mixin/regress_13688_test.dart index e0c44ac614f..4dc6faa5114 100644 --- a/tests/language/mixin/regress_13688_test.dart +++ b/tests/language/mixin/regress_13688_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class ComparableMixin { +mixin ComparableMixin { e() { return E; } diff --git a/tests/language/mixin/regress_flutter_55345_const_test.dart b/tests/language/mixin/regress_flutter_55345_const_test.dart index bb4463da8cb..d6450f7e3e9 100644 --- a/tests/language/mixin/regress_flutter_55345_const_test.dart +++ b/tests/language/mixin/regress_flutter_55345_const_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Verifies that references to deduplicated mixins are properly updated // in types which are only accessible through constants. // Regression test for https://github.com/flutter/flutter/issues/55345. -class Diagnosticable {} +mixin Diagnosticable {} class SomeClass with Diagnosticable {} diff --git a/tests/language/mixin/regress_flutter_55345_test.dart b/tests/language/mixin/regress_flutter_55345_test.dart index f7e61db90cc..5e7de027ab9 100644 --- a/tests/language/mixin/regress_flutter_55345_test.dart +++ b/tests/language/mixin/regress_flutter_55345_test.dart @@ -2,14 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Verifies that references to deduplicated mixins are properly updated. // Regression test for https://github.com/flutter/flutter/issues/55345. -class Diagnosticable {} +mixin Diagnosticable {} class SomeClass with Diagnosticable {} diff --git a/tests/language/mixin/substitution_test.dart b/tests/language/mixin/substitution_test.dart index a422ca6159d..b09f28ec588 100644 --- a/tests/language/mixin/substitution_test.dart +++ b/tests/language/mixin/substitution_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Test that mixins don't interfere with type variable substitution. import '../dynamic_type_helper.dart'; @@ -14,7 +10,7 @@ class B { B(T x); } -class M {} +mixin M {} class A extends B with M { A(T x) : super(x); // This line must be warning free. diff --git a/tests/language/mixin/super_2_test.dart b/tests/language/mixin/super_2_test.dart index 0e0137206dc..8c518c07a46 100644 --- a/tests/language/mixin/super_2_test.dart +++ b/tests/language/mixin/super_2_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class B { +mixin class B { // 'super' resolves to Object, and in some tests, multiple points in the // inheritance chain. toString() => 'B(' + super.toString() + ')'; diff --git a/tests/language/mixin/super_bound_runtime_test.dart b/tests/language/mixin/super_bound_runtime_test.dart deleted file mode 100644 index ad7c91d183c..00000000000 --- a/tests/language/mixin/super_bound_runtime_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -class M {} - -class N {} - -class S {} - -class MNA extends S> - with M, N, List> {} - -class MNA2 = S> with M, N, List>; - -main() { - new MNA(); - new MNA2(); - - // Type parameter U of M must extend type parameter V, but - // type argument num is not a subtype of int. - - // Type parameter U of M must extend type parameter V, but - // type argument num is not a subtype of int. - -} diff --git a/tests/language/mixin/super_bound_test.dart b/tests/language/mixin/super_bound_test.dart index a4ffc8ba1cf..9d49e98328d 100644 --- a/tests/language/mixin/super_bound_test.dart +++ b/tests/language/mixin/super_bound_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 +mixin M {} -class M {} - -class N {} +mixin N {} class S {} diff --git a/tests/language/mixin/super_constructor2_test.dart b/tests/language/mixin/super_constructor2_test.dart index 4a1c10201f8..9946b549404 100644 --- a/tests/language/mixin/super_constructor2_test.dart +++ b/tests/language/mixin/super_constructor2_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class Base { @@ -14,7 +10,7 @@ class Base { Base.ctor2(int i, this.j) : this.i = i + 8; } -abstract class M { +abstract mixin class M { get i; get j; int k = 42; diff --git a/tests/language/mixin/super_constructor_default_test.dart b/tests/language/mixin/super_constructor_default_test.dart index e248cf9de1d..edf23cb60ef 100644 --- a/tests/language/mixin/super_constructor_default_test.dart +++ b/tests/language/mixin/super_constructor_default_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class Base { @@ -13,7 +9,7 @@ class Base { Base(int i, this.j) : this.i = i + 7; } -abstract class M { +abstract mixin class M { int get i; int get j; int k = 42; diff --git a/tests/language/mixin/super_constructor_multiple_test.dart b/tests/language/mixin/super_constructor_multiple_test.dart index 80bd25a6228..c34066a8e20 100644 --- a/tests/language/mixin/super_constructor_multiple_test.dart +++ b/tests/language/mixin/super_constructor_multiple_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class S { @@ -13,9 +9,9 @@ class S { S.foo() : i = 1742; } -class M1 {} +mixin class M1 {} -class M2 {} +mixin class M2 {} class C extends S with M1, M2 { C.foo() : super.foo(); diff --git a/tests/language/mixin/super_constructor_named_test.dart b/tests/language/mixin/super_constructor_named_test.dart index 433c5c2010f..93739bb62de 100644 --- a/tests/language/mixin/super_constructor_named_test.dart +++ b/tests/language/mixin/super_constructor_named_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class Base { @@ -19,7 +15,7 @@ class Base { } } -abstract class M { +abstract mixin class M { int? get i; int? get j; int k = 42; diff --git a/tests/language/mixin/super_constructor_positionals_test.dart b/tests/language/mixin/super_constructor_positionals_test.dart index 76603b2e547..ab5a54c0898 100644 --- a/tests/language/mixin/super_constructor_positionals_test.dart +++ b/tests/language/mixin/super_constructor_positionals_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class Base { @@ -18,7 +14,7 @@ class Base { ); } -abstract class M { +abstract mixin class M { int? get i; int? get j; int k = 42; diff --git a/tests/language/mixin/super_constructor_test.dart b/tests/language/mixin/super_constructor_test.dart index 97e263257aa..d6b3a98137d 100644 --- a/tests/language/mixin/super_constructor_test.dart +++ b/tests/language/mixin/super_constructor_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class Base { @@ -13,7 +9,7 @@ class Base { Base.ctor(int i, this.j) : this.i = i + 7; } -abstract class M { +abstract mixin class M { int get i; int get j; int k = 42; diff --git a/tests/language/mixin/super_use_test.dart b/tests/language/mixin/super_use_test.dart index 02a56009df8..c84a157e0b9 100644 --- a/tests/language/mixin/super_use_test.dart +++ b/tests/language/mixin/super_use_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class M {} +mixin M {} -class P0 { +mixin P0 { foo() { super.toString(); @@ -28,7 +24,7 @@ class P0 { } } -class P1 { +mixin class P1 { bar() { super.toString(); return 87; @@ -48,7 +44,7 @@ class P1 { } } -class P2 { +mixin class P2 { baz() { super.toString(); return 99; diff --git a/tests/language/mixin/superclass_runtime_test.dart b/tests/language/mixin/superclass_runtime_test.dart deleted file mode 100644 index 6c986e1aa75..00000000000 --- a/tests/language/mixin/superclass_runtime_test.dart +++ /dev/null @@ -1,129 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -class S0 {} - -class S1 extends Object {} - -class S2 extends S0 {} - -class M0 {} - -class M1 extends Object {} - -mixin M2 on M0 {} - -class C00 = S0 with M0; -class C01 = S0 with M1; - -class C03 = S0 with M0, M1; -class C04 = S0 with M0, M2; - - - - -class C10 = S1 with M0; -class C11 = S1 with M1; - -class C13 = S1 with M0, M1; -class C14 = S1 with M0, M2; - - - - -class C20 = S2 with M0; -class C21 = S2 with M1; - -class C23 = S2 with M0, M1; -class C24 = S2 with M0, M2; - - - - -class D00 extends S0 with M0 {} - -class D01 extends S0 with M1 {} - - - -class D03 extends S0 with M0, M1 {} - -class D04 extends S0 with M0, M2 {} - - - - - - - -class D10 extends S1 with M0 {} - -class D11 extends S1 with M1 {} - - - -class D13 extends S1 with M0, M1 {} - -class D14 extends S1 with M0, M2 {} - - - - - - - -class D20 extends S2 with M0 {} - -class D21 extends S2 with M1 {} - - - -class D23 extends S2 with M0, M1 {} - -class D24 extends S2 with M0, M2 {} - - - - - - - -main() { - new C00(); - new C01(); - new C03(); - new C04(); - - new C10(); - new C11(); - new C13(); - new C14(); - - new C20(); - new C21(); - new C23(); - new C24(); - - new D00(); - new D01(); - new D03(); - new D04(); - - new D10(); - new D11(); - new D13(); - new D14(); - - new D20(); - new D21(); - new D23(); - new D24(); -} diff --git a/tests/language/mixin/superclass_test.dart b/tests/language/mixin/superclass_test.dart index c2ffe52a2ef..c1d5a182086 100644 --- a/tests/language/mixin/superclass_test.dart +++ b/tests/language/mixin/superclass_test.dart @@ -2,19 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - class S0 {} class S1 extends Object {} class S2 extends S0 {} -class M0 {} +mixin M0 {} -class M1 extends Object {} +mixin class M1 extends Object {} mixin M2 on M0 {} diff --git a/tests/language/mixin/supertype_subclass2_test.dart b/tests/language/mixin/supertype_subclass2_test.dart deleted file mode 100644 index e040e5e0e2d..00000000000 --- a/tests/language/mixin/supertype_subclass2_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -class B {} - -class C {} - -class D {} - -class E extends B with C implements D {} - -class F extends E {} - -// M is mixed onto E which implements B, C and D. -mixin M // - on B //# 01: ok - on C //# 02: ok - on D //# 03: ok - on E //# 04: ok - on F //# 05: compile-time error -{} - -class A extends E with M {} - -main() { - new A(); -} diff --git a/tests/language/mixin/supertype_subclass_error_test.dart b/tests/language/mixin/supertype_subclass_error_test.dart new file mode 100644 index 00000000000..4d7dfc30f66 --- /dev/null +++ b/tests/language/mixin/supertype_subclass_error_test.dart @@ -0,0 +1,42 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +class B {} + +mixin C {} + +class D {} + +class E extends B with C implements D {} + +class F extends E {} + +// M is mixed onto E which implements B, C and D. +mixin MB on B {} +mixin MC on C {} +mixin MD on D {} +mixin ME on E {} +mixin MF on F {} + +class AB extends E with MB {} +class AC extends E with MC {} +class AD extends E with MD {} +class AE extends E with ME {} +class AF extends E with MF {} +// ^ +// [cfe] 'E' doesn't implement 'F' so it can't be used with 'MF'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_APPLICATION_NOT_IMPLEMENTED_INTERFACE + +class AB2 = E with MB; +class AC2 = E with MC; +class AD2 = E with MD; +class AE2 = E with ME; +class AF2 = E with MF; +// ^ +// [cfe] 'E' doesn't implement 'F' so it can't be used with 'MF'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_APPLICATION_NOT_IMPLEMENTED_INTERFACE + +main() {} diff --git a/tests/language/mixin/supertype_subclass_test.dart b/tests/language/mixin/supertype_subclass_test.dart deleted file mode 100644 index 9f3000c7515..00000000000 --- a/tests/language/mixin/supertype_subclass_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -class B {} - -class C {} - -class D {} - -class E extends B with C implements D {} - -class F extends E {} - -// M is mixed onto E which implements B, C and D. -mixin M // - on B //# 01: ok - on C //# 02: ok - on D //# 03: ok - on E //# 04: ok - on F //# 05: compile-time error -{} - -class A = E with M; - -main() { - new A(); -} diff --git a/tests/language/mixin/this_use_test.dart b/tests/language/mixin/this_use_test.dart index 954e49d3dbd..cf2a57ee9ba 100644 --- a/tests/language/mixin/this_use_test.dart +++ b/tests/language/mixin/this_use_test.dart @@ -2,17 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -// Test that [:this:] in a class A used as a mixin in class D knows it can be an +// Test that `this` in a class A used as a mixin in class D knows it can be an // instance of D. import "package:expect/expect.dart"; -class A { - foo() => bar(); // Implicit use of [:this:] +mixin class A { + foo() => bar(); // Implicit use of `this` bar() => 42; } diff --git a/tests/language/mixin/type_parameter1_test.dart b/tests/language/mixin/type_parameter1_test.dart index 4f5f2046b74..3e9ebf8601c 100644 --- a/tests/language/mixin/type_parameter1_test.dart +++ b/tests/language/mixin/type_parameter1_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin1 {} +mixin Mixin1 {} -abstract class Mixin2 {} +mixin Mixin2 {} class A {} diff --git a/tests/language/mixin/type_parameter2_test.dart b/tests/language/mixin/type_parameter2_test.dart index a95a516be97..13ac982b5e4 100644 --- a/tests/language/mixin/type_parameter2_test.dart +++ b/tests/language/mixin/type_parameter2_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin1 {} +mixin Mixin1 {} -abstract class Mixin2 {} +mixin Mixin2 {} class A { A(foo); diff --git a/tests/language/mixin/type_parameter3_test.dart b/tests/language/mixin/type_parameter3_test.dart index 7d9404a9dd7..d9314cf57f8 100644 --- a/tests/language/mixin/type_parameter3_test.dart +++ b/tests/language/mixin/type_parameter3_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin1 {} +mixin Mixin1 {} -abstract class Mixin2 {} +mixin Mixin2 {} class A { A(foo); diff --git a/tests/language/mixin/type_parameter4_test.dart b/tests/language/mixin/type_parameter4_test.dart index 739e5ba8e0f..bc5771a74e2 100644 --- a/tests/language/mixin/type_parameter4_test.dart +++ b/tests/language/mixin/type_parameter4_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class R {} -class M implements R {} +mixin M implements R {} class B1 {} diff --git a/tests/language/mixin/type_parameter5_test.dart b/tests/language/mixin/type_parameter5_test.dart index fe667544e52..c87b2f260d7 100644 --- a/tests/language/mixin/type_parameter5_test.dart +++ b/tests/language/mixin/type_parameter5_test.dart @@ -2,19 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -class MixinA { +mixin MixinA { T? intField; } -class MixinB { +mixin MixinB { S? stringField; } -class MixinC { +mixin MixinC { U? listField; V? mapField; } diff --git a/tests/language/mixin/type_parameter6_test.dart b/tests/language/mixin/type_parameter6_test.dart index a8ba0297ee8..5f295088bbd 100644 --- a/tests/language/mixin/type_parameter6_test.dart +++ b/tests/language/mixin/type_parameter6_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - class A {} -class B { +mixin B { int? foo(S s) => null; } diff --git a/tests/language/mixin/type_parameter_inference_previous_mixin_test.dart b/tests/language/mixin/type_parameter_inference_previous_mixin_test.dart index 9edecedb0f9..87fa5458403 100644 --- a/tests/language/mixin/type_parameter_inference_previous_mixin_test.dart +++ b/tests/language/mixin/type_parameter_inference_previous_mixin_test.dart @@ -2,21 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; +import "package:expect/static_type_helper.dart"; abstract class A { // This is ok because type inference will ensure that in C, A and M are // instantiated with the same T. - T f(T x) => x; //# 01: ok + T f(T x) => x; } class B {} -abstract class M1 implements A {} +mixin M1 implements A {} mixin M2 on A { T f(T x) => x; @@ -30,12 +27,16 @@ class C extends Object with M1, M2 {} main() { C c = new C(); - // M is instantiated with B, so C.g has type (B) -> B. - B Function(B) x = c.g; //# 02: ok - Null Function(Null) x = c.g; //# 03: compile-time error - Object Function(Object) x = c.g; //# 04: compile-time error + // M is instantiated with B. + A asA = c; // Allowed. + + // So C.g has type (B) -> B. + // Static type. + Expect.equals(typeOf(), c.g.staticType); + // Runtime type. Is covariant-by-generic, so actual argument type is Object?. + Expect.equals(typeOf(), c.g.runtimeType); // And verify that the runtime system has the right type for the type // parameter - Expect.equals(c.h(), B); //# 05: ok + Expect.equals(B, c.h()); } diff --git a/tests/language/mixin/type_parameter_inference_test.dart b/tests/language/mixin/type_parameter_inference_test.dart index 0f445f703aa..abffe136d4f 100644 --- a/tests/language/mixin/type_parameter_inference_test.dart +++ b/tests/language/mixin/type_parameter_inference_test.dart @@ -2,11 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; +import "package:expect/static_type_helper.dart"; abstract class A { // This is ok because type inference will ensure that in C, A and M are @@ -22,7 +19,7 @@ mixin M1 on A { Type h() => T; } -class M2 { +mixin class M2 { T g(T x) => x; Type h() => T; } @@ -45,33 +42,25 @@ main() { E e = new E(); F f = new F(); - // M1 is instantiated with B, so C.g has type (B) -> B. - B Function(B) x = c.g; //# 02: ok - B Function(B) x = d.g; //# 03: ok - Null Function(Null) x = c.g; //# 04: compile-time error - Null Function(Null) x = d.g; //# 05: compile-time error - Object Function(Object) x = c.g; //# 06: compile-time error - Object Function(Object) x = d.g; //# 07: compile-time error - + // M1 is instantiated with B, so C.g has static type (B) -> B. + Expect.equals(typeOf(), c.g.staticType); + // Is covariant-by-generics, so runtime parameter type is Object?. + Expect.equals(typeOf(), c.g.runtimeType); // And verify that the runtime system has the right type for the type // parameter - Expect.equals(c.h(), B); //# 08: ok - Expect.equals(c.h(), B); //# 09: ok + Expect.equals(B, c.h()); - // M2 is instantiated with dynamic, so E.g has type (dynamic) -> dynamic. - dynamic Function(dynamic) x = e.g; //# 10: ok - B Function(B) x = e.g; //# 11: compile-time error + Expect.equals(typeOf(), d.g.staticType); + Expect.equals(typeOf(), d.g.runtimeType); + Expect.equals(B, d.h()); - // And verify that the runtime system has the right type for the type - // parameter - Expect.equals(e.h(), dynamic); //# 12: ok + // M2 is instantiated with dynamic, E.g has static type (dynamic) -> dynamic. + Expect.equals(typeOf(), e.g.staticType); + Expect.equals(typeOf(), e.g.runtimeType); + Expect.equals(dynamic, e.h()); // M2 is instantiated with B, so F.g has type (B) -> B. - B Function(B) x = f.g; //# 13: ok - Null Function(Null) x = f.g; //# 14: compile-time error - Object Function(Object) x = f.g; //# 15: compile-time error - - // And verify that the runtime system has the right type for the type - // parameter - Expect.equals(f.h(), B); //# 16: ok + Expect.equals(typeOf(), f.g.staticType); + Expect.equals(typeOf(), f.g.runtimeType); + Expect.equals(B, f.h()); } diff --git a/tests/language/mixin/type_parameters_errors_runtime_test.dart b/tests/language/mixin/type_parameters_errors_runtime_test.dart deleted file mode 100644 index 524c1e7fd2e..00000000000 --- a/tests/language/mixin/type_parameters_errors_runtime_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -class S {} - -class M {} - -class A extends S with M {} - - - -class F = S with M; - - -main() { - var a; - a = new A(); - a = new A(); - - a = new F(); - -} diff --git a/tests/language/mixin/type_parameters_errors_test.dart b/tests/language/mixin/type_parameters_errors_test.dart index 21c2409c263..f3ed612cb38 100644 --- a/tests/language/mixin/type_parameters_errors_test.dart +++ b/tests/language/mixin/type_parameters_errors_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - class S {} -class M {} +mixin M {} class A extends S with M {} class B extends S with M { } diff --git a/tests/language/mixin/type_parameters_mixin_extends_test.dart b/tests/language/mixin/type_parameters_mixin_extends_test.dart index a489793b4f4..f7f35e3c00c 100644 --- a/tests/language/mixin/type_parameters_mixin_extends_test.dart +++ b/tests/language/mixin/type_parameters_mixin_extends_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class M { +mixin M { bool matches(o) { bool isChecked = checkUsingIs(o); if (checkedMode) { diff --git a/tests/language/mixin/type_parameters_mixin_test.dart b/tests/language/mixin/type_parameters_mixin_test.dart index f55414ba6d3..cf7f5505783 100644 --- a/tests/language/mixin/type_parameters_mixin_test.dart +++ b/tests/language/mixin/type_parameters_mixin_test.dart @@ -2,17 +2,14 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; +import "package:expect/variations.dart"; -class M { +mixin M { bool matches(o) { - bool isChecked = checkUsingIs(o); - if (checkedMode) { - Expect.equals(isChecked, checkUsingCheckedMode(o)); + bool isChecked = checkUsingIs(o); // `is` check. + if (checkedImplicitDowncasts) { + Expect.equals(isChecked, checkUsingDowncast(o)); // `as` check, implicit. } return isChecked; } @@ -21,24 +18,14 @@ class M { return o is T; } - bool checkUsingCheckedMode(o) { + bool checkUsingDowncast(o) { try { - T x = o; + T x = o as dynamic; } on Error { return false; } return true; } - - static final bool checkedMode = computeCheckedMode(); - static bool computeCheckedMode() { - try { - int x = "foo" as dynamic; - } on Error { - return true; - } - return false; - } } class S {} diff --git a/tests/language/mixin/type_parameters_simple_test.dart b/tests/language/mixin/type_parameters_simple_test.dart index 51ebec906a2..a06c87f1cc8 100644 --- a/tests/language/mixin/type_parameters_simple_test.dart +++ b/tests/language/mixin/type_parameters_simple_test.dart @@ -2,19 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class S {} -class M1 { +mixin M1 { m1() => X; } -class M2 { +mixin M2 { m2() => Y; } diff --git a/tests/language/mixin/type_parameters_super_extends_test.dart b/tests/language/mixin/type_parameters_super_extends_test.dart index 30140c25c47..2d28c5eb77b 100644 --- a/tests/language/mixin/type_parameters_super_extends_test.dart +++ b/tests/language/mixin/type_parameters_super_extends_test.dart @@ -2,17 +2,14 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; +import "package:expect/variations.dart"; class S { bool matches(o) { - bool isChecked = checkUsingIs(o); - if (checkedMode) { - Expect.equals(isChecked, checkUsingCheckedMode(o)); + bool isChecked = checkUsingIs(o); // `is` check. + if (checkedImplicitDowncasts) { + Expect.equals(isChecked, checkUsingDowncast(o)); // `as` check, implicit. } return isChecked; } @@ -21,27 +18,17 @@ class S { return o is T; } - bool checkUsingCheckedMode(o) { + bool checkUsingDowncast(o) { try { - T x = o; + T x = o as dynamic; } on Error { return false; } return true; } - - static final bool checkedMode = computeCheckedMode(); - static bool computeCheckedMode() { - try { - int x = "foo" as dynamic; - } on Error { - return true; - } - return false; - } } -class M {} +mixin M {} class C0 extends S with M {} diff --git a/tests/language/mixin/type_parameters_super_test.dart b/tests/language/mixin/type_parameters_super_test.dart index e89881399d6..8b5e92066ce 100644 --- a/tests/language/mixin/type_parameters_super_test.dart +++ b/tests/language/mixin/type_parameters_super_test.dart @@ -2,17 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class S { bool matches(o) => o is T; } -class M {} +mixin M {} class C0 = S with M; class C1 = S with M; diff --git a/tests/language/mixin/type_variable_test.dart b/tests/language/mixin/type_variable_test.dart index 46623f7c7bb..f5b263f454b 100644 --- a/tests/language/mixin/type_variable_test.dart +++ b/tests/language/mixin/type_variable_test.dart @@ -2,35 +2,31 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Regression test for generic mixin fields. -class A { +mixin class A { T? field; } class B = Object with A; -class C extends B {} //# 03: ok -class D extends B {} //# 04: ok +class C extends B {} +class D extends B {} class E = Object with A; -class F extends E {} //# 06: ok +class F extends E {} -class G extends Object with A {} //# 07: ok -class H extends Object with A {} //# 08: ok +class G extends Object with A {} +class H extends Object with A {} void main() { - new A(); //# 01: ok - new B(); //# 02: ok - new C(); //# 03: continued - new D(); //# 04: continued - new E(); //# 05: ok - new F(); //# 06: continued - new G(); //# 07: continued - new H(); //# 08: continued + new A(); + new B(); + new C(); + new D(); + new E(); + new F(); + new G(); + new H(); } diff --git a/tests/language/mixin/typedef_constructor_test.dart b/tests/language/mixin/typedef_constructor_test.dart index b1e13f8f8a7..5036bbba56b 100644 --- a/tests/language/mixin/typedef_constructor_test.dart +++ b/tests/language/mixin/typedef_constructor_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class A { @@ -13,7 +9,7 @@ class A { A(this.field); } -class Mixin { +mixin Mixin { var mixinField = 54; } diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_error_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_error_test.dart new file mode 100644 index 00000000000..fbe0dcc8856 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/const_constructor_error_test.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import "const_constructor_test.dart" show Application; + +main() { + // Only make forwarders const if original constructor is const. + const Application.c1(0); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c2(0); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c3(x: 0); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_legacy_error_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_legacy_error_test.dart new file mode 100644 index 00000000000..9a201e85d95 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/const_constructor_legacy_error_test.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 +import "const_constructor_legacy_test.dart" show Application; + +main() { + // Only make forwarders const if original constructor is const. + const Application.c1(0); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c2(0); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c3(x: 0); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_legacy_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_legacy_test.dart new file mode 100644 index 00000000000..a156a8caa2a --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/const_constructor_legacy_test.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; + +abstract class Mixin { + // Declares no instance variable. + int get x; + int get m => x; +} + +class Base { + final int x; + + // Non-const constructors. + Base.c1(this.x); + Base.c2([this.x = 37]); + Base.c3({this.x = 37}); + + // Non-forwarding generative const constructors. + const Base.c4(this.x); + const Base.c5([this.x = 37]); + const Base.c6({this.x = 37}); + + // Forwarding generative const constructors. + const Base.c7(int x) : this.c4(x); + const Base.c8([int x = 87]) : this.c4(x); + const Base.c9({int x = 87}) : this.c4(x); + const Base.c10(int x) : this.c5(x); + const Base.c11([int x = 87]) : this.c5(x); + const Base.c12({int x = 87}) : this.c5(x); + const Base.c13(int x) : this.c6(x: x); + const Base.c14([int x = 87]) : this.c6(x: x); + const Base.c15({int x = 87}) : this.c6(x: x); + + // Non-generative constructor. + const factory Base() = Base.c5; +} + +class Application = Base with Mixin; + +main() { + Expect.equals(42, new Application.c1(42).m); + Expect.equals(42, new Application.c2(42).m); + Expect.equals(42, new Application.c3(x: 42).m); + Expect.equals(42, const Application.c4(42).m); + Expect.equals(42, const Application.c5(42).m); + Expect.equals(42, const Application.c6(x: 42).m); + Expect.equals(42, const Application.c7(42).m); + Expect.equals(42, const Application.c8(42).m); + Expect.equals(42, const Application.c9(x: 42).m); + Expect.equals(42, const Application.c10(42).m); + Expect.equals(42, const Application.c11(42).m); + Expect.equals(42, const Application.c12(x: 42).m); + Expect.equals(42, const Application.c13(42).m); + Expect.equals(42, const Application.c14(42).m); + Expect.equals(42, const Application.c15(x: 42).m); + + Expect.equals(37, new Application.c2().m); + Expect.equals(37, new Application.c3().m); + Expect.equals(37, const Application.c5().m); + Expect.equals(37, const Application.c6().m); + Expect.equals(87, const Application.c8().m); + Expect.equals(87, const Application.c9().m); + Expect.equals(87, const Application.c11().m); + Expect.equals(87, const Application.c12().m); + Expect.equals(87, const Application.c14().m); + Expect.equals(87, const Application.c15().m); +} diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_test.dart index 15f42ddb3ba..751fae888eb 100644 --- a/tests/language/mixin_constructor_forwarding/const_constructor_test.dart +++ b/tests/language/mixin_constructor_forwarding/const_constructor_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin { +mixin Mixin { // Declares no instance variable. int get x; int get m => x; @@ -61,22 +57,14 @@ main() { Expect.equals(42, const Application.c14(42).m); Expect.equals(42, const Application.c15(x: 42).m); - Expect.equals(37, new Application.c2().m); //# issue38304: ok + Expect.equals(37, new Application.c2().m); Expect.equals(37, new Application.c3().m); - Expect.equals(37, const Application.c5().m); //# issue38304: continued + Expect.equals(37, const Application.c5().m); Expect.equals(37, const Application.c6().m); - Expect.equals(87, const Application.c8().m); //# issue38304: continued + Expect.equals(87, const Application.c8().m); Expect.equals(87, const Application.c9().m); - Expect.equals(87, const Application.c11().m); //# issue38304: continued + Expect.equals(87, const Application.c11().m); Expect.equals(87, const Application.c12().m); - Expect.equals(87, const Application.c14().m); //# issue38304: continued + Expect.equals(87, const Application.c14().m); Expect.equals(87, const Application.c15().m); - - // Only make forwarders const if original constructor is const. - const Application.c1(0); //# 01: compile-time error - const Application.c2(0); //# 02: compile-time error - const Application.c3(x: 0); //# 03: compile-time error - - // Only insert forwarders for generative constructors. - new Application(); //# 04: compile-time error } diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_with_field_error_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_error_test.dart new file mode 100644 index 00000000000..ac682f61041 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_error_test.dart @@ -0,0 +1,78 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import "package:expect/expect.dart"; + +import "const_constructor_with_field_test.dart" show Application; + +main() { + // Forwarding constructors are not constant. + + const Application.c4(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c5(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c6(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c7(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c8(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c9(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c10(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c11(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c12(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c13(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c14(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c15(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_error_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_error_test.dart new file mode 100644 index 00000000000..e6a15d3692b --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_error_test.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; +import "const_constructor_with_field_legacy_test.dart" show Application; + +main() { + // Forwarding constructors are not constant. + + const Application.c4(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c5(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c6(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c7(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c8(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c9(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c10(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c11(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c12(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c13(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c14(42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + const Application.c15(x: 42); + // [error column 3, length 5] + // [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST + // ^ + // [cfe] Cannot invoke a non-'const' constructor where a const expression is expected. + + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_test.dart new file mode 100644 index 00000000000..d0771580ea8 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_legacy_test.dart @@ -0,0 +1,77 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; + +abstract class Mixin { + // Declares an instance variable. + // Declaration would be valid in a "const class", but mixin application + // won't get const constructor forwarders. + final int y = 0; + + int get x; + int get m => x; +} + +class Base { + final int x; + + // Non-const constructors. + Base.c1(this.x); + Base.c2([this.x = 37]); + Base.c3({this.x = 37}); + + // Non-forwarding generative const constructors. + const Base.c4(this.x); + const Base.c5([this.x = 37]); + const Base.c6({this.x = 37}); + + // Forwarding generative const constructors. + const Base.c7(int x) : this.c4(x); + const Base.c8([int x = 87]) : this.c4(x); + const Base.c9({int x = 87}) : this.c4(x); + const Base.c10(int x) : this.c5(x); + const Base.c11([int x = 87]) : this.c5(x); + const Base.c12({int x = 87}) : this.c5(x); + const Base.c13(int x) : this.c6(x: x); + const Base.c14([int x = 87]) : this.c6(x: x); + const Base.c15({int x = 87}) : this.c6(x: x); + + // Non-generative constructor. + const factory Base() = Base.c5; +} + +class Application = Base with Mixin; + +main() { + Expect.equals(42, new Application.c1(42).m); + Expect.equals(42, new Application.c2(42).m); + Expect.equals(42, new Application.c3(x: 42).m); + Expect.equals(42, new Application.c4(42).m); + Expect.equals(42, new Application.c5(42).m); + Expect.equals(42, new Application.c6(x: 42).m); + Expect.equals(42, new Application.c7(42).m); + Expect.equals(42, new Application.c8(42).m); + Expect.equals(42, new Application.c9(x: 42).m); + Expect.equals(42, new Application.c10(42).m); + Expect.equals(42, new Application.c11(42).m); + Expect.equals(42, new Application.c12(x: 42).m); + Expect.equals(42, new Application.c13(42).m); + Expect.equals(42, new Application.c14(42).m); + Expect.equals(42, new Application.c15(x: 42).m); + + Expect.equals(37, new Application.c2().m); + Expect.equals(37, new Application.c3().m); + Expect.equals(37, new Application.c5().m); + Expect.equals(37, new Application.c6().m); + Expect.equals(87, new Application.c8().m); + Expect.equals(87, new Application.c9().m); + Expect.equals(87, new Application.c11().m); + Expect.equals(87, new Application.c12().m); + Expect.equals(87, new Application.c14().m); + Expect.equals(87, new Application.c15().m); +} diff --git a/tests/language/mixin_constructor_forwarding/const_constructor_with_field_test.dart b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_test.dart index f3dd32c4b79..ccaaf883545 100644 --- a/tests/language/mixin_constructor_forwarding/const_constructor_with_field_test.dart +++ b/tests/language/mixin_constructor_forwarding/const_constructor_with_field_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin { +mixin Mixin { // Declares an instance variable. // Declaration would be valid in a "const class", but mixin application // won't get const constructor forwarders. @@ -65,31 +61,14 @@ main() { Expect.equals(42, new Application.c14(42).m); Expect.equals(42, new Application.c15(x: 42).m); - Expect.equals(37, new Application.c2().m); //# issue38304: ok + Expect.equals(37, new Application.c2().m); Expect.equals(37, new Application.c3().m); - Expect.equals(37, new Application.c5().m); //# issue38304: continued + Expect.equals(37, new Application.c5().m); Expect.equals(37, new Application.c6().m); - Expect.equals(87, new Application.c8().m); //# issue38304: continued + Expect.equals(87, new Application.c8().m); Expect.equals(87, new Application.c9().m); - Expect.equals(87, new Application.c11().m); //# issue38304: continued + Expect.equals(87, new Application.c11().m); Expect.equals(87, new Application.c12().m); - Expect.equals(87, new Application.c14().m); //# issue38304: continued + Expect.equals(87, new Application.c14().m); Expect.equals(87, new Application.c15().m); - - // Don't make constructors const if mixin declares instance variable. - const Application.c4(42); //# 00: compile-time error - const Application.c5(42); //# 01: compile-time error - const Application.c6(x: 42); //# 02: compile-time error - const Application.c7(42); //# 03: compile-time error - const Application.c8(42); //# 04: compile-time error - const Application.c9(x: 42); //# 05: compile-time error - const Application.c10(42); //# 06: compile-time error - const Application.c11(42); //# 07: compile-time error - const Application.c12(x: 42); //# 08: compile-time error - const Application.c13(42); //# 09: compile-time error - const Application.c14(42); //# 10: compile-time error - const Application.c15(x: 42); //# 11: compile-time error - - // Only insert forwarders for generative constructors. - new Application(); //# 12: compile-time error } diff --git a/tests/language/mixin_constructor_forwarding/optional_named_parameters_error_test.dart b/tests/language/mixin_constructor_forwarding/optional_named_parameters_error_test.dart new file mode 100644 index 00000000000..02fd118d617 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/optional_named_parameters_error_test.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import "optional_named_parameters_test.dart" show Application; + +main() { + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_error_test.dart b/tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_error_test.dart new file mode 100644 index 00000000000..213921c5a43 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_error_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "optional_named_parameters_legacy_test.dart" show Application; + +main() { + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_test.dart b/tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_test.dart new file mode 100644 index 00000000000..5ef132037be --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/optional_named_parameters_legacy_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; + +abstract class Mixin { + int get x; + int get m => x; +} + +class Base { + final int x; + Base.c1(this.x); + Base.c2({this.x = 37}); + Base.c3(int x) : this.c1(x); + Base.c4({int x = 37}) : this.c1(x); + Base.c5(int x) : this.c2(x: x); + Base.c6({int x = 37}) : this.c2(x: x); + factory Base() = Base.c2; +} + +class Application = Base with Mixin; + +main() { + Expect.equals(42, new Application.c1(42).m); + Expect.equals(42, new Application.c2(x: 42).m); + Expect.equals(42, new Application.c3(42).m); + Expect.equals(42, new Application.c4(x: 42).m); + Expect.equals(42, new Application.c5(42).m); + Expect.equals(42, new Application.c6(x: 42).m); + Expect.equals(37, new Application.c2().m); + Expect.equals(37, new Application.c4().m); + Expect.equals(37, new Application.c6().m); +} diff --git a/tests/language/mixin_constructor_forwarding/optional_named_parameters_test.dart b/tests/language/mixin_constructor_forwarding/optional_named_parameters_test.dart index 722fbb1febf..ef159d6f727 100644 --- a/tests/language/mixin_constructor_forwarding/optional_named_parameters_test.dart +++ b/tests/language/mixin_constructor_forwarding/optional_named_parameters_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin { +mixin Mixin { int get x; int get m => x; } @@ -36,7 +32,4 @@ main() { Expect.equals(37, new Application.c2().m); Expect.equals(37, new Application.c4().m); Expect.equals(37, new Application.c6().m); - - // Only insert forwarders for generative constructors. - new Application(); //# 01: compile-time error } diff --git a/tests/language/mixin_constructor_forwarding/optional_positional_parameters_error_test.dart b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_error_test.dart new file mode 100644 index 00000000000..61d742aaa7e --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_error_test.dart @@ -0,0 +1,12 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import "optional_positional_parameters_test.dart" show Application; +main() { + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_error_test.dart b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_error_test.dart new file mode 100644 index 00000000000..bee46ef58f2 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_error_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "optional_positional_parameters_legacy_test.dart" show Application; + +main() { + // Only insert forwarders for generative constructors. + new Application(); + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT + // [cfe] Couldn't find constructor 'Application'. +} diff --git a/tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_test.dart b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_test.dart new file mode 100644 index 00000000000..37dd14b1da3 --- /dev/null +++ b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_legacy_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; + +abstract class Mixin { + int get x; + int get m => x; +} + +class Base { + final int x; + Base.c1(this.x); + Base.c2([this.x = 37]); + Base.c3(int x) : this.c1(x); + Base.c4([int x = 37]) : this.c1(x); + Base.c5(int x) : this.c2(x); + Base.c6([int x = 37]) : this.c2(x); + factory Base() = Base.c2; +} + +class Application = Base with Mixin; + +main() { + Expect.equals(42, new Application.c1(42).m); + Expect.equals(42, new Application.c2(42).m); + Expect.equals(42, new Application.c3(42).m); + Expect.equals(42, new Application.c4(42).m); + Expect.equals(42, new Application.c5(42).m); + Expect.equals(42, new Application.c6(42).m); + Expect.equals(37, new Application.c2().m); + Expect.equals(37, new Application.c4().m); + Expect.equals(37, new Application.c6().m); +} diff --git a/tests/language/mixin_constructor_forwarding/optional_positional_parameters_test.dart b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_test.dart index 96212659252..416fe26695f 100644 --- a/tests/language/mixin_constructor_forwarding/optional_positional_parameters_test.dart +++ b/tests/language/mixin_constructor_forwarding/optional_positional_parameters_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -abstract class Mixin { +mixin Mixin { int get x; int get m => x; } @@ -36,7 +32,4 @@ main() { Expect.equals(37, new Application.c2().m); Expect.equals(37, new Application.c4().m); Expect.equals(37, new Application.c6().m); - - // Only insert forwarders for generative constructors. - new Application(); //# 01: compile-time error } diff --git a/tests/language/mixin_declaration/mixin_declaration_constructor_error_test.dart b/tests/language/mixin_declaration/mixin_declaration_constructor_error_test.dart new file mode 100644 index 00000000000..b5f86b9ea99 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_constructor_error_test.dart @@ -0,0 +1,99 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// A mixin declaration cannot declare any constructors, +// including factory constructors. +// A mixin class declaration cannot declare any non-factory, non-trivial +// constructors. + +class A {} + +class B implements M, N { + const B(); +} + +mixin M on A { + factory M.foo() => throw "uncalled"; + // [error column 3, length 7] + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. + const factory M.bar() = B; + // ^^^^^^^ + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. + M.baz(); + // [error column 3, length 1] + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. + M.qux() : this.baz(); + // [error column 3, length 1] + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. +} + +class MA extends A with M {} +// ^ +// [cfe] Can't use 'M' as a mixin because it has constructors. + +mixin class N { + // It's OK for a mixin derived from a class to have factory constructors + // and trivial non-redirecting generative constructors. + // (Trivial means: No initializer list, no body, no parameters. + // That is, anything which does anything, and can't be ignored.) + factory N.foo() => const B(); + const factory N.bar() = B; + const N.baz(); +} + +mixin class NE { + const NE.baz(); + // Not generative constructors that has initializer lists or bodies, + // or is forwarding. Anything that contains any user code. + + const NE.qux(): this.baz(); // Is forwarding. + // ^^ + // [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR + // [cfe] Can't use 'NE' as a mixin because it has constructors. + + NE.param(int i); + // [error column 3, length 2] + // [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR + // [cfe] Can't use 'NE' as a mixin because it has constructors. + + const NE.init() : assert(true, "has initializer list"); + // ^^ + // [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR + // [cfe] Can't use 'NE' as a mixin because it has constructors. + + external NE.ext(); + // ^^ + // [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR + // [cfe] Can't use 'NE' as a mixin because it has constructors. + + NE.body() { + // [error column 3, length 2] + // [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR + // [cfe] Can't use 'NE' as a mixin because it has constructors. + print("Did something"); + } +} + +class NA = A with N; +class NAE = A with NE; + +main() { + // Constructors of mixin are not inherited by application. + NA.foo(); + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD + // [cfe] Member not found: 'NA.foo'. + NA.bar(); + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD + // [cfe] Member not found: 'NA.bar'. + NA.baz(); + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD + // [cfe] Member not found: 'NA.baz'. +} diff --git a/tests/language/mixin_declaration/mixin_declaration_constructor_legacy_error_test.dart b/tests/language/mixin_declaration/mixin_declaration_constructor_legacy_error_test.dart new file mode 100644 index 00000000000..b64a84fbc42 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_constructor_legacy_error_test.dart @@ -0,0 +1,66 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +// A class declaration cannot declare any non-factory constructors +// and be used as a mixin. +// A mixin declaration cannot declare any constructors. + +class A {} + +class B implements M, C1, C2, C3 { + const B(); +} + +mixin M on A { + factory M.foo() => throw "uncalled"; + // [error column 3, length 7] + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. + const factory M.bar() = B; + // ^^^^^^^ + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. + M.baz(); + // [error column 3, length 1] + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. + M.qux() : this.baz(); + // [error column 3, length 1] + // [analyzer] SYNTACTIC_ERROR.MIXIN_DECLARES_CONSTRUCTOR + // [cfe] Mixins can't declare constructors. +} + +// In Dart 3.0, it's OK for a mixin class to have factory constructors +// and trivial non-redirecting generative constructors. +// (Trivial means: No initializer list, no body, no parameters. +// That is, anything which does anything, and can't be ignored.) +// Not so for classes used as mixins in <3.0. + +// (Cannot test a class with *only* a redirecting generative constructor, +// it also needs a constructor to redirect to.) +class C1 { + factory C1.foo() => const B(); // Factory constructor is OK. +} + +class C2 { + const factory C2.bar() = B; // Redirecting factory constructor is OK. +} + +// Generative constructor means cannot be used as mixin. +class C3 { + const C3.baz(); // Trivial generative constructor is not OK. +} + +class AC1 = A with C1; +class AC2 = A with C2; +class AC3 = A with C3; +// ^ +// [cfe] Can't use 'C3' as a mixin because it has constructors. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR + +main() {} diff --git a/tests/language/mixin_declaration/mixin_declaration_factory_test.dart b/tests/language/mixin_declaration/mixin_declaration_factory_test.dart index 332c5d17de8..c23959a61ac 100644 --- a/tests/language/mixin_declaration/mixin_declaration_factory_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_factory_test.dart @@ -2,35 +2,40 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 +// A mixin class declaration *can* declare factory and trivial generative +// constructors. -// A mixin declaration cannot declare any (factory) constructors. +import "package:expect/expect.dart"; -class A {} +class A { + const A(); + const A.baz(); +} -class B implements A { +class B implements N { const B(); } -mixin M on A { - factory M.foo() => throw "uncalled"; //# 01: compile-time error - const factory M.bar() = B; //# 02: compile-time error - M.baz(); //# 03: compile-time error +mixin class N { + // It's OK for a mixin derived from a class to have factory constructors + // and trivial constructors. + // (Trivial means: No initializer list, no body, no parameters, and not + // forwarding.) + factory N.foo() => const B(); + const factory N.bar() = B; + N.baz(); } -class MA extends A with M {} - -class N { - // It's OK for a mixin derived from a class to have factory constructors. - factory N.quux() => throw "uncalled"; //# none: ok - N.bar(); //# 04: compile-time error -} - -class NA extends A with N {} +// Used as mixin. +class NA = A with N; main() { - new MA(); - new NA(); + // Constructors on `N` can be used directly. + Expect.identical(const B(), N.foo()); + const N bar = N.bar(); + N n = N.baz(); + + // Constructors from `A` inherited by `NA`. + NA na = const NA(); // Inherited from A. + na = const NA.baz(); // Inherited from A, not shadowed by N. } diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_legacy_test.dart new file mode 100644 index 00000000000..6b0f3e03743 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class B00 extends Object with I, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new B00()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_test.dart index 02a2c77a839..5d207bee112 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B00_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} class C1 implements I {} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_legacy_test.dart new file mode 100644 index 00000000000..8bdffc89370 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class B01 extends Object with C1, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new B01()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_test.dart index 85ad4dba084..fe9945edc19 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B01_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} -class C1 implements I {} +mixin class C1 implements I {} mixin M0 on I { } diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_legacy_test.dart new file mode 100644 index 00000000000..edd18965439 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class B10 extends Object with I, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new B10()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_test.dart index 275ddda38be..59236b24df5 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B10_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} class C1 implements I {} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_legacy_test.dart new file mode 100644 index 00000000000..55e864cb300 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class B11 extends Object with C1, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new B11()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_test.dart index 989a2b65dd5..cc8081067ec 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_B11_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} -class C1 implements I {} +mixin class C1 implements I {} mixin M0 on I { } diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_legacy_test.dart new file mode 100644 index 00000000000..bd409cd9571 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class C00 with I, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new C00()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_test.dart index 40ab1fa2b68..ff31149bad3 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C00_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} class C1 implements I {} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_legacy_test.dart new file mode 100644 index 00000000000..01780b5ffca --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class C01 with C1, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new C01()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_test.dart index d48c73485fa..8158ea9e56d 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C01_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} -class C1 implements I {} +mixin class C1 implements I {} mixin M0 on I { } diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_legacy_test.dart new file mode 100644 index 00000000000..40c784bc88f --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class C02 with I, M0, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new C02()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_test.dart index f2977e48785..73d522dc23e 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C02_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} class C1 implements I {} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_legacy_test.dart new file mode 100644 index 00000000000..e82280401bb --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class C10 with I, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new C10()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_test.dart index d847bd12eff..427c59b8f0a 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C10_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} class C1 implements I {} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_legacy_test.dart new file mode 100644 index 00000000000..a6d64264397 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class C11 with C1, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new C11()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_test.dart index 4bc07f9eb4b..6bb5f595491 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C11_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} -class C1 implements I {} +mixin class C1 implements I {} mixin M0 on I { } diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_legacy_test.dart new file mode 100644 index 00000000000..a1b1017d327 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_legacy_test.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +// M1 is inferred as M1 +class C12 with I, M0, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +void main() { + Expect.type>(new C12()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_test.dart index 5c237be6e49..2a67c30c1b5 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_C12_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; -class I {} +mixin class I {} class C0 extends I {} class C1 implements I {} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_legacy_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_legacy_test.dart new file mode 100644 index 00000000000..cc918da2e92 --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_legacy_test.dart @@ -0,0 +1,448 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +/////////////////////////////////////////////////////// +// Tests for inference of type arguments to mixins in +// class definition mixin applications of the form +// `class Foo = A with M` +/////////////////////////////////////////////////////// + +class I {} + +class C0 extends I {} +class C1 implements I {} + +mixin M0 on I { +} + +mixin M1 on I { + T Function(T) get value => (param) => param; +} + +mixin M2 implements I {} + +mixin M3 on I {} + +class J {} +class C2 extends C1 implements J {} +class C3 extends J {} + +mixin M4 on I, J { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +/////////////////////////////////////////////////////// +// Inference of a single mixin from a super class works +/////////////////////////////////////////////////////// + +mixin A00Mixin on M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class A00 = I with M1, A00Mixin; + +mixin A01Mixin on M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class A01 = C0 with M1, A01Mixin; + +mixin A02Mixin on M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class A02 = C1 with M1, A02Mixin; + +/////////////////////////////////////////////////////// +// Inference of a single mixin from another mixin works +/////////////////////////////////////////////////////// + +mixin B00Mixin on M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B00 = Object with I, M1, B00Mixin; + +mixin B01Mixin on M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B01 = Object with C1, M1, B01Mixin; + +mixin B02Mixin on M0, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B02 = I with M0, M1, B02Mixin; + +mixin B03Mixin on M2, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B03 = Object with M2, M1, B03Mixin; + +/////////////////////////////////////////////////////// +// Inference of a single mixin from another mixin works +// with the shorthand syntax +/////////////////////////////////////////////////////// + +mixin C00Mixin on M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C00 = Object with I, M1, C00Mixin; + +mixin C01Mixin on C1, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C01 = Object with C1, M1, C01Mixin; + +mixin C02Mixin on M0, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C02 = Object with I, M0, M1, C02Mixin; + +mixin C03Mixin on M2, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C03 = Object with M2, M1, C03Mixin; + +/////////////////////////////////////////////////////// +// Inference of two mixins from a super class works +/////////////////////////////////////////////////////// + +mixin A10Mixin on M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class A10 = I with M3, M1, A10Mixin; + +mixin A11Mixin on C0, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class A11 = C0 with M3, M1, A11Mixin; + +mixin A12Mixin on C1, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class A12 = C1 with M3, M1, A12Mixin; + +/////////////////////////////////////////////////////// +// Inference of two mixins from another mixin works +/////////////////////////////////////////////////////// + +mixin B10Mixin on I, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B10 = Object with I, M3, M1, B10Mixin; + +mixin B11Mixin on C1, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B11 = Object with C1, M3, M1, B11Mixin; + +mixin B12Mixin on I, M0, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B12 = I with M0, M3, M1, B12Mixin; + +mixin B13Mixin on M2, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class B13 = Object with M2, M3, M1, B13Mixin; + +/////////////////////////////////////////////////////// +// Inference of a single mixin from another mixin works +// with the shorthand syntax +/////////////////////////////////////////////////////// + +mixin C10Mixin on I, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C10 = Object with I, M3, M1, C10Mixin; + +mixin C11Mixin on C1, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C11 = Object with C1, M3, M1, C11Mixin; + +mixin C12Mixin on I, M0, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C12 = Object with I, M0, M3, M1, C12Mixin; + +mixin C13Mixin on M2, M3, M1 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + } +} + +// M1 is inferred as M1 +class C13 = Object with M2, M3, M1, C13Mixin; + + +/////////////////////////////////////////////////////// +// Inference from multiple constraints works +/////////////////////////////////////////////////////// + + +mixin A20Mixin on C2, M4 { + void check() { + // Verify that M4.S is exactly int + int Function(int) f0 = this.value0; + // Verify that M4.T is exactly double + double Function(double) f1 = this.value1; + } +} + +// M4 is inferred as M4 +class A20 = C2 with M4, A20Mixin; + +mixin A21Mixin on C3, M2, M4 { + void check() { + // Verify that M4.S is exactly int + int Function(int) f0 = this.value0; + // Verify that M4.T is exactly double + double Function(double) f1 = this.value1; + } +} + +// M4 is inferred as M4 +class A21 = C3 with M2, M4, A21Mixin; + +mixin A22Mixin on C2, M1, M4 { + void check() { + // Verify that M1.T is exactly int + int Function(int) f = this.value; + // Verify that M4.S is exactly int + int Function(int) f0 = this.value0; + // Verify that M4.T is exactly double + double Function(double) f1 = this.value1; + } +} + +// M4 is inferred as M4 +class A22 = C2 with M1, M4, A22Mixin; + +mixin _M5 on I implements J {} + +// Inference here puts J in the superclass hierarchy +class _A23 extends C0 with _M5 {} + +mixin A23Mixin on _A23, M4 { + void check() { + // Verify that M4.S is exactly int + int Function(int) f0 = this.value0; + // Verify that M4.T is exactly int + int Function(int) f1 = this.value1; + } +} + +// Inference here should get J for M4.T +// if inference for _A23 is done first (correctly) +// and otherwise J +class A23 = _A23 with M4, A23Mixin; + +/////////////////////////////////////////////////////// +// Unconstrained parameters go to bounds +/////////////////////////////////////////////////////// + +mixin M5 on I { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +mixin M6 on I { + S Function(S) get value0 => (param) => param; + T Function(T) get value1 => (param) => param; +} + +mixin A30Mixin on C0, M5 { + void check() { + // Verify that M5.S is exactly int + int Function(int) f0 = this.value0; + // Verify that M5.T is exactly String + String Function(String) f1 = this.value1; + } +} + +// M5 is inferred as M5 +class A30 = C0 with M5, A30Mixin; + +mixin A31Mixin on C0, M6 { + void check() { + // Verify that M6.S is exactly int + int Function(int) f0 = this.value0; + // Verify that M6.T is exactly int + int Function(int) f1 = this.value1; + } +} + +// M6 is inferred as M6 +class A31 = C0 with M6, A31Mixin; + +/////////////////////////////////////////////////////// +// Non-trivial constraints should work +/////////////////////////////////////////////////////// + +mixin M7 on I> { + T Function(T) get value0 => (param) => param; +} + +class A40 extends I> {} + +class A41 extends A40> {} + +mixin A42Mixin on A41, M7> { + void check() { + // Verify that M7.T is exactly Map + Map Function(Map) f1 = this.value0; + } +} + +// M7 is inferred as M7> +class A42 = A41 with M7, A42Mixin; + +void main() { + Expect.type>(new A00()..check()); + Expect.type>(new A01()..check()); + Expect.type>(new A02()..check()); + + Expect.type>(new B00()..check()); + Expect.type>(new B01()..check()); + Expect.type>(new B02()..check()); + Expect.type>(new B03()..check()); + + Expect.type>(new C00()..check()); + Expect.type>(new C01()..check()); + Expect.type>(new C02()..check()); + Expect.type>(new C03()..check()); + + Expect.type>(new A10()..check()); + Expect.type>(new A11()..check()); + Expect.type>(new A12()..check()); + + Expect.type>(new B10()..check()); + Expect.type>(new B11()..check()); + Expect.type>(new B12()..check()); + Expect.type>(new B13()..check()); + + Expect.type>(new C10()..check()); + Expect.type>(new C11()..check()); + Expect.type>(new C12()..check()); + Expect.type>(new C13()..check()); + + Expect.type>(new A20()..check()); + Expect.type>(new A21()..check()); + Expect.type>(new A22()..check()); + Expect.type>(new A22()..check()); + Expect.type>(new A23()..check()); + + Expect.type>(new A30()..check()); + Expect.type>(new A31()..check()); + + Expect.type>>(new A42()..check()); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_test.dart b/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_test.dart index c6141420710..fe169379bab 100644 --- a/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_inference_valid_mixin_applications_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; /////////////////////////////////////////////////////// @@ -14,10 +10,10 @@ import "package:expect/expect.dart"; // `class Foo = A with M` /////////////////////////////////////////////////////// -class I {} +mixin class I {} class C0 extends I {} -class C1 implements I {} +mixin class C1 implements I {} mixin M0 on I { } diff --git a/tests/language/mixin_declaration/mixin_declaration_invalid_override_legacy_error_test.dart b/tests/language/mixin_declaration/mixin_declaration_invalid_override_legacy_error_test.dart new file mode 100644 index 00000000000..8b5c8e9a52f --- /dev/null +++ b/tests/language/mixin_declaration/mixin_declaration_invalid_override_legacy_error_test.dart @@ -0,0 +1,81 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test behavior when using a class as a mixin. +// @dart=2.19 + +import "package:expect/expect.dart"; + +// Test various invalid super-constraints for mixin declarations. + +abstract class UnaryNum { + num foo(num x); +} + +// Overrides must still be valid, wrt. signatures and types. + +mixin M3 on UnaryNum { + // M3.foo is a valid override of UnaryNum.foo + num foo(num x) => super.foo(x) * 2; +} + +// Invalid signature override (overriding optional parameter with required). +class C3 implements UnaryNum { + // C3.foo is a valid override of UnaryNum.foo + num foo([num x = 17]) => x; +} + +// M3.foo is not a valid override for C3.foo. +class A3 extends C3 with M3 {} +// ^ +// [cfe] Applying the mixin 'M3' to 'C3' introduces an erroneous override of 'foo'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE + +// Invalid type override (overriding `int` return with `num` return). +class C4 implements UnaryNum { + // C4.foo is a valid override of UnaryNum.foo + int foo(num x) => x.toInt(); +} + +// M3.foo is not a valid override for C4.foo. +class A4 extends C4 with M3 {} +// ^ +// [cfe] Applying the mixin 'M3' to 'C4' introduces an erroneous override of 'foo'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE + +// It's not required to have an implementation of members which are not super- +// invoked, if the application class is abstract. +abstract class C5 { + num foo(num x); + num bar(num x); +} + +mixin M5 on C5 { + num baz(num x) => super.foo(x); +} + +abstract class C5Foo implements C5 { + num foo(num x) => x; +} + +abstract class C5Bar implements C5 { + num bar(num x) => x; +} + +// Valid abstract class, super-invocation of foo hits implementation, +// even if bar is still abstract. +abstract class A5Foo = C5Foo with M5; +// Invalid since super-invocation of foo does not hit concrete implementation. +abstract class _ = C5Bar with M5; +// ^^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_APPLICATION_NO_CONCRETE_SUPER_INVOKED_MEMBER +// [cfe] The class doesn't have a concrete implementation of the super-invoked member 'foo'. + +class A5FooConcrete = A5Foo with C5Bar; + +main() { + Expect.equals(42, A5FooConcrete().baz(42)); +} diff --git a/tests/language/mixin_declaration/mixin_declaration_invalid_override_test.dart b/tests/language/mixin_declaration/mixin_declaration_invalid_override_test.dart index eca336f48fe..a6c572c222a 100644 --- a/tests/language/mixin_declaration/mixin_declaration_invalid_override_test.dart +++ b/tests/language/mixin_declaration/mixin_declaration_invalid_override_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; // Test various invalid super-constraints for mixin declarations. @@ -27,9 +23,11 @@ class C3 implements UnaryNum { num foo([num x = 17]) => x; } // M3.foo is not a valid override for C3.foo. -class A3 extends C3 // - with M3 //# 06: compile-time error -{} +class A3 extends C3 with M3 {} +// ^ +// [cfe] Applying the mixin 'M3' to 'C3' introduces an erroneous override of 'foo'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE // Invalid type override (overriding `int` return with `num` return). class C4 implements UnaryNum { @@ -37,9 +35,11 @@ class C4 implements UnaryNum { int foo(num x) => x.toInt(); } // M3.foo is not a valid override for C4.foo. -class A4 extends C4 // - with M3 //# 07: compile-time error -{} +class A4 extends C4 with M3 {} +// ^ +// [cfe] Applying the mixin 'M3' to 'C4' introduces an erroneous override of 'foo'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE // It's not required to have an implementation of members which are not super- // invoked, if the application class is abstract. @@ -53,7 +53,7 @@ mixin M5 on C5 { abstract class C5Foo implements C5 { num foo(num x) => x; } -abstract class C5Bar implements C5 { +abstract mixin class C5Bar implements C5 { num bar(num x) => x; } @@ -61,10 +61,13 @@ abstract class C5Bar implements C5 { // even if bar is still abstract. abstract class A5Foo = C5Foo with M5; // Invalid since super-invocation of foo does not hit concrete implementation. -abstract class _ = C5Bar with M5; //# 08: compile-time error +abstract class _ = C5Bar with M5; +// ^^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_APPLICATION_NO_CONCRETE_SUPER_INVOKED_MEMBER +// [cfe] The class doesn't have a concrete implementation of the super-invoked member 'foo'. class A5FooConcrete = A5Foo with C5Bar; main() { Expect.equals(42, A5FooConcrete().baz(42)); -} \ No newline at end of file +} diff --git a/tests/language/mixin_legacy/super_bound_runtime_test.dart b/tests/language/mixin_legacy/super_bound_runtime_test.dart deleted file mode 100644 index c6ee2744013..00000000000 --- a/tests/language/mixin_legacy/super_bound_runtime_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// @dart=2.19 - -class M {} - -class N {} - -class S {} - -class MNA extends S> - with M, N, List> {} - -class MNA2 = S> with M, N, List>; - -main() { - new MNA(); - new MNA2(); - - // Type parameter U of M must extend type parameter V, but - // type argument num is not a subtype of int. - - // Type parameter U of M must extend type parameter V, but - // type argument num is not a subtype of int. -} diff --git a/tests/language/mixin_legacy/superclass_runtime_test.dart b/tests/language/mixin_legacy/superclass_runtime_test.dart deleted file mode 100644 index 8f1f17f7637..00000000000 --- a/tests/language/mixin_legacy/superclass_runtime_test.dart +++ /dev/null @@ -1,94 +0,0 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// @dart=2.19 - -class S0 {} - -class S1 extends Object {} - -class S2 extends S0 {} - -class M0 {} - -class M1 extends Object {} - -mixin M2 on M0 {} - -class C00 = S0 with M0; -class C01 = S0 with M1; - -class C03 = S0 with M0, M1; -class C04 = S0 with M0, M2; - -class C10 = S1 with M0; -class C11 = S1 with M1; - -class C13 = S1 with M0, M1; -class C14 = S1 with M0, M2; - -class C20 = S2 with M0; -class C21 = S2 with M1; - -class C23 = S2 with M0, M1; -class C24 = S2 with M0, M2; - -class D00 extends S0 with M0 {} - -class D01 extends S0 with M1 {} - -class D03 extends S0 with M0, M1 {} - -class D04 extends S0 with M0, M2 {} - -class D10 extends S1 with M0 {} - -class D11 extends S1 with M1 {} - -class D13 extends S1 with M0, M1 {} - -class D14 extends S1 with M0, M2 {} - -class D20 extends S2 with M0 {} - -class D21 extends S2 with M1 {} - -class D23 extends S2 with M0, M1 {} - -class D24 extends S2 with M0, M2 {} - -main() { - new C00(); - new C01(); - new C03(); - new C04(); - - new C10(); - new C11(); - new C13(); - new C14(); - - new C20(); - new C21(); - new C23(); - new C24(); - - new D00(); - new D01(); - new D03(); - new D04(); - - new D10(); - new D11(); - new D13(); - new D14(); - - new D20(); - new D21(); - new D23(); - new D24(); -} diff --git a/tests/language/nonfunction_type_aliases/usage_object_error_test.dart b/tests/language/nonfunction_type_aliases/usage_object_error_test.dart index ba852405b02..28576fc476b 100644 --- a/tests/language/nonfunction_type_aliases/usage_object_error_test.dart +++ b/tests/language/nonfunction_type_aliases/usage_object_error_test.dart @@ -2,55 +2,49 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 - - // Introduce an aliased type. typedef T = Object; // Use the aliased type. -abstract class C { +class C { T? v10; final T v12; C(): v12 = T(); C.name1(this.v10, this.v12); - factory C.name2(T arg1, T arg2) = C1.name1; -} - -class C1 implements C { - C1.name1(T arg1, T arg2); - noSuchMethod(Invocation invocation) => throw 0; + factory C.name2(T arg1, T arg2) = C.name1; } abstract class D2 extends C with T {} // ^ -// [analyzer] unspecified // [cfe] Can't use 'Object' as a mixin because it has constructors. +// ^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR +// [cfe] The class 'Object' can't be used as a mixin because it isn't a mixin class nor a mixin. abstract class D3 implements T {} // ^ -// [analyzer] unspecified // [cfe] 'Object' can't be used in both 'extends' and 'implements' clauses. +// ^ +// [analyzer] COMPILE_TIME_ERROR.IMPLEMENTS_SUPER_CLASS abstract class D4 = C with T; // ^ -// [analyzer] unspecified // [cfe] Can't use 'Object' as a mixin because it has constructors. +// ^ +// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR +// [cfe] The class 'Object' can't be used as a mixin because it isn't a mixin class nor a mixin. main() { T.named(); // ^^^^^ -// [analyzer] unspecified +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD // [cfe] Member not found: 'Object.named'. T.staticMethod(); // ^^^^^^^^^^^^ -// [analyzer] unspecified +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD // [cfe] A constructor invocation can't have type arguments after the constructor name. // [cfe] Member not found: 'Object.staticMethod'. } diff --git a/tests/language/nonfunction_type_aliases/usage_object_legacy_error_test.dart b/tests/language/nonfunction_type_aliases/usage_object_legacy_error_test.dart new file mode 100644 index 00000000000..ba852405b02 --- /dev/null +++ b/tests/language/nonfunction_type_aliases/usage_object_legacy_error_test.dart @@ -0,0 +1,56 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins +// being applied in this test should be "mixin", "mixin class" or the test +// should be left at 2.19. +// @dart=2.19 + + +// Introduce an aliased type. + +typedef T = Object; + +// Use the aliased type. + +abstract class C { + T? v10; + final T v12; + C(): v12 = T(); + C.name1(this.v10, this.v12); + factory C.name2(T arg1, T arg2) = C1.name1; +} + +class C1 implements C { + C1.name1(T arg1, T arg2); + noSuchMethod(Invocation invocation) => throw 0; +} + +abstract class D2 extends C with T {} +// ^ +// [analyzer] unspecified +// [cfe] Can't use 'Object' as a mixin because it has constructors. + +abstract class D3 implements T {} +// ^ +// [analyzer] unspecified +// [cfe] 'Object' can't be used in both 'extends' and 'implements' clauses. + +abstract class D4 = C with T; +// ^ +// [analyzer] unspecified +// [cfe] Can't use 'Object' as a mixin because it has constructors. + +main() { + T.named(); +// ^^^^^ +// [analyzer] unspecified +// [cfe] Member not found: 'Object.named'. + + T.staticMethod(); +// ^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] A constructor invocation can't have type arguments after the constructor name. +// [cfe] Member not found: 'Object.staticMethod'. +} diff --git a/tests/language/null/inherit_static_errors_legacy_test.dart b/tests/language/null/inherit_static_errors_legacy_test.dart new file mode 100644 index 00000000000..aae684ae5e8 --- /dev/null +++ b/tests/language/null/inherit_static_errors_legacy_test.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins +// being applied in this test should be "mixin", "mixin class" or the test +// should be left at 2.19. +// @dart=2.19 + +class BadExtends extends Null {} +// ^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] The superclass, 'Null', has no unnamed constructor that takes no arguments. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. + +class BadImplements implements Null {} +// ^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. + +class BadMixin extends Object with Null {} +// ^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. + +class BadMixin2 = Object with Null; +// ^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. diff --git a/tests/language/null/inherit_static_errors_test.dart b/tests/language/null/inherit_static_errors_test.dart index aae684ae5e8..4ba19d6fd6c 100644 --- a/tests/language/null/inherit_static_errors_test.dart +++ b/tests/language/null/inherit_static_errors_test.dart @@ -2,44 +2,40 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 - class BadExtends extends Null {} +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. +// [cfe] The superclass, 'Null', has no unnamed constructor that takes no arguments. // ^^^^ // [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE -// ^ -// [cfe] 'Null' is restricted and can't be extended or implemented. -// [cfe] The superclass, 'Null', has no unnamed constructor that takes no arguments. -// [cfe] Subtypes of deeply immutable classes must be deeply immutable. -// ^ // [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] The class 'Null' can't be extended outside of its library because it's a final class. class BadImplements implements Null {} +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. // ^^^^ // [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE -// ^ -// [cfe] 'Null' is restricted and can't be extended or implemented. -// [cfe] Subtypes of deeply immutable classes must be deeply immutable. -// ^ // [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] The class 'Null' can't be implemented outside of its library because it's a final class. class BadMixin extends Object with Null {} +// ^ +// [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] Subtypes of deeply immutable classes must be deeply immutable. +// [cfe] The type 'BadMixin' must be 'base', 'final' or 'sealed' because the supertype 'Null' is 'final'. // ^^^^ // [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE -// ^ -// [cfe] 'Null' is restricted and can't be extended or implemented. -// [cfe] Subtypes of deeply immutable classes must be deeply immutable. -// ^ // [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] The class 'Null' can't be used as a mixin because it isn't a mixin class nor a mixin. class BadMixin2 = Object with Null; -// ^^^^ -// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE // ^ // [cfe] 'Null' is restricted and can't be extended or implemented. // [cfe] Subtypes of deeply immutable classes must be deeply immutable. -// ^ +// ^^^^ +// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE // [cfe] 'Null' is restricted and can't be extended or implemented. +// [cfe] The class 'Null' can't be used as a mixin because it isn't a mixin class nor a mixin. diff --git a/tests/language/private/mixin_exception_throw_legacy_test.dart b/tests/language/private/mixin_exception_throw_legacy_test.dart new file mode 100644 index 00000000000..2a8e4c341e4 --- /dev/null +++ b/tests/language/private/mixin_exception_throw_legacy_test.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// Regression test for http://dartbug.com/11637 + +class _C {} + +class _E { + throwIt() => throw "it"; +} + +class _F { + throwIt() => throw "IT"; +} + +class _D extends _C with _E, _F {} + +main() { + var d = new _D(); + try { + d.throwIt(); + } catch (e, s) { + print("Exception: $e"); + print("Stacktrace:\n$s"); + } +} diff --git a/tests/language/private/mixin_exception_throw_test.dart b/tests/language/private/mixin_exception_throw_test.dart index 5ba1080f94d..341c51ea841 100644 --- a/tests/language/private/mixin_exception_throw_test.dart +++ b/tests/language/private/mixin_exception_throw_test.dart @@ -2,19 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Regression test for http://dartbug.com/11637 class _C {} -class _E { +mixin class _E { throwIt() => throw "it"; } -class _F { +mixin class _F { throwIt() => throw "IT"; } diff --git a/tests/language/private/other_mixin2.dart b/tests/language/private/other_mixin2.dart index 2295e85e5af..ff7d78fe753 100644 --- a/tests/language/private/other_mixin2.dart +++ b/tests/language/private/other_mixin2.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Dart test for testing access to private fields on mixins. library private_mixin2_other; -class C1 { +mixin class C1 { int _field = 42; } diff --git a/tests/language/regress/regress18713_legacy_test.dart b/tests/language/regress/regress18713_legacy_test.dart new file mode 100644 index 00000000000..9db2aa5da7e --- /dev/null +++ b/tests/language/regress/regress18713_legacy_test.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class T { + final Type tType = X; + Type get getTType => X; +} + +class S { + final Type sType = Y; + Type get getSType => Y; +} + +class TS = T with S; + +@pragma('dart2js:noInline') +@pragma('dart2js:assumeDynamic') +dyn(x) => x; + +main() { + var ts = new TS(); + + Expect.equals("String", ts.sType.toString()); + Expect.equals("int", ts.tType.toString()); + Expect.equals("String", ts.getSType.toString()); + Expect.equals("int", ts.getTType.toString()); + + Expect.equals("String", dyn(ts).sType.toString()); + Expect.equals("int", dyn(ts).tType.toString()); + Expect.equals("String", dyn(ts).getSType.toString()); + Expect.equals("int", dyn(ts).getTType.toString()); +} diff --git a/tests/language/regress/regress18713_test.dart b/tests/language/regress/regress18713_test.dart index c1f593ee9f9..d835016b165 100644 --- a/tests/language/regress/regress18713_test.dart +++ b/tests/language/regress/regress18713_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class T { @@ -13,7 +9,7 @@ class T { Type get getTType => X; } -class S { +mixin S { final Type sType = Y; Type get getSType => Y; } diff --git a/tests/language/regress/regress22666_test.dart b/tests/language/regress/regress22666_test.dart deleted file mode 100644 index 91f02deee60..00000000000 --- a/tests/language/regress/regress22666_test.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 - -import 'dart:collection'; - -class A extends Object with LinkedListEntry {} - -main() => new A(); diff --git a/tests/language/regress/regress23914_test.dart b/tests/language/regress/regress23914_test.dart deleted file mode 100644 index 3c1aab0239e..00000000000 --- a/tests/language/regress/regress23914_test.dart +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(https://github.com/dart-lang/sdk/issues/51557): Decide if the mixins -// being applied in this test should be "mixin", "mixin class" or the test -// should be left at 2.19. -// @dart=2.19 - -import 'dart:collection'; - -class C extends LinkedListEntry {} - -main() { - var ll = new LinkedList(); - var a = new List.unmodifiable(ll); -} diff --git a/tests/language/regress/regress26230_legacy_test.dart b/tests/language/regress/regress26230_legacy_test.dart new file mode 100644 index 00000000000..2678b3ea6d2 --- /dev/null +++ b/tests/language/regress/regress26230_legacy_test.dart @@ -0,0 +1,50 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +class _RenderTabBar extends RenderBox + with + ContainerRenderObjectMixin, + RenderBoxContainerDefaultsMixin {} + +class RenderObject {} + +class RenderSector extends RenderObject {} + +class RenderBox extends RenderObject {} + +class ParentData {} + +class BoxParentData extends ParentData {} + +class SectorParentData extends ParentData {} + +class ContainerParentDataMixin {} + +class ContainerRenderObjectMixin> {} + +class SectorChildListParentData extends SectorParentData + with ContainerParentDataMixin {} + +class RenderDecoratedSector extends RenderSector {} + +class RenderSectorWithChildren extends RenderDecoratedSector + with ContainerRenderObjectMixin {} + +class ContainerBoxParentDataMixin + extends BoxParentData with ContainerParentDataMixin {} + +class RenderBoxContainerDefaultsMixin> + implements ContainerRenderObjectMixin {} + +class FlexParentData extends ContainerBoxParentDataMixin {} + +class _TabBarParentData extends ContainerBoxParentDataMixin {} + +main() { + new _RenderTabBar(); +} diff --git a/tests/language/regress/regress26230_test.dart b/tests/language/regress/regress26230_test.dart index 390a8b8c331..3433f963438 100644 --- a/tests/language/regress/regress26230_test.dart +++ b/tests/language/regress/regress26230_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - class _RenderTabBar extends RenderBox with ContainerRenderObjectMixin, @@ -23,9 +19,9 @@ class BoxParentData extends ParentData {} class SectorParentData extends ParentData {} -class ContainerParentDataMixin {} +mixin class ContainerParentDataMixin {} -class ContainerRenderObjectMixin> {} class SectorChildListParentData extends SectorParentData @@ -39,7 +35,7 @@ class RenderSectorWithChildren extends RenderDecoratedSector class ContainerBoxParentDataMixin extends BoxParentData with ContainerParentDataMixin {} -class RenderBoxContainerDefaultsMixin> implements ContainerRenderObjectMixin {} diff --git a/tests/language/regress/regress27957_legacy_test.dart b/tests/language/regress/regress27957_legacy_test.dart new file mode 100644 index 00000000000..d751002347b --- /dev/null +++ b/tests/language/regress/regress27957_legacy_test.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; +import 'regress27957_lib1.dart' as s1; +import 'regress27957_lib2.dart' as s2; + +class Mixin {} + +class C1 = s1.Superclass with Mixin; +class C2 = s2.Superclass with Mixin; + +main() { + var c1 = new C1(), c2 = new C2(); + Expect.equals(1, c1.m()); + Expect.equals(2, c2.m()); +} diff --git a/tests/language/regress/regress27957_test.dart b/tests/language/regress/regress27957_test.dart index 75a6147a505..e2b7f3c5216 100644 --- a/tests/language/regress/regress27957_test.dart +++ b/tests/language/regress/regress27957_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; import 'regress27957_lib1.dart' as s1; import 'regress27957_lib2.dart' as s2; -class Mixin {} +mixin Mixin {} class C1 = s1.Superclass with Mixin; class C2 = s2.Superclass with Mixin; diff --git a/tests/language/regress/regress29949_legacy_test.dart b/tests/language/regress/regress29949_legacy_test.dart new file mode 100644 index 00000000000..7d0466c30bc --- /dev/null +++ b/tests/language/regress/regress29949_legacy_test.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +abstract class S {} + +abstract class M {} + +abstract class N {} + +class C extends S with M>, N> {} + +main() { + new C(); +} diff --git a/tests/language/regress/regress29949_test.dart b/tests/language/regress/regress29949_test.dart index 8c28f5b58a2..0a30c738ad2 100644 --- a/tests/language/regress/regress29949_test.dart +++ b/tests/language/regress/regress29949_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - abstract class S {} -abstract class M {} +mixin M {} -abstract class N {} +mixin N {} class C extends S with M>, N> {} diff --git a/tests/language/regress/regress30669_legacy_test.dart b/tests/language/regress/regress30669_legacy_test.dart new file mode 100644 index 00000000000..4857e83ce19 --- /dev/null +++ b/tests/language/regress/regress30669_legacy_test.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import 'package:expect/expect.dart'; +import 'package:expect/variations.dart'; + +class M { + int compareTo(int x) { + return x.isEven ? 37 : -37; + } +} + +// All of these should work the same for the purposes of calling through +// the Comparable interface. + +class C extends M implements Comparable {} + +class D extends Object with M implements Comparable {} + +class E = Object with M implements Comparable; + +/// Regression test for https://github.com/dart-lang/sdk/issues/30669, DDC was +/// not attaching the "extension member" symbol to call `Comparable.compareTo` in +/// some cases. +main() { + testComparable(new C()); + testComparable(new D()); + testComparable(new E()); +} + +testComparable(Comparable c) { + Expect.equals(c.compareTo(42), 37, '$c'); + Expect.equals(c.compareTo(41), -37, '$c'); + if (checkedParameters) { + Expect.throws(() => print(c.compareTo("42"))); + } +} diff --git a/tests/language/regress/regress30669_test.dart b/tests/language/regress/regress30669_test.dart index 347313f3745..aaf2c1714b2 100644 --- a/tests/language/regress/regress30669_test.dart +++ b/tests/language/regress/regress30669_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import 'package:expect/expect.dart'; -class M { +mixin class M { int compareTo(int x) => x.isEven ? 1 : -1; } diff --git a/tests/language/regress/regress32267_legacy_test.dart b/tests/language/regress/regress32267_legacy_test.dart new file mode 100644 index 00000000000..c8c008c86e8 --- /dev/null +++ b/tests/language/regress/regress32267_legacy_test.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// There was a bug in the Kernel mixin transformation: it copied factory +// constructors from the mixin into the mixin application class. This could be +// observed as an unbound type parameter which led to a crash. + +class State {} + +class A {} + +abstract class Mixin { + factory Mixin._() => throw "uncalled"; +} + +class AState extends State {} + +class AStateImpl extends AState with Mixin {} + +void main() { + new AStateImpl(); +} diff --git a/tests/language/regress/regress32267_test.dart b/tests/language/regress/regress32267_test.dart index bca28ba3635..3359bb9d1d1 100644 --- a/tests/language/regress/regress32267_test.dart +++ b/tests/language/regress/regress32267_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // There was a bug in the Kernel mixin transformation: it copied factory // constructors from the mixin into the mixin application class. This could be // observed as an unbound type parameter which led to a crash. @@ -14,7 +10,7 @@ class State {} class A {} -abstract class Mixin { +abstract mixin class Mixin { factory Mixin._() => throw "uncalled"; } diff --git a/tests/language/regress/regress32353_legacy_test.dart b/tests/language/regress/regress32353_legacy_test.dart new file mode 100644 index 00000000000..46b5ef4e7f2 --- /dev/null +++ b/tests/language/regress/regress32353_legacy_test.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class io_FileSystemEntity {} + +class io_Directory extends io_FileSystemEntity {} + +class _LocalDirectory + extends _LocalFileSystemEntity<_LocalDirectory, io_Directory> + with ForwardingDirectory, DirectoryAddOnsMixin { + noSuchMethod(invocation) => null; +} + +abstract class _LocalFileSystemEntity extends ForwardingFileSystemEntity {} + +abstract class FileSystemEntity implements io_FileSystemEntity {} + +abstract class ForwardingFileSystemEntity implements FileSystemEntity {} + +mixin ForwardingDirectory + on ForwardingFileSystemEntity implements Directory { + get t => T; +} + +abstract class Directory implements FileSystemEntity, io_Directory {} + +abstract class DirectoryAddOnsMixin implements Directory {} + +main() { + var x = new _LocalDirectory(); + Expect.equals(x.t, _LocalDirectory); +} diff --git a/tests/language/regress/regress32353_test.dart b/tests/language/regress/regress32353_test.dart index 3cdeacd093a..5117c5080b5 100644 --- a/tests/language/regress/regress32353_test.dart +++ b/tests/language/regress/regress32353_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class io_FileSystemEntity {} @@ -33,9 +29,9 @@ mixin ForwardingDirectory abstract class Directory implements FileSystemEntity, io_Directory {} -abstract class DirectoryAddOnsMixin implements Directory {} +mixin DirectoryAddOnsMixin implements Directory {} -main() { +void main() { var x = new _LocalDirectory(); Expect.equals(x.t, _LocalDirectory); } diff --git a/tests/language/regress/regress32372_legacy_test.dart b/tests/language/regress/regress32372_legacy_test.dart new file mode 100644 index 00000000000..d902c1a0ec9 --- /dev/null +++ b/tests/language/regress/regress32372_legacy_test.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import "package:expect/expect.dart"; + +class A extends Object with B, C {} + +class B {} + +mixin C on B { + get t => T; +} + +main() { + var x = new A(); + Expect.equals(x.t, String); +} diff --git a/tests/language/regress/regress32372_test.dart b/tests/language/regress/regress32372_test.dart index dc466234140..3b23d29a32b 100644 --- a/tests/language/regress/regress32372_test.dart +++ b/tests/language/regress/regress32372_test.dart @@ -2,15 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import "package:expect/expect.dart"; class A extends Object with B, C {} -class B {} +mixin B {} mixin C on B { get t => T; diff --git a/tests/language/regress/regress34235_runtime_test.dart b/tests/language/regress/regress34235_legacy_test.dart similarity index 67% rename from tests/language/regress/regress34235_runtime_test.dart rename to tests/language/regress/regress34235_legacy_test.dart index 71584f54e19..48bec5a8deb 100644 --- a/tests/language/regress/regress34235_runtime_test.dart +++ b/tests/language/regress/regress34235_legacy_test.dart @@ -1,12 +1,7 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. // @dart=2.19 class Base { @@ -16,7 +11,7 @@ class Base { class M1 { void foo( // Prevent formatter from joining the line below to the one above - + {x} ) {} } @@ -27,6 +22,10 @@ class M2 { } class Derived extends BaseWithM1 with M2 {} +// ^^^^^^^ +// [cfe] Applying the mixin 'M2' to 'BaseWithM1' introduces an erroneous override of 'foo'. +// ^^ +// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE main() { new Derived().foo(); diff --git a/tests/language/regress/regress34235_test.dart b/tests/language/regress/regress34235_test.dart index 89d3da27677..32b91717c86 100644 --- a/tests/language/regress/regress34235_test.dart +++ b/tests/language/regress/regress34235_test.dart @@ -2,24 +2,17 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - class Base { void foo() {} } -class M1 { - void foo( - // Prevent formatter from joining the line below to the one above - {x} - ) {} +mixin M1 { + void foo({x}) {} } class BaseWithM1 = Base with M1; -class M2 { +mixin M2 { void foo() {} } diff --git a/tests/language/regress/regress34488_legacy_test.dart b/tests/language/regress/regress34488_legacy_test.dart new file mode 100644 index 00000000000..54a4064f819 --- /dev/null +++ b/tests/language/regress/regress34488_legacy_test.dart @@ -0,0 +1,52 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +abstract class Base { + void f(int i); + void g([int i]); + void h({int i}); +} + +abstract class Mixin implements Base {} + +class Derived extends Object with Mixin { + // Type `(int) -> void` should be inherited from `Base` + f(i) {} + + // Type `([int]) -> void` should be inherited from `Base` + g([i = -1]) {} + + // Type `({h: int}) -> void` should be inherited from `Base` + h({i = -1}) {} +} + +main() { + var d = new Derived(); + d.f('bad'); + // ^^^^^ + // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE + // [cfe] The argument type 'String' can't be assigned to the parameter type 'int'. + d.g('bad'); + // ^^^^^ + // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE + // [cfe] The argument type 'String' can't be assigned to the parameter type 'int'. + d.h(i: 'bad'); + // ^^^^^ + // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE + // [cfe] The argument type 'String' can't be assigned to the parameter type 'int'. + Object x = d.f(1); + // ^ + // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT + // [cfe] This expression has type 'void' and can't be used. + Object y = d.g(1); + // ^ + // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT + // [cfe] This expression has type 'void' and can't be used. + Object z = d.h(i: 1); + // ^ + // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT + // [cfe] This expression has type 'void' and can't be used. +} diff --git a/tests/language/regress/regress34488_test.dart b/tests/language/regress/regress34488_test.dart index 2e6e4b6323c..126081d603b 100644 --- a/tests/language/regress/regress34488_test.dart +++ b/tests/language/regress/regress34488_test.dart @@ -2,9 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 +import "package:expect/static_type_helper.dart"; abstract class Base { void f(int i); @@ -12,7 +10,7 @@ abstract class Base { void h({int i}); } -abstract class Mixin implements Base {} +mixin Mixin implements Base {} class Derived extends Object with Mixin { // Type `(int) -> void` should be inherited from `Base` @@ -27,28 +25,7 @@ class Derived extends Object with Mixin { main() { var d = new Derived(); - d.f('bad'); - // ^^^^^ - // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE - // [cfe] The argument type 'String' can't be assigned to the parameter type 'int'. - d.g('bad'); - // ^^^^^ - // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE - // [cfe] The argument type 'String' can't be assigned to the parameter type 'int'. - d.h(i: 'bad'); - // ^^^^^ - // [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE - // [cfe] The argument type 'String' can't be assigned to the parameter type 'int'. - Object x = d.f(1); - // ^ - // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT - // [cfe] This expression has type 'void' and can't be used. - Object y = d.g(1); - // ^ - // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT - // [cfe] This expression has type 'void' and can't be used. - Object z = d.h(i: 1); - // ^ - // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT - // [cfe] This expression has type 'void' and can't be used. + d.f.expectStaticType>(); + d.g.expectStaticType>(); + d.h.expectStaticType>(); } diff --git a/tests/language/regress/regress34877_legacy_test.dart b/tests/language/regress/regress34877_legacy_test.dart new file mode 100644 index 00000000000..d96bcdbcbdb --- /dev/null +++ b/tests/language/regress/regress34877_legacy_test.dart @@ -0,0 +1,26 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// Regression test: ensure that async for loops remain async for loops when +// mixed in. + +import 'dart:async'; + +abstract class _Mixin { + Future stuff(Stream values) async { + var total = 0; + await for (var value in values) { + total += value; + } + return total; + } +} + +class Implementation extends Object with _Mixin {} + +void main() async { + print(await Implementation().stuff(Stream.fromIterable([1, 2, 3]))); +} diff --git a/tests/language/regress/regress34877_test.dart b/tests/language/regress/regress34877_test.dart index 55d8e78b5f7..c25096a9f28 100644 --- a/tests/language/regress/regress34877_test.dart +++ b/tests/language/regress/regress34877_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Regression test: ensure that async for loops remain async for loops when // mixed in. import 'dart:async'; -abstract class _Mixin { +mixin _Mixin { Future stuff(Stream values) async { var total = 0; await for (var value in values) { diff --git a/tests/language/regress/regress65278_legacy_test.dart b/tests/language/regress/regress65278_legacy_test.dart new file mode 100644 index 00000000000..4b93ae11188 --- /dev/null +++ b/tests/language/regress/regress65278_legacy_test.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +void main() { + ContentTabsWidget(); +} + +class StatefulWidget {} + +class State {} + +class WidgetsBindingObserver {} + +class IBase {} + +class ContentTabsWidget extends BaseStatefulWidget {} + +class ContentTabsState + extends BaseState {} + +class BaseStatefulWidget + extends SuperStatefulWidget {} + +class BaseState extends SuperState {} + +class SuperStatefulWidget extends StatefulWidget {} + +class SuperState extends State + with WidgetsBindingObserver {} diff --git a/tests/language/regress/regress65278_test.dart b/tests/language/regress/regress65278_test.dart index d71af419ba3..89c7f0a7aaa 100644 --- a/tests/language/regress/regress65278_test.dart +++ b/tests/language/regress/regress65278_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - void main() { ContentTabsWidget(); } @@ -14,7 +10,7 @@ class StatefulWidget {} class State {} -class WidgetsBindingObserver {} +mixin WidgetsBindingObserver {} class IBase {} diff --git a/tests/language/super/mixin_legacy_test.dart b/tests/language/super/mixin_legacy_test.dart new file mode 100644 index 00000000000..b5e1fda5bd0 --- /dev/null +++ b/tests/language/super/mixin_legacy_test.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// Dart2js regression test: Test that the type mask for non-null exact Mixin is +// created for Mixin.getter. + +import 'package:expect/expect.dart'; + +class Mixin { + @pragma('dart2js:noInline') + get getter => 42; +} + +class Superclass {} + +class Subclass extends Superclass with Mixin { + method() => super.getter; +} + +void main() { + Expect.equals(42, new Subclass().method()); +} diff --git a/tests/language/super/mixin_test.dart b/tests/language/super/mixin_test.dart index c7a883647b6..6d83c41b024 100644 --- a/tests/language/super/mixin_test.dart +++ b/tests/language/super/mixin_test.dart @@ -2,16 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Dart2js regression test: Test that the type mask for non-null exact Mixin is // created for Mixin.getter. import 'package:expect/expect.dart'; -class Mixin { +mixin Mixin { @pragma('dart2js:noInline') get getter => 42; } diff --git a/tests/language/super/no_such_method4_legacy_test.dart b/tests/language/super/no_such_method4_legacy_test.dart new file mode 100644 index 00000000000..e25f094a021 --- /dev/null +++ b/tests/language/super/no_such_method4_legacy_test.dart @@ -0,0 +1,26 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import 'package:expect/expect.dart'; + +class A { + int foo(); + + noSuchMethod(im) => 42; +} + +class B extends Object with A { + noSuchMethod(im) => 87; + + foo() => super.foo(); + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.ABSTRACT_SUPER_MEMBER_REFERENCE + // [cfe] Superclass has no method named 'foo'. +} + +main() { + Expect.equals(87, new B().foo()); +} diff --git a/tests/language/super/no_such_method4_runtime_legacy_test.dart b/tests/language/super/no_such_method4_runtime_legacy_test.dart new file mode 100644 index 00000000000..7d93c3389dd --- /dev/null +++ b/tests/language/super/no_such_method4_runtime_legacy_test.dart @@ -0,0 +1,26 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import 'package:expect/expect.dart'; + +class A { + int foo(); + + noSuchMethod(im) => 42; +} + +class B extends Object with A { + noSuchMethod(im) => 87; + + +} + +main() { + Expect.equals(87, new B().foo()); +} diff --git a/tests/language/super/no_such_method4_runtime_test.dart b/tests/language/super/no_such_method4_runtime_test.dart index 6e3df0bbd3b..d94897be8c5 100644 --- a/tests/language/super/no_such_method4_runtime_test.dart +++ b/tests/language/super/no_such_method4_runtime_test.dart @@ -1,17 +1,10 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import 'package:expect/expect.dart'; -class A { +mixin class A { int foo(); noSuchMethod(im) => 42; @@ -19,10 +12,9 @@ class A { class B extends Object with A { noSuchMethod(im) => 87; - - } main() { + Expect.equals(42, new A().foo()); Expect.equals(87, new B().foo()); } diff --git a/tests/language/super/no_such_method4_test.dart b/tests/language/super/no_such_method4_test.dart index 62032a73d79..98d890dc403 100644 --- a/tests/language/super/no_such_method4_test.dart +++ b/tests/language/super/no_such_method4_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import 'package:expect/expect.dart'; -class A { +mixin class A { int foo(); noSuchMethod(im) => 42; @@ -24,5 +20,6 @@ class B extends Object with A { } main() { + Expect.equals(42, new A().foo()); Expect.equals(87, new B().foo()); } diff --git a/tests/language/super/no_such_method5_legacy_test.dart b/tests/language/super/no_such_method5_legacy_test.dart new file mode 100644 index 00000000000..0b915d27b28 --- /dev/null +++ b/tests/language/super/no_such_method5_legacy_test.dart @@ -0,0 +1,24 @@ +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +import 'package:expect/expect.dart'; + +class A { + int foo(); + + noSuchMethod(im) => 42; +} + +class B extends Object with A { + foo() => super.foo(); + // ^^^ + // [analyzer] COMPILE_TIME_ERROR.ABSTRACT_SUPER_MEMBER_REFERENCE + // [cfe] Superclass has no method named 'foo'. +} + +main() { + Expect.equals(42, new B().foo()); +} diff --git a/tests/language/mixin_legacy/type_parameters_errors_runtime_test.dart b/tests/language/super/no_such_method5_runtime_legacy_test.dart similarity index 56% rename from tests/language/mixin_legacy/type_parameters_errors_runtime_test.dart rename to tests/language/super/no_such_method5_runtime_legacy_test.dart index b388cbb258d..8f7545e97e2 100644 --- a/tests/language/mixin_legacy/type_parameters_errors_runtime_test.dart +++ b/tests/language/super/no_such_method5_runtime_legacy_test.dart @@ -1,24 +1,24 @@ // TODO(multitest): This was automatically migrated from a multitest and may // contain strange or dead code. -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // @dart=2.19 -class S {} +import 'package:expect/expect.dart'; -class M {} +class A { + int foo(); -class A extends S with M {} + noSuchMethod(im) => 42; +} -class F = S with M; +class B extends Object with A { + +} main() { - var a; - a = new A(); - a = new A(); - - a = new F(); + Expect.equals(42, new B().foo()); } diff --git a/tests/language/super/no_such_method5_runtime_test.dart b/tests/language/super/no_such_method5_runtime_test.dart index 497bb5c9037..fb17c54cf15 100644 --- a/tests/language/super/no_such_method5_runtime_test.dart +++ b/tests/language/super/no_such_method5_runtime_test.dart @@ -1,26 +1,18 @@ -// TODO(multitest): This was automatically migrated from a multitest and may -// contain strange or dead code. - // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import 'package:expect/expect.dart'; -class A { +mixin class A { int foo(); noSuchMethod(im) => 42; } -class B extends Object with A { - -} +class B extends Object with A {} main() { - Expect.equals(42, new B().foo()); + Expect.equals(42, A().foo()); + Expect.equals(42, B().foo()); } diff --git a/tests/language/super/no_such_method5_test.dart b/tests/language/super/no_such_method5_test.dart index ada81d15017..85d9c31d3d1 100644 --- a/tests/language/super/no_such_method5_test.dart +++ b/tests/language/super/no_such_method5_test.dart @@ -2,13 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - import 'package:expect/expect.dart'; -class A { +mixin class A { int foo(); noSuchMethod(im) => 42; @@ -22,5 +18,6 @@ class B extends Object with A { } main() { - Expect.equals(42, new B().foo()); + Expect.equals(42, A().foo()); + Expect.equals(42, B().foo()); } diff --git a/tests/language/superinterface_variance/covariance_legacy_test.dart b/tests/language/superinterface_variance/covariance_legacy_test.dart new file mode 100644 index 00000000000..d71a80ec6f9 --- /dev/null +++ b/tests/language/superinterface_variance/covariance_legacy_test.dart @@ -0,0 +1,89 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +typedef F = X Function(); +typedef G = void Function(void Function(X)); + +class A {} + +class B01 extends A> {} + +class B02 extends A> {} + +class B03 extends A {} + +class B04 extends A {} + +class B05 extends Object with A> {} + +class B06 extends Object with A> {} + +class B07 extends Object with A {} + +class B08 extends Object with A {} + +class B09 implements A> {} + +class B10 implements A> {} + +class B11 implements A {} + +class B12 implements A {} + +abstract class B13 extends A>> {} + +abstract class B14 extends A>> {} + +abstract class B15 extends A> {} + +abstract class B16 extends A> {} + +abstract class B17 extends Object with A>> {} + +abstract class B18 extends Object with A>> {} + +abstract class B19 extends Object with A> {} + +abstract class B20 extends Object + with A> {} + +abstract class B21 implements A>> {} + +abstract class B22 implements A>> {} + +abstract class B23 implements A> {} + +abstract class B24 implements A> {} + +main() { + A(); + + B01(); + B02(); + B03(); + B04(); + B05(); + B06(); + B07(); + B08(); + B09(); + B10(); + B11(); + B12(); + + B13 b13; + B14 b14; + B15 b15; + B16 b16; + B17 b17; + B18 b18; + B19 b19; + B20 b20; + B21 b21; + B22 b22; + B23 b23; + B24 b24; +} diff --git a/tests/language/superinterface_variance/covariance_test.dart b/tests/language/superinterface_variance/covariance_test.dart index 8e718b79996..93b0654d43f 100644 --- a/tests/language/superinterface_variance/covariance_test.dart +++ b/tests/language/superinterface_variance/covariance_test.dart @@ -2,14 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - typedef F = X Function(); typedef G = void Function(void Function(X)); -class A {} +mixin class A {} class B01 extends A> {} diff --git a/tests/language/switch/bad_case_legacy_test.dart b/tests/language/switch/bad_case_legacy_test.dart new file mode 100644 index 00000000000..82e8b28078f --- /dev/null +++ b/tests/language/switch/bad_case_legacy_test.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +// Test reporting a compile-time error if case expressions are of type double, +// prior to Dart 3.0 and patterns. + +import "package:expect/expect.dart"; + +void main() { + Expect.equals("IV", caesarSays(4)); + Expect.equals(null, caesarSays(2)); + Expect.equals(null, archimedesSays(3.14)); +} + +/// Before null safety, it was an error if the cases in a switch were not of +/// the same type, regardless of the value expression's type. Now it is only an +/// error if the cases are not a subtype of the value's type. +caesarSays(n) { + switch (n) { + case 1: + return "I"; + case 4: + return "IV"; + case "M": + return 1000; + } + return null; +} + +archimedesSays(n) { + switch (n) { + case 3.14: + // ^^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS + // [cfe] Case expression '3.14' does not have a primitive operator '=='. + return "Pi"; + case 2.71828: + // ^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS + // [cfe] Case expression '2.71828' does not have a primitive operator '=='. + return "Huh?"; + } + return null; +} diff --git a/tests/language/switch/bad_case_test.dart b/tests/language/switch/bad_case_test.dart index 82e8b28078f..87a9f61c59d 100644 --- a/tests/language/switch/bad_case_test.dart +++ b/tests/language/switch/bad_case_test.dart @@ -2,10 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // -// @dart=2.19 - // Test reporting a compile-time error if case expressions are of type double, // prior to Dart 3.0 and patterns. +// @dart=2.19 import "package:expect/expect.dart"; diff --git a/tests/language/switch/case_expression_with_assignment_legacy_test.dart b/tests/language/switch/case_expression_with_assignment_legacy_test.dart new file mode 100644 index 00000000000..58c3e43a846 --- /dev/null +++ b/tests/language/switch/case_expression_with_assignment_legacy_test.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +// Regression test for crash in VM parser (issue 29370). + +import "package:expect/expect.dart"; + +const ERROR_A = 0; +const ERROR_B = 1; + +errorToString(error) { + switch (error) { + case ERROR_A: + return "ERROR_A"; + case ERROR_B = 1: + // ^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_CONST + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.NON_CONSTANT_CASE_EXPRESSION + // [cfe] Setter not found: 'ERROR_B'. + case ERROR_B: + return "ERROR_B"; + default: + return "Unknown error"; + } +} + +main() { + Expect.equals(errorToString(ERROR_A), "ERROR_A"); + Expect.equals(errorToString(ERROR_B), "ERROR_B"); + Expect.equals(errorToString(55), "Unknown error"); +} diff --git a/tests/language/switch/case_expression_with_assignment_test.dart b/tests/language/switch/case_expression_with_assignment_test.dart index 58c3e43a846..0ce963d727f 100644 --- a/tests/language/switch/case_expression_with_assignment_test.dart +++ b/tests/language/switch/case_expression_with_assignment_test.dart @@ -2,9 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // +// Regression test for crash in VM parser (issue 29370). +// Error was in pre-pattern case parsing. // @dart=2.19 -// Regression test for crash in VM parser (issue 29370). import "package:expect/expect.dart"; diff --git a/tests/language/switch/case_fallthrough_legacy_error_test.dart b/tests/language/switch/case_fallthrough_legacy_error_test.dart new file mode 100644 index 00000000000..23f4a67d50a --- /dev/null +++ b/tests/language/switch/case_fallthrough_legacy_error_test.dart @@ -0,0 +1,317 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test switch statement "fallthrough" behavior. +// +// Test behavior for Dart from version 2.12 until 3.0. +// @dart=2.19 +// +// From Dart 2.12 until Dart 3.0, it's an error if control can reach the end +// of a case block. This is backed by a competent control flow analysis. +// +// From Dart 2.0 until Dart 2.12 there was a warning if a case block did +// not end with a control flow statement (like `break`). +// +// From Dart 3.0 and forward, there is no warning or error. + +// These switch-case statements should not cause static warnings or errors, +// and also shouldn't in Dart 2.0 until Dart 2.12. +dynamic testSwitch(int x) { + // Catch all control flow leaving the switch. + // Run switch in catch clause to check that `rethrow` is control flow. + TRY: + try { + throw x; + } catch (_) { + // Add loop as break/continue target. + LOOP: + do { + switch (x) { + case 0: + case 1: + nop(x); + break; // Break switch. + case 2: + nop(x); + break LOOP; + case 3: + nop(x); + continue; // Continue loop. + case 4: + nop(x); + continue LOOP; + case 5: + nop(x); + continue LAST; + case 6: + nop(x); + return; + case 7: + nop(x); + return x; + case 8: + nop(x); + throw x; + case 9: + nop(x); + rethrow; + case 10: + case 11: + { + nop(x); + break; + } + case 12: + { + nop(x); + break LOOP; + } + case 13: + { + nop(x); + continue; // Continue loop. + } + case 14: + { + nop(x); + continue LOOP; + } + case 15: + { + nop(x); + continue LAST; + } + case 16: + { + nop(x); + return; + } + case 17: + { + nop(x); + return x; + } + case 18: + { + nop(x); + throw x; + } + case 19: + { + nop(x); + rethrow; + } + LAST: + case 20: + { + nop(x); + // Fallthrough allowed on last statements. + } + } + } while (false); + } finally { + // Catch all control flow leaving the switch and ignore it. + // Use break instead of return to avoid warning for `return` and `return e` + // in same function. + break TRY; + } +} + +// In Dart 2.0, all of these switch cases should cause warnings because the +// fallthrough analysis was very limited and syntax-based. Null safety +// includes more precise flow analysis so most of these are now valid code +// because in fact no fallthrough will occur. +// +// The cases that are now recognized as not reaching the end of the case block, +// with the Dart 2.12 control flow analysis, are still included to ensure +// that they no longer cause warnings or errors. +// The ones that are still considered as being able to reach the end +// are now expected to cause an error. +// +// Return type `dynamic` to avoid a warning for either of +// `return;` or `return x;`. +dynamic testSwitchWarn(int x) { + // Catch all control flow from the switch and ignore it. + TRY: + try { + throw 0; + } catch (_) { + // Enable `rethrow` as control flow. + // Wrap in loop as target for continue/break. + LOOP: + do { + switch (x) { + case 0: // Case for same statements as next case. + case 1: + { + // Dart 2.0 looked inside a single nested block, but not two. + { + nop(x); + break; // Break and exit switch. + } + } + case 2: + { + { + nop(x); + break LOOP; // Break loop, exits switch (and loop). + } + } + case 3: + { + { + nop(x); + continue; // Continue loop, exits switch. + } + } + case 4: + { + { + nop(x); + continue LOOP; // Continue loop, exits switch. + } + } + case 5: + { + { + nop(x); + continue LAST; // Exits case, goto other case. + } + } + case 6: + { + { + nop(x); + return; // Exits function, loop and switch. + } + } + case 7: + { + { + nop(x); + return x; // Exits function, loop and switch. + } + } + case 8: + { + { + nop(x); + throw x; // Exits switch. + } + } + case 9: + { + { + nop(x); + rethrow; // Exits switch. + } + } + case 10: + // [error column 9, length 4] + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + // [cfe] Switch case may fall through to the next case. + while (true) break; // Breaks loop, reaches end. + case 11: + // [error column 9, length 4] + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + // [cfe] Switch case may fall through to the next case. + do break; while (true); // Breaks loop, reaches end. + case 12: + // [error column 9, length 4] + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + // [cfe] Switch case may fall through to the next case. + for (;;) break; // Breaks loop, reaches end. + case 13: + // [error column 9, length 4] + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + // [cfe] Switch case may fall through to the next case. + for (var _ in []) break LOOP; // Can be empty, reaches end. + case 14: + if (x.isEven) { + break; // Breaks and exits switch. + } else { + break LOOP; // Breaks loop and exits switch. + } + case 15: + (throw 0); // Exits switch. + case 16: + // [error column 9, length 4] + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + // [cfe] Switch case may fall through to the next case. + nop(x); // Reaches end. + case 17: + L: + break; // Breaks and exits switch. + case 18: + // [error column 9, length 4] + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + // [cfe] Switch case may fall through to the next case. + L: + break L; // Breaks break statement only, reaches end. + case 19: + // [error column 9, length 4] + // [cfe] Switch case may fall through to the next case. + // [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY + L: + if (x.isOdd) { + break L; // Breaks if, reaches end. + } else { + break LOOP; + } + + // The type `Never` is new in Dart 2.12. These would be warnings + // with any pre-2.12 type. + case 20: + notEver(x); // Type Never implies not completing. + case 21: { + notEver(x); + } + case 22: { + { + notEver(x); + } + } + case 23: { + do { + notEver(x); + } while (true); + } + case 24: { + if (x.isEven) { + notEver(x); + } else { + notEver(-x); + } + } + case 25: + nop(x.isEven ? notEver(x) : notEver(-x)); + LAST: + case 99: + // Last case can't cause static warning. + } + } while (false); + } finally { + // Catch all control flow leaving the switch and ignore it. + break TRY; + } +} + +Never notEver(int x) { + if (x < 0) { + notEver(x + 1); + } else { + throw AssertionError("Never"); + } +} + +main() { + // Don't let compiler optimize for a specific value. + for (int i = 0; i <= 100; i++) { + testSwitch(i); + testSwitchWarn(i); + } +} + +/// Don't make it obvious that a switch case isn't doing anything. +void nop(Object? x) {} diff --git a/tests/language/switch/case_fallthrough_test.dart b/tests/language/switch/case_fallthrough_test.dart new file mode 100644 index 00000000000..f360211e20b --- /dev/null +++ b/tests/language/switch/case_fallthrough_test.dart @@ -0,0 +1,242 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Test switch statement "fallthrough" behavior. +// +// Tests behavior for Dart from version 3.0, where there is no error or +// warning related to control reaching the end of switch cases. +// See `case_fallthrough_legacy_error_test.dart` for previous behavior. + +// Return type `dynamic` to avoid a warning for either of +// `return;` or `return x;`. +dynamic testSwitch(int x) { + // Catch all control flow leaving the switch. + // Run switch in catch clause to check that `rethrow` is control flow. + TRY: + try { + throw x; + } catch (_) { + // Add loop as break/continue target. + LOOP: + do { + switch (x) { + case 0: + case 1: + nop(x); + break; // Break switch. + case 2: + nop(x); + break LOOP; + case 3: + nop(x); + continue; // Continue loop. + case 4: + nop(x); + continue LOOP; + case 5: + nop(x); + continue LAST; + case 6: + nop(x); + return; + case 7: + nop(x); + return x; + case 8: + nop(x); + throw x; + case 9: + nop(x); + rethrow; + case 10: + case 11: + { + nop(x); + break; + } + case 12: + { + nop(x); + break LOOP; + } + case 13: + { + nop(x); + continue; // Continue loop. + } + case 14: + { + nop(x); + continue LOOP; + } + case 15: + { + nop(x); + continue LAST; + } + case 16: + { + nop(x); + return; + } + case 17: + { + nop(x); + return x; + } + case 18: + { + nop(x); + throw x; + } + case 19: + { + nop(x); + rethrow; + } + case 20: + { + { + nop(x); + break; // Break and exit switch. + } + } + case 21: + { + { + nop(x); + break LOOP; // Break loop, exits switch (and loop). + } + } + case 22: + { + { + nop(x); + continue; // Continue loop, exits switch. + } + } + case 23: + { + { + nop(x); + continue LOOP; // Continue loop, exits switch. + } + } + case 24: + { + { + nop(x); + continue LAST; // Exits case, goto other case. + } + } + case 25: + { + { + nop(x); + return; // Exits function, loop and switch. + } + } + case 26: + { + { + nop(x); + return x; // Exits function, loop and switch. + } + } + case 27: + { + { + nop(x); + throw x; // Exits switch. + } + } + case 28: + { + { + nop(x); + rethrow; // Exits switch. + } + } + case 29: + while (true) break; // Breaks loop, reaches end. + case 30: + do break; while (true); // Breaks loop, reaches end. + case 31: + for (;;) break; // Breaks loop, reaches end. + case 32: + for (var _ in []) break LOOP; // Can be empty, reaches end. + case 33: + if (x.isEven) { + break; // Breaks and exits switch. + } else { + break LOOP; // Breaks loop and exits switch. + } + case 34: + (throw 0); // Exits switch. + case 35: + nop(x); // Reaches end. + case 36: + L: + break; // Breaks and exits switch. + case 37: + L: + break L; // Breaks break statement only, reaches end. + case 38: + L: + if (x.isOdd) { + break L; // Breaks if, reaches end. + } else { + break LOOP; + } + case 39: + notEver(x); // Type Never implies not completing. + case 40: { + notEver(x); + } + case 41: { + { + notEver(x); + } + } + case 42: { + do { + notEver(x); + } while (true); + } + case 43: { + if (x.isEven) { + notEver(x); + } else { + notEver(-x); + } + } + case 44: + nop(x.isEven ? notEver(x) : notEver(-x)); + LAST: + case 99: + } + } while (false); + } finally { + // Catch all control flow leaving the switch and ignore it. + break TRY; + } +} + +Never notEver(int x) { + if (x < 0) { + notEver(x + 1); + } else { + throw AssertionError("Never"); + } +} + +main() { + // Don't let compiler optimize for a specific value. + for (int i = 0; i <= 100; i++) { + testSwitch(i); + } +} + +/// Don't make it obvious that a switch case isn't doing anything. +void nop(Object? x) {} diff --git a/tests/language/switch/case_legacy_test.dart b/tests/language/switch/case_legacy_test.dart new file mode 100644 index 00000000000..5219aabb2e2 --- /dev/null +++ b/tests/language/switch/case_legacy_test.dart @@ -0,0 +1,69 @@ +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +import "package:expect/expect.dart"; + +class A { + const A(); + const factory A.B() = B; + const factory A.C() = C; + const factory A.C2() = D; +} + +class B implements A { + const B(); + + operator ==(o) => true; +} + +class C implements D { + final int x; + const C() : x = 0; + const C.fromD() : x = 1; +} + +class D implements A { + int get x => 0; + const factory D() = C.fromD; +} + +main() { + switch (new B()) { + case const A.B() as B: Expect.fail("bad switch"); break; + // ^^^^^^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS + // ^ + // [cfe] Case expression 'B {}' does not have a primitive operator '=='. + } + + switch (new C()) { + case const C(): + Expect.fail("bad switch"); + break; + case const A.C() as C: + Expect.fail("bad switch"); + break; + case const A.C2() as C: + Expect.fail("bad switch"); + break; + case const A(): Expect.fail("bad switch"); break; + // ^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IS_NOT_SWITCH_EXPRESSION_SUBTYPE + // ^ + // [cfe] Type 'A' of the case expression is not a subtype of type 'C' of this switch expression. + } + + switch (new A()) { + case const A(): + Expect.fail("bad switch"); + break; + case const A.B(): Expect.fail("bad switch"); break; + // ^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS + // ^ + // [cfe] Case expression 'B {}' does not have a primitive operator '=='. + } +} diff --git a/tests/language/switch/case_test.dart b/tests/language/switch/case_test.dart index 5219aabb2e2..84d6ce392bc 100644 --- a/tests/language/switch/case_test.dart +++ b/tests/language/switch/case_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // +// Testing pre-3.0 patterns behavior. // @dart=2.19 import "package:expect/expect.dart"; diff --git a/tests/language/switch/case_warn_test.dart b/tests/language/switch/case_warn_test.dart deleted file mode 100644 index 7920255b5df..00000000000 --- a/tests/language/switch/case_warn_test.dart +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -// Test switch statement. -// -// @dart=2.19 - -// Tests some switch-case statements blocks that should and should not -// cause static warnings. -// This test is not testing runtime behavior, only static warnings. - -// None of the cases blocks should cause a warning. -dynamic testSwitch(int x) { - // Catch all control flow leaving the switch. - // Run switch in catch clause to check rethrow. - TRY: - try { - throw x; - } catch (x) { - // Add loop as break/continue target. - LOOP: - do { - switch (x) { - case 0: - case 1: - nop(x); - break; // Break switch. - case 2: - nop(x); - break LOOP; - case 3: - nop(x); - continue; // Continue loop. - case 4: - nop(x); - continue LOOP; - case 5: - nop(x); - continue LAST; - // Avoid warning for "return;"" and "return e;" in same function. - case 6: // //# retnon: ok - nop(x); // //# retnon: continued - return; // //# retnon: continued - case 7: // //# retval: ok - nop(x); // //# retval: continued - return x; // //# retval: continued - case 8: - nop(x); - throw x; - case 9: - nop(x); - rethrow; - case 10: - case 11: - { - nop(x); - break; // Break switch. - } - case 12: - { - nop(x); - break LOOP; - } - case 13: - { - nop(x); - continue; // Continue loop. - } - case 14: - { - nop(x); - continue LOOP; - } - case 15: - { - nop(x); - continue LAST; - } - case 16: { // //# retnon: continued - nop(x); // //# retnon: continued - return; // //# retnon: continued - } // //# retnon: continued - case 17: { // //# retval: continued - nop(x); // //# retval: continued - return x; // //# retval: continued - } // //# retval: continued - case 18: - { - nop(x); - throw x; - } - case 19: - { - nop(x); - rethrow; - } - LAST: - case 20: - { - nop(x); - // Fallthrough allowed on last statements. - } - } - } while (false); - } finally { - // Catch all control flow leaving the switch and ignore it. - // Use break instead of return to avoid warning for `return` and `return e` - // in same function. - break TRY; - } -} - -/// In Dart 2.0, all of these switch cases should cause warnings because the -/// fallthrough analysis was very limited and syntax-based. Null safety -/// includes more precise flow analysis so most of these are now valid code -/// because in fact no fallthrough will occur. -void testSwitchWarn(x) { - // Catch all control flow from the switch and ignore it. - TRY: - try { - throw 0; - } catch (e) { - // Wrap in loop as target for continue/break. - LOOP: - do { - switch (x) { - case 0: // //# 01: ok - case 1: { // //# 01: continued - { // //# 01: continued - nop(x); // //# 01: continued - break; // Break switch. // //# 01: continued - } // //# 01: continued - } // //# 01: continued - case 2: { // //# 02: ok - { // //# 02: continued - nop(x); // //# 02: continued - break LOOP; // //# 02: continued - } // //# 02: continued - } // //# 02: continued - case 3: { // //# 03: ok - { // //# 03: continued - nop(x); // //# 03: continued - continue; // Continue loop. //# 03: continued - } // //# 03: continued - } // //# 03: continued - case 4: { // //# 04: ok - { // //# 04: continued - nop(x); // //# 04: continued - continue LOOP; // //# 04: continued - } // //# 04: continued - } // //# 04: continued - case 5: { // //# 05: ok - { // //# 05: continued - nop(x); // //# 05: continued - continue LAST; // //# 05: continued - } // //# 05: continued - } // //# 05: continued - case 6: { // //# 06: ok - { // //# 06: continued - nop(x); // //# 06: continued - return; // //# 06: continued - } // //# 06: continued - } // //# 06: continued - case 7: { // //# 07: ok - { // //# 07: continued - nop(x); // //# 07: continued - return x; // //# 07: continued - } // //# 07: continued - } // //# 07: continued - case 8: { // //# 08: ok - { // //# 08: continued - nop(x); // //# 08: continued - throw x; // //# 08: continued - } // //# 08: continued - } // //# 08: continued - case 9: { // //# 09: ok - { // //# 09: continued - nop(x); // //# 09: continued - rethrow; // //# 09: continued - } // //# 09: continued - } // //# 09: continued - case 10: // //# 10: compile-time error - while (true) break; // //# 10: continued - case 11: // //# 11: compile-time error - do break; while (true); // //# 11: continued - case 12: // //# 12: compile-time error - for (;;) break; // //# 12: continued - case 13: // //# 13: compile-time error - for (var _ in []) break; // //# 13: continued - case 14: // //# 14: ok - if (x) break; else break; // //# 14: continued - case 15: // //# 15: ok - (throw 0); // //# 15: continued - case 16: // //# 16: compile-time error - nop(x); // fallthrough. // //# 16: continued - case 17: // //# 17: ok - L: break; // //# 17: continued - LAST: - case 99: - // Last case can't cause static warning. - } - } while (false); - } finally { - // Catch all control flow leaving the switch and ignore it. - // Use break instead of return to avoid warning for `return` and `return e` - // in same function. - break TRY; - } -} - -main() { - // Ensure that all the cases compile and run (even if they might throw). - for (int i = 0; i <= 20; i++) { - testSwitch(i); // Just make sure it runs. - } - for (int i = 0; i <= 18; i++) { - testSwitchWarn(i); - } -} - -/// Don't make it obvious that a switch case isn't doing anything. -void nop(x) {} diff --git a/tests/language/switch/fallthru_legacy_test.dart b/tests/language/switch/fallthru_legacy_test.dart new file mode 100644 index 00000000000..180d44f2cde --- /dev/null +++ b/tests/language/switch/fallthru_legacy_test.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +import "package:expect/expect.dart"; + +String test(int n) { + String result = "foo"; + switch (n) { + case 0: + result = "zero"; + break; + case 1: +// ^^^^ +// [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY +// [cfe] Switch case may fall through to the next case. + result = "one"; + // fall-through, error if case is non-empty + case 9: + result = "nine"; + // No error at end of last switch case. + } + return result; +} + +main() { + Expect.equals("zero", test(0)); + Expect.equals("nine", test(1)); + Expect.equals("nine", test(9)); + Expect.equals("foo", test(99)); +} diff --git a/tests/language/switch/fallthru_test.dart b/tests/language/switch/fallthru_test.dart index 180d44f2cde..77e399c6df0 100644 --- a/tests/language/switch/fallthru_test.dart +++ b/tests/language/switch/fallthru_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // +// Tests legacy behavior where a break was required. // @dart=2.19 import "package:expect/expect.dart"; diff --git a/tests/language/unsorted/assignable_expression_legacy_test.dart b/tests/language/unsorted/assignable_expression_legacy_test.dart new file mode 100644 index 00000000000..88eca641f43 --- /dev/null +++ b/tests/language/unsorted/assignable_expression_legacy_test.dart @@ -0,0 +1,113 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// +// @dart=2.19 + +// Enable the experiments even though the test itself is pinned to 2.19 since +// the error messages relate to patterns. + +// Test to detect syntactically illegal left-hand-side (assignable) +// expressions. + +class C { + static dynamic field = 0; +} + +dynamic variable = 0; + +main() { + variable = 0; + (variable) = 0; +//^^^^^^^^^^ +// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE +// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR +// ^ +// [cfe] Can't assign to a parenthesized expression. + (variable)++; + // ^ + // [cfe] Can't assign to a parenthesized expression. + // ^^ + // [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE + ++(variable); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR + // [cfe] Can't assign to a parenthesized expression. + + C.field = 0; + (C.field) = 0; +//^^^^^^^^^ +// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE +// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR +// ^ +// [cfe] Can't assign to a parenthesized expression. + (C.field)++; + // ^ + // [cfe] Can't assign to a parenthesized expression. + // ^^ + // [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE + ++(C.field); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR + // [cfe] Can't assign to a parenthesized expression. + + variable = [1, 2, 3]; + variable[0] = 0; + (variable)[0] = 0; + (variable[0]) = 0; +//^^^^^^^^^^^^^ +// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE +// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR +// ^ +// [cfe] Can't assign to a parenthesized expression. + (variable[0])++; + // ^ + // [cfe] Can't assign to a parenthesized expression. + // ^^ + // [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE + ++(variable[0]); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR + // [cfe] Can't assign to a parenthesized expression. + + C.field = [1, 2, 3]; + (C.field[0]) = 0; +//^^^^^^^^^^^^ +// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE +// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR +// ^ +// [cfe] Can't assign to a parenthesized expression. + (C.field[0])++; + // ^ + // [cfe] Can't assign to a parenthesized expression. + // ^^ + // [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE + ++(C.field[0]); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR + // [cfe] Can't assign to a parenthesized expression. + + var a = 0; + (a) = 0; +//^^^ +// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE +// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR +// ^ +// [cfe] Can't assign to a parenthesized expression. + (a)++; + //^ + // [cfe] Can't assign to a parenthesized expression. + // ^^ + // [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE + ++(a); + // ^ + // [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR + // [cfe] Can't assign to a parenthesized expression. + + // Neat palindrome expression. x is assignable, ((x)) is not. + var funcnuf = (x) => ((x))=((x)) <= (x); + // ^^^^^ + // [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR + // ^ + // [cfe] Can't assign to a parenthesized expression. +} diff --git a/tests/language/unsorted/assignable_expression_test.dart b/tests/language/unsorted/assignable_expression_test.dart index 88eca641f43..d98b35daf31 100644 --- a/tests/language/unsorted/assignable_expression_test.dart +++ b/tests/language/unsorted/assignable_expression_test.dart @@ -2,13 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // -// @dart=2.19 - -// Enable the experiments even though the test itself is pinned to 2.19 since -// the error messages relate to patterns. - // Test to detect syntactically illegal left-hand-side (assignable) // expressions. +// +// Checks that the pattern feature does not affect invalid legacy code. +// @dart=2.19 class C { static dynamic field = 0; diff --git a/tests/language/unsorted/deny_listed_test.dart b/tests/language/unsorted/deny_listed_test.dart deleted file mode 100644 index 785b0ee88f1..00000000000 --- a/tests/language/unsorted/deny_listed_test.dart +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -// Dart test checking that static/instance field shadowing do not conflict. - -// Test that certain interfaces/classes are denylisted from being -// implemented or extended. - -// bool. -class MyBool implements bool {} // //# 01: compile-time error -abstract class MyBoolInterface implements bool default F { // //# 02: syntax error - MyBoolInterface(); // //# 02: continued -} // //# 02: continued - -// num. -class MyNum implements num {} // //# 03: compile-time error -abstract class MyNumInterface implements num default F { // //# 04: syntax error - MyNumInterface(); // //# 04: continued -} // //# 04: continued - -// int. -class MyInt implements int {} // //# 05: compile-time error -abstract class MyIntInterface implements int default F { // //# 06: syntax error - MyIntInterface(); // //# 06: continued -} // //# 06: continued - -// double. -class MyDouble implements double {} // //# 07: compile-time error -abstract class MyDoubleInterface implements double default F { // //# 08: syntax error - MyDoubleInterface(); // //# 08: continued -} // //# 08: continued - -// String. -class MyString implements String {} // //# 09: compile-time error -abstract class MyStringInterface implements String default F { // //# 10: syntax error - MyStringInterface(); // //# 10: continued -} // //# 10: continued - -// Function. -class MyFunction implements Function {} - -class MyOtherFunction extends Function {} -abstract class MyFunctionInterface implements Function default F { // //# 12: syntax error - MyFunctionInterface(); // //# 12: continued -} // //# 12: continued - -// dynamic. -class MyDynamic implements dynamic {} // //# 13: compile-time error -abstract class MyDynamicInterface implements dynamic default F { // //# 14: syntax error - MyDynamicInterface(); // //# 14: continued -} // //# 14: continued - -class F { - factory MyBoolInterface() { return null; } // //# 02: continued - factory MyNumInterface() { return null; } // //# 04: continued - factory MyIntInterface() { return null; } // //# 06: continued - factory MyDoubleInterface() { return null; } // //# 08: continued - factory MyStringInterface() { return null; } // //# 10: continued - factory MyFunctionInterface() { return null; } // //# 12: continued - factory MyDynamicInterface() { return null; } // //# 14: continued -} - -main() { - new MyBool(); // //# 01: continued - new MyBoolInterface(); // //# 02: continued - new MyNum(); // //# 03: continued - new MyNumInterface(); // //# 04: continued - new MyInt(); // //# 05: continued - new MyIntInterface(); // //# 06: continued - new MyDouble(); // //# 07: continued - new MyDoubleInterface(); // //# 08: continued - new MyString(); // //# 09: continued - new MyStringInterface(); // //# 10: continued - new MyFunction(); - new MyOtherFunction(); - new MyFunctionInterface(); //# 12: continued - new MyDynamic(); // //# 13: continued - new MyDynamicInterface(); // //# 14: continued -} diff --git a/tests/language/vm/regress_32971_legacy_test.dart b/tests/language/vm/regress_32971_legacy_test.dart new file mode 100644 index 00000000000..7220afb61b8 --- /dev/null +++ b/tests/language/vm/regress_32971_legacy_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// Test verifying that default switch cast is cloned correctly by the +// mixin transformation. + +import "package:expect/expect.dart"; + +void main() { + final o = new A(); + Expect.isTrue(o.f()); + Expect.isTrue(o.g()); +} + +class A extends B with M {} + +class B { + bool f() { + switch (true) { + default: + return true; + } + return false; + } +} + +class M { + bool g() { + switch (true) { + default: + return true; + } + return false; + } +} diff --git a/tests/language/vm/regress_32971_test.dart b/tests/language/vm/regress_32971_test.dart index eeff98ee3a0..2be7d53272c 100644 --- a/tests/language/vm/regress_32971_test.dart +++ b/tests/language/vm/regress_32971_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Test verifying that default switch cast is cloned correctly by the // mixin transformation. @@ -29,7 +25,7 @@ class B { } } -class M { +mixin M { bool g() { switch (true) { default: diff --git a/tests/language/vm/regress_33040_instantiation_legacy_test.dart b/tests/language/vm/regress_33040_instantiation_legacy_test.dart new file mode 100644 index 00000000000..e4fe0730e1b --- /dev/null +++ b/tests/language/vm/regress_33040_instantiation_legacy_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// +// Exact regression test for issue #33040. + +import 'dart:async'; + +class Optional {} + +typedef T? ConvertFunction(); + +T? blockingLatest() { + return null; +} + +abstract class ObservableModel {} + +abstract class AsyncValueMixin { + Future? get asyncValue { + ConvertFunction f = blockingLatest; + if (f is! ConvertFunction) throw "error"; + return null; + } +} + +abstract class OptionalSettableObservableModel + extends ObservableModel> with AsyncValueMixin> {} + +class FooObservableModel extends OptionalSettableObservableModel {} + +Future main() async { + var model = new FooObservableModel(); + await model.asyncValue; +} diff --git a/tests/language/vm/regress_33040_instantiation_test.dart b/tests/language/vm/regress_33040_instantiation_test.dart index 20d30809559..f027b61a97b 100644 --- a/tests/language/vm/regress_33040_instantiation_test.dart +++ b/tests/language/vm/regress_33040_instantiation_test.dart @@ -2,12 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - -// // Exact regression test for issue #33040. +// @dart=2.19 import 'dart:async'; diff --git a/tests/language/vm/regression_38231_legacy_test.dart b/tests/language/vm/regression_38231_legacy_test.dart new file mode 100644 index 00000000000..cab6d2be29b --- /dev/null +++ b/tests/language/vm/regression_38231_legacy_test.dart @@ -0,0 +1,128 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// VMOptions=--optimization_counter_threshold=1 + +import "package:expect/expect.dart"; + +import 'dart:typed_data'; + +// Found by DartFuzzing: would sometimes crash on OSR +// https://github.com/dart-lang/sdk/issues/38231 + +import 'dart:async'; +import 'dart:cli'; +import 'dart:collection'; +import 'dart:convert'; +import 'dart:core'; +import 'dart:io'; +import 'dart:isolate'; +import 'dart:math'; +import 'dart:typed_data'; + +Map var0 = { + 41: 'V\u2665Y\u2665#Xs', + for (int loc0 in { + if (true) for (int loc0 in {-2147483649}) -4294967167 else if (false) -1, + -60, + -82, + -21, + for (int loc0 in [ + -9223372036854771712, + for (int loc0 = 0; loc0 < 53; loc0++) 96 + ]) + 1, + -58, + 77 + }) + 95: '', + 5: 'z2\u2665e', + if (false) for (int loc0 in [-87, -2147483649, 0, 97, -53, 95]) 10: '#synP3', + 22: '' +}; +String var1 = ')LIpwG'; +double var2 = 0.30016980633333135; +bool var3 = true; +bool var4 = true; +int var5 = -9223372036854774808; +double var6 = 0.7012235530406754; +String var7 = 'H'; +List var8 = [90, -50, -34, -97, -33, 1]; +Set var9 = { + 42, + 36, + 9223372034707292159, + ...{52}, + 97, + for (int loc0 in { + if (true) ...{13} else -54, + -26, + -38, + 9223372032559808513, + 60 + }) + for (int loc1 in { + for (int loc1 in {19, 60}) -4294967280, + -17, + -62 + }) ...{23, 11}, + for (int loc0 = 0; loc0 < 30; loc0++) -44 +}; +Map var10 = { + for (int loc0 in { + ...{ + -52, + -9223372030412324864, + if (true) 82, + ...{76, 5, 9223372032559841279, 98, 58, 97, -127, 72}, + for (int loc0 in [-97]) -14, + for (int loc0 = 0; loc0 < 21; loc0++) 88 + }, + -52, + for (int loc0 = 0; loc0 < 63; loc0++) ...{64, 0}, + for (int loc0 = 0; loc0 < 67; loc0++) ...{67} + }) + 54: '', + 41: 'cvokV0', + 4: '9\u2665', + 35: 'vRkv', + 41: '\u2665', + 63: 'Nu+u\u26659S' +}; + +class X0 {} + +class X1 with X0 { + bool foo1_0(List par1, bool par2) => true; + Map foo1_1(Set par1, bool par2, Set par3) { + return {1: "a", 2: "b"}; + } +} + +main() { + try { + X1().foo1_0([1, 2], true); + } catch (exception, stackTrace) { + print('X1().foo1_0() throws'); + } + try { + X1().foo1_1( + { + 32, + -94, + -2147483649, + -43, + for (int loc0 in {56, -31}) -9223372032559775745, + 53, + 86, + 4294967296 + }, + var4, + {1, 2}); + } catch (exception, stackTrace) { + print('X1().foo1_1() throws'); + } +} diff --git a/tests/language/vm/regression_38231_test.dart b/tests/language/vm/regression_38231_test.dart index 024ec1d58cb..3c7475d4e1d 100644 --- a/tests/language/vm/regression_38231_test.dart +++ b/tests/language/vm/regression_38231_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // VMOptions=--optimization_counter_threshold=1 import "package:expect/expect.dart"; @@ -95,7 +91,7 @@ Map var10 = { 63: 'Nu+u\u26659S' }; -class X0 {} +mixin class X0 {} class X1 with X0 { bool foo1_0(List par1, bool par2) => true; diff --git a/tests/language/void/generalized_void_syntax_legacy_test.dart b/tests/language/void/generalized_void_syntax_legacy_test.dart new file mode 100644 index 00000000000..4db48053d0a --- /dev/null +++ b/tests/language/void/generalized_void_syntax_legacy_test.dart @@ -0,0 +1,148 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart=2.19 + +// Testing that the reserved word `void` is allowed to occur as a type, not +// just as a return type. + +typedef F = void Function(Object?); +typedef F2 = void Function([Object?]); +typedef F3 = void Function({Object? x}); + +typedef G = void Function(void); +typedef G2 = void Function([void]); +typedef G3 = void Function({void x}); + +typedef H = int Function(void); +typedef H2 = int Function([void]); +typedef H3 = int Function({void x}); + +class A { + final T t; + const A(this.t); +} + +const void x1 = null; +const A x2 = const A(null); + +final void x3 = null; +final A x4 = new A(null); + +void x5 = null, x6; +A x7 = new A(null), x8 = new A(null); + +void get g1 => null; +A get g2 => new A(null); +void set s1(void x) => null; +void set s2(A x) => null; +void m1(void x, [void y]) => null; +void m2(void x, {void y}) => null; +A m3(A? x, [A? y]) => new A(null); +A m4(A? x, {A? y}) => new A(null); + +class B implements A { + void get t => null; +} + +class C extends A with B> { + C() : super(null); + + static final void x1 = null; + static final A x2 = new A(null); + + static const void x3 = null; + static const A x4 = const A(null); + + final void x5 = null; + final A x6 = new A(null); + + static void x7 = null, x8; + static A x9 = new A(null); + + covariant void x11 = null, x12; + covariant A x13 = new A(null); + + static void get g1 => null; + static A get g2 => new A(null); + static void set s1(void x) => null; + static void set s2(A x) => null; + static void m1(void x, [void y]) => null; + static void m2(void x, {void y}) => null; + static A m3(A x, [A? y]) => x; + static A m4(A x, {A? y}) => x; + + void get g3 => null; + A get g4 => new A(null); + void set s3(void x) => null; + void set s4(A x) => null; + void m5(void x, [void y]) => null; + void m6(void x, {void y}) => null; + A m7(A x, [A? y]) => x; + A m8(A x, {A? y}) => x; + + // Ensure that all members are used, and use `void` in expressions. + void run() { + x1; + x2; + x3; + x4; + x5; + x6; + x7; + x8; + x9; + + x11; + x12; + x13; + + g1; + g2; + g3; + g4; + + s1 = null; + s2 = new A(null); + s3 = null; + s4 = new A(null); + m1(new A(null), null); + m2(new A(null), y: null); + m3(new A(null), new A(null)); + m4(new A(null), y: new A(null)); + m5(new A(null), null); + m6(new A(null), y: null); + m7(new A(null), new A(null)); + m8(new A(null), y: new A(null)); + + void pretendToUse(dynamic x) => null; + pretendToUse([]); + pretendToUse({}); + pretendToUse(>[]); + pretendToUse(, A>{}); + } +} + +// Testing syntax, just enforce compilation. +main() { + // ignore + x1; + x2; + x3; + x4; + x5; + x6; + x7; + x8; + g1; + g2; + + s1 = null; + s2 = new A(null); + m1(new A(null), new A(null)); + m2(new A(null), y: new A(null)); + m3(new A(null), new A(null)); + m4(new A(null), y: new A(null)); + new C().run(); +} diff --git a/tests/language/void/generalized_void_syntax_test.dart b/tests/language/void/generalized_void_syntax_test.dart index 5c9f9aedfa1..0a7ab9ca41e 100644 --- a/tests/language/void/generalized_void_syntax_test.dart +++ b/tests/language/void/generalized_void_syntax_test.dart @@ -2,10 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// TODO(51557): Decide if the mixins being applied in this test should be -// "mixin", "mixin class" or the test should be left at 2.19. -// @dart=2.19 - // Testing that the reserved word `void` is allowed to occur as a type, not // just as a return type. @@ -44,7 +40,7 @@ void m2(void x, {void y}) => null; A m3(A? x, [A? y]) => new A(null); A m4(A? x, {A? y}) => new A(null); -class B implements A { +mixin B implements A { void get t => null; }