From 213cde4a212ba3ac79f93b09d1f3443e717be3df Mon Sep 17 00:00:00 2001 From: "Sergey G. Grekhov" Date: Wed, 2 Oct 2024 15:44:17 +0300 Subject: [PATCH] Fixes #2909. Fix extension applicability tests according to the updated spec (#2911) Fixes #2909. Fix extension applicability tests according to the updated spec --- .../applicability_A01_t01.dart | 50 +++++++-------- .../applicability_A01_t02.dart | 64 ++++++++++--------- 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/LanguageFeatures/Extension-methods/applicability_A01_t01.dart b/LanguageFeatures/Extension-methods/applicability_A01_t01.dart index e12c70a2cc..ef144a0337 100644 --- a/LanguageFeatures/Extension-methods/applicability_A01_t01.dart +++ b/LanguageFeatures/Extension-methods/applicability_A01_t01.dart @@ -6,46 +6,44 @@ /// invocation with corresponding member basename m and target expression `e`, /// where `e` has static type `S`, if /// ... -/// - The type S does not have a member with the basename m. For this, the type -/// `dynamic` is considered as having all member names, and an expression of -/// type `Never` or `void` cannot occur as the target of a member invocation, -/// so none of these can ever have applicable extensions. Function types and -/// the type `Function` are considered as having a `call` member. This ensure -/// that if there is an applicable extension, the existing invocation would -/// otherwise be a compile-time error. Members of `Object` exists on all -/// types, so they can never be the target of implicit member invocations -/// (they can also not be declared as extension members). +/// - The type S does not have an instance member with the basename m. For this, +/// the type `dynamic` is considered as having all member names, and an +/// expression of type `Never` or `void` cannot occur as the target of a +/// member invocation, so none of these can ever have applicable extensions. +/// Function types and the type `Function` are considered as having a `call` +/// member. This ensure that if there is an applicable extension, the existing +/// invocation would otherwise be a compile-time error. Members of `Object` +/// exists on all types, so they can never be the target of implicit member +/// invocations (they can also not be declared as extension members). /// -/// @description Check that an extension member with the basename `m` is not -/// applicable if on type has a static member with the same basename. +/// @description Check that an extension member with the basename `m` is +/// applicable even if the on type has a static member with the same basename. /// @author sgrekhov22@gmail.com /// @issue 56818 +import '../../Utils/expect.dart'; + +String _log = ""; + class C { static String get m1 => "m1"; static String m2() => "m2"; - static void set m3(String _) {} + static void set m3(String _) { + _log = "m3"; + } } extension Ext on C { String get m1 => "Ext.m1"; String m2() => "Ext.m2"; - void set m3(String _) {} + void set m3(String _) { + _log = "Ext.m3"; + } } main() { - print(C().m1); -// ^^ -// [analyzer] unspecified -// [cfe] unspecified - - print(C().m2()); -// ^^ -// [analyzer] unspecified -// [cfe] unspecified - + Expect.equals("Ext.m1", C().m1); + Expect.equals("Ext.m2", C().m2()); C().m3 = ""; -// ^^ -// [analyzer] unspecified -// [cfe] unspecified + Expect.equals("Ext.m3", _log); } diff --git a/LanguageFeatures/Extension-methods/applicability_A01_t02.dart b/LanguageFeatures/Extension-methods/applicability_A01_t02.dart index 46a26133bf..48fadb452b 100644 --- a/LanguageFeatures/Extension-methods/applicability_A01_t02.dart +++ b/LanguageFeatures/Extension-methods/applicability_A01_t02.dart @@ -6,45 +6,51 @@ /// invocation with corresponding member basename m and target expression `e`, /// where `e` has static type `S`, if /// ... -/// - The type S does not have a member with the basename m. For this, the type -/// `dynamic` is considered as having all member names, and an expression of -/// type `Never` or `void` cannot occur as the target of a member invocation, -/// so none of these can ever have applicable extensions. Function types and -/// the type `Function` are considered as having a `call` member. This ensure -/// that if there is an applicable extension, the existing invocation would -/// otherwise be a compile-time error. Members of `Object` exists on all -/// types, so they can never be the target of implicit member invocations -/// (they can also not be declared as extension members). +/// - The type S does not have an instance member with the basename m. For this, +/// the type `dynamic` is considered as having all member names, and an +/// expression of type `Never` or `void` cannot occur as the target of a +/// member invocation, so none of these can ever have applicable extensions. +/// Function types and the type `Function` are considered as having a `call` +/// member. This ensure that if there is an applicable extension, the existing +/// invocation would otherwise be a compile-time error. Members of `Object` +/// exists on all types, so they can never be the target of implicit member +/// invocations (they can also not be declared as extension members). /// -/// @description Check that an extension member with the basename `m` is not -/// applicable if on type has a static member with the same basename. +/// @description Check that an extension member with the basename `m` is +/// applicable even if the on type has a static member with the same basename. /// @author sgrekhov22@gmail.com +import '../../Utils/expect.dart'; + +String _log = ""; + class C { static String get m1 => "m1"; static String m2() => "m2"; - static void set m3(String _) {} + static void set m3(String _) { + _log = "m3"; + } + static void set m4(String _) { + _log = "m4"; + } } extension Ext on C { - void set m1(String _) {} - void set m2(String _) {} - String m3() => "Ext.m2"; + void set m1(String _) { + _log = "Ext.m1"; + } + void set m2(String _) { + _log = "Ext.m2"; + } + String m3() => "Ext.m3"; + String get m4 => "Ext.m4"; } main() { - print(C().m1); -// ^^ -// [analyzer] unspecified -// [cfe] unspecified - - print(C().m2()); -// ^^ -// [analyzer] unspecified -// [cfe] unspecified - - C().m3 = ""; -// ^^ -// [analyzer] unspecified -// [cfe] unspecified + C().m1 = ""; + Expect.equals("Ext.m1", _log); + C().m2 = ""; + Expect.equals("Ext.m2", _log); + Expect.equals("Ext.m3", C().m3()); + Expect.equals("Ext.m4", C().m4); }