mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
8de8a1c226
They are all errors now. Change-Id: If48d38e38e845fd5b5a950dd5514bf1cbbce03d8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155880 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
122 lines
3.1 KiB
Dart
122 lines
3.1 KiB
Dart
// 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.
|
|
|
|
// Tests extension method resolution failures.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
main() {
|
|
A a = C();
|
|
B1 b1 = C();
|
|
B2 b2 = C();
|
|
C c = C();
|
|
|
|
Expect.equals("EA.v1", a.v1);
|
|
Expect.equals("EB1.v1", b1.v1);
|
|
Expect.equals("EB2.v1", b2.v1);
|
|
Expect.equals("EC.v1", c.v1);
|
|
|
|
Expect.equals("EA.v2", a.v2);
|
|
Expect.equals("EB1.v2", b1.v2);
|
|
Expect.equals("EB2.v2", b2.v2);
|
|
// Cannot determine which of EB1 and EB2's v2 is more specific
|
|
c.v2;
|
|
//^^
|
|
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
|
|
// [cfe] The property 'v2' is defined in multiple extensions for 'C' and neither is more specific.
|
|
|
|
Expect.equals("EA.v3", a.v3);
|
|
Expect.equals("EA.v3", b1.v3);
|
|
Expect.equals("EA.v3", b2.v3);
|
|
Expect.equals("EA.v3", c.v3);
|
|
|
|
Iterable<num> i_num = <int>[];
|
|
Iterable<int> ii = <int>[];
|
|
List<num> ln = <int>[];
|
|
List<int> li = <int>[];
|
|
|
|
// No `i_num` extension declared.
|
|
i_num.i_num;
|
|
// ^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
|
|
// [cfe] The getter 'i_num' isn't defined for the class 'Iterable<num>'.
|
|
|
|
Expect.equals("Iterable<int>.i_num", ii.i_num);
|
|
Expect.equals("List<num>.i_num", ln.i_num);
|
|
|
|
// Both apply, neither is more specific.
|
|
li.i_num;
|
|
// ^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
|
|
// [cfe] The property 'i_num' is defined in multiple extensions for 'List<int>' and neither is more specific.
|
|
|
|
// no most specific because both are equally specific.
|
|
c.cs;
|
|
//^^
|
|
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
|
|
// [cfe] The property 'cs' is defined in multiple extensions for 'C' and neither is more specific.
|
|
|
|
// Both EIT.e1 and ELO.e1 apply, but their instantiated on
|
|
// types are incomparable, and hence this is an error.
|
|
ln.e1();
|
|
// ^^
|
|
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
|
|
// [cfe] The method 'e1' is defined in multiple extensions for 'List<num>' and neither is more specific.
|
|
}
|
|
|
|
// Diamond class hierarchy.
|
|
class A {}
|
|
|
|
class B1 implements A {}
|
|
|
|
class B2 implements A {}
|
|
|
|
class C implements B1, B2 {}
|
|
|
|
extension EA on A {
|
|
String get v1 => "EA.v1";
|
|
String get v2 => "EA.v2";
|
|
String get v3 => "EA.v3";
|
|
}
|
|
|
|
extension EB1 on B1 {
|
|
String get v1 => "EB1.v1";
|
|
String get v2 => "EB1.v2";
|
|
}
|
|
|
|
extension EB2 on B2 {
|
|
String get v1 => "EB2.v1";
|
|
String get v2 => "EB2.v2";
|
|
}
|
|
|
|
extension EC on C {
|
|
String get v1 => "EC.v1";
|
|
}
|
|
|
|
// Iterable<num>, Iterable<int>, List<num> and List<int> also forms diamond
|
|
// hierarchy.
|
|
extension II on Iterable<int> {
|
|
String get i_num => "Iterable<int>.i_num";
|
|
}
|
|
|
|
extension LN on List<num> {
|
|
String get i_num => "List<num>.i_num";
|
|
}
|
|
|
|
// Two exactly identical `on` types.
|
|
extension C1 on C {
|
|
String get cs => "C1.cs";
|
|
}
|
|
|
|
extension C2 on C {
|
|
String get cs => "C2.cs";
|
|
}
|
|
|
|
extension EIT<T> on Iterable<T> {
|
|
String e1() => "Iterable<T>.e1";
|
|
}
|
|
|
|
extension ELO on List<Object> {
|
|
String e1() => "List<Object>.e1";
|
|
}
|