dart-sdk/tests/language/extension_methods/static_extension_property_set_context_test.dart
Paul Berry 4d1c8b09cb Fix context for the RHS of the invocation of an extension setter to match analyzer.
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>
2024-02-21 15:10:18 +00:00

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?>>());
}