Files
sdk/tests/language/covariant_field_implicit_setter_test.dart
Martin Kustermann e5704eacfa [dart2wasm] Fix missing type check in implicit field setters if field is covariant
For a class like this:

   class A<T> {
     T? value;
   }

the implicit setter function (`A.value=`) has to check the argument
type.

TEST=language/covariant_field_implicit_setter_test

Change-Id: Ie990b79f631275fb0a7c88ec7d7dd3a82a784148
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381000
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-08-16 11:49:19 +00:00

27 lines
683 B
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.
import 'package:expect/expect.dart';
import 'package:expect/variations.dart';
main() {
final List<A<Object>> l = [A<int>(), A<String>()];
final aInt = l[int.parse('0')];
Expect.isNull(aInt.value);
aInt.value = 10;
Expect.equals(10, aInt.value);
final aString = l[int.parse('1')];
Expect.isNull(aString.value);
if (checkedParameters) {
Expect.throws(() => aString.value = 1);
Expect.isNull(aString.value);
}
}
class A<T> {
T? value;
}