| // 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 getters is inferred |
| /// to be the return type of the combined member signature of said getter 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 getter declared not in the direct |
| /// superinterface. |
| /// @author sgrekhov22@gmail.com |
| |
| import '../../Utils/static_type_helper.dart'; |
| |
| mixin M { |
| num get m1 => 3.14; |
| num get m2 => 3.14; |
| num get m3 => 3.14; |
| } |
| |
| class B with M {} |
| |
| class C1 extends B { |
| get m1 => 0; |
| void set m2(v) { |
| v.expectStaticType<Exactly<num>>(); |
| } |
| final m3 = 0; |
| } |
| |
| class C2 implements B { |
| get m1 => 0; |
| get m2 => 0; |
| void set m2(v) { |
| v.expectStaticType<Exactly<num>>(); |
| } |
| final m3 = 0; |
| } |
| |
| mixin M1 on B { |
| get m1 => 0; |
| void set m2(v) { |
| v.expectStaticType<Exactly<num>>(); |
| } |
| final m3 = 0; |
| } |
| |
| mixin M2 implements B { |
| get m1 => 0; |
| get m2 => 0; |
| void set m2(v) { |
| v.expectStaticType<Exactly<num>>(); |
| } |
| final m3 = 0; |
| } |
| |
| mixin class MC implements B { |
| get m1 => 0; |
| get m2 => 0; |
| void set m2(v) { |
| v.expectStaticType<Exactly<num>>(); |
| } |
| final m3 = 0; |
| } |
| |
| enum E1 implements B { |
| e0; |
| |
| get m1 => 0; |
| get m2 => 0; |
| void set m2(v) { |
| v.expectStaticType<Exactly<num>>(); |
| } |
| final m3 = 0; |
| } |
| |
| class MA1 = B 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>>(); |
| 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>>(); |
| } |