blob: c72c1d8d4e8e039a690435ed0a7c9d94d5a451cd [file] [edit]
// Copyright (c) 2026, 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 The return type of a getter, parameter type of a setter or type
/// of a field which overrides/implements only one or more setters is inferred
/// to be the parameter type of the combined member signature of said setter in
/// the direct superinterfaces.
///
/// @description Checks that the return type of a getter/field or parameter type
/// of a setter can be inferred from a setter in the direct superinterface. Test
/// a type parameter which is instantiated explicitly.
/// @author sgrekhov22@gmail.com
import '../../Utils/static_type_helper.dart';
mixin class A<T> {
void set m1(T _) {}
void set m2(T _) {}
void set m3(T _) {}
}
class C1 extends A<num> {
get m1 => 0;
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
}
class C2 implements A<num> {
get m1 => 0;
void set m1(_) {} // We need to implement a setter as well
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
void set m3(_) {}
}
class C3 with A<num> {
get m1 => 0;
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
}
mixin M1 on A<num> {
get m1 => 0;
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
}
mixin M2 implements A<num> {
get m1 => 0;
void set m1(_) {}
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
void set m3(_) {}
}
mixin class MC implements A<num> {
get m1 => 0;
void set m1(_) {}
get m2 => 0;
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
void set m3(_) {}
}
enum E1 implements A<num> {
e0;
get m1 => 0;
void set m1(_) {}
get m2 => 0;
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
void set m3(_) {}
}
enum E2 with A<num> {
e0;
get m1 => 0;
void set m2(v) {
v.expectStaticType<Exactly<num>>();
}
final m3 = 0;
}
class MA1 = A<num> with M1;
class MA2 = Object with M2;
main() {
C1().m1.expectStaticType<Exactly<num>>();
C1().m3.expectStaticType<Exactly<num>>();
C2().m1.expectStaticType<Exactly<num>>();
C2().m3.expectStaticType<Exactly<num>>();
C3().m1.expectStaticType<Exactly<num>>();
C3().m3.expectStaticType<Exactly<num>>();
MA1().m1.expectStaticType<Exactly<num>>();
MA1().m3.expectStaticType<Exactly<num>>();
MA2().m1.expectStaticType<Exactly<num>>();
MA2().m3.expectStaticType<Exactly<num>>();
MC().m1.expectStaticType<Exactly<num>>();
MC().m3.expectStaticType<Exactly<num>>();
E1.e0.m1.expectStaticType<Exactly<num>>();
E1.e0.m3.expectStaticType<Exactly<num>>();
E2.e0.m1.expectStaticType<Exactly<num>>();
E2.e0.m3.expectStaticType<Exactly<num>>();
}