Files
sdk/pkg/front_end/testcases/patterns/extension_access.dart
T
Johnni Winther 3b56301f3d [_fe_analyzer_shared] Add support for extension members in exhaustiveness checking
This adds support for extension members in exhaustiveness checking. These are different from regular members in that the type cannot be derived from the matched type but instead is determined by the required type of the object pattern.

To support this a new ExtensionKey is added which holds the static type of the property and whose identity is determined by the name of the property _and_ the type of the receiver (taken from the required type of the object pattern).

When expanding properties, the type of the ExtensionKey is used when the
SingleSpace doesn't have the corresponding property instead of looking up the property type on the static type of the SingleSpace.

Closes #51854

Change-Id: I7a54005972d0640b7dc79e92950bf6d1f89c3fd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292741
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-04-03 16:47:33 +00:00

28 lines
552 B
Dart

// 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.
class I {}
class A implements I {}
extension on A {
int get member => 87;
}
extension on I {
int get member => 42;
}
method(A a) => switch (a) {
I(:var member) => member,
};
main() {
expect(42, method(new A()));
}
expect(expected, actual) {
if (expected != actual) throw 'Expected $expected, actual $actual';
}