mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:29:48 +00:00
4d1c8b09cb
This looks like it was an oversight--previous to this change, there was zero test coverage for this case. Change-Id: I4301a3ba90aedce3b0fcd901649c370cba522f4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353280 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
49 lines
1.8 KiB
Dart
49 lines
1.8 KiB
Dart
// 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.
|
|
|
|
/// Tests that type inference supplies the proper context for the right hand
|
|
/// side of a property set that refers to an extension method.
|
|
|
|
import '../static_type_helper.dart';
|
|
|
|
extension E on Object? {
|
|
set s1(int i) {}
|
|
set s2(int? i) {}
|
|
}
|
|
|
|
class C {
|
|
set s3(int i) {}
|
|
set s4(int? i) {}
|
|
}
|
|
|
|
main() {
|
|
var string = '';
|
|
context<num>(string.s1 = contextType(1)..expectStaticType<Exactly<int>>());
|
|
context<num>(E(string).s1 = contextType(1)..expectStaticType<Exactly<int>>());
|
|
context<num?>(string.s2 = contextType(1)..expectStaticType<Exactly<int?>>());
|
|
context<num?>(
|
|
E(string).s2 = contextType(1)..expectStaticType<Exactly<int?>>());
|
|
|
|
var nullableString = '' as String?;
|
|
context<num?>(
|
|
nullableString?.s1 = contextType(1)..expectStaticType<Exactly<int>>());
|
|
context<num?>(
|
|
E(nullableString)?.s1 = contextType(1)..expectStaticType<Exactly<int>>());
|
|
context<num?>(
|
|
nullableString?.s2 = contextType(1)..expectStaticType<Exactly<int?>>());
|
|
context<num?>(E(nullableString)?.s2 = contextType(1)
|
|
..expectStaticType<Exactly<int?>>());
|
|
|
|
// And just to verify that the expectations above are reasonable, repeat the
|
|
// same thing with an ordinary class:
|
|
var c = C();
|
|
context<num>(c.s3 = contextType(1)..expectStaticType<Exactly<int>>());
|
|
context<num?>(c.s4 = contextType(1)..expectStaticType<Exactly<int?>>());
|
|
var nullableC = C() as C?;
|
|
context<num?>(
|
|
nullableC?.s3 = contextType(1)..expectStaticType<Exactly<int>>());
|
|
context<num?>(
|
|
nullableC?.s4 = contextType(1)..expectStaticType<Exactly<int?>>());
|
|
}
|