Skip to content

Fixes #2902. Add tests for an extension applicability #2903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions LanguageFeatures/Extension-methods/applicability_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.

/// @assertion An extension `E` is applicable to a simple or composite member
/// 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).
///
/// @description Check that an extension member with the basename `m` is not
/// applicable if on type has a static member with the same basename.
/// @author [email protected]
/// @issue 56818

class C {
static String get m1 => "m1";
static String m2() => "m2";
static void set m3(String _) {}
}

extension Ext on C {
String get m1 => "Ext.m1";
String m2() => "Ext.m2";
void set m3(String _) {}
}

main() {
print(C().m1);
// ^^
// [analyzer] unspecified
// [cfe] unspecified

print(C().m2());
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C().m3 = "";
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
50 changes: 50 additions & 0 deletions LanguageFeatures/Extension-methods/applicability_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.

/// @assertion An extension `E` is applicable to a simple or composite member
/// 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).
///
/// @description Check that an extension member with the basename `m` is not
/// applicable if on type has a static member with the same basename.
/// @author [email protected]

class C {
static String get m1 => "m1";
static String m2() => "m2";
static void set m3(String _) {}
}

extension Ext on C {
void set m1(String _) {}
void set m2(String _) {}
String m3() => "Ext.m2";
}

main() {
print(C().m1);
// ^^
// [analyzer] unspecified
// [cfe] unspecified

print(C().m2());
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C().m3 = "";
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}