Skip to content

Commit

Permalink
Fixes #2909. Fix extension applicability tests according to the updat…
Browse files Browse the repository at this point in the history
…ed spec (#2911)

Fixes #2909. Fix extension applicability tests according to the updated spec
  • Loading branch information
sgrekhov authored Oct 2, 2024
1 parent 4134cea commit 213cde4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 55 deletions.
50 changes: 24 additions & 26 deletions LanguageFeatures/Extension-methods/applicability_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
/// @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);
}
64 changes: 35 additions & 29 deletions LanguageFeatures/Extension-methods/applicability_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
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);
}

0 comments on commit 213cde4

Please sign in to comment.