mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 01:28:21 +00:00
654b725ee4
Also splits up cast_test to test collections separately and updates corelib_2 version with the same changes, including fixes in relevant pending CL: https://dart-review.googlesource.com/c/sdk/+/126320 Fixes #39517 Bug: http://dartbug.com/39517 Change-Id: I8df1fde1d48ed23561ce9d0d8b87d7fc2ba52eb1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144469 Commit-Queue: Riley Porter <rileyporter@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
37 lines
1.1 KiB
Dart
37 lines
1.1 KiB
Dart
// Copyright (c) 2020, 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 "dart:collection";
|
|
import 'cast_helper.dart';
|
|
|
|
void main() {
|
|
testSetDowncast();
|
|
testMapDowncast();
|
|
}
|
|
|
|
void testSetDowncast() {
|
|
var setEls = new Set<C?>.from(elements);
|
|
var dSet = Set.castFrom<C?, D?>(setEls);
|
|
|
|
var newC = new C();
|
|
dSet.add(newC);
|
|
// ^^^^
|
|
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
|
// [cfe] The argument type 'C' can't be assigned to the parameter type 'D?'.
|
|
}
|
|
|
|
void testMapDowncast() {
|
|
var map = new Map.fromIterables(elements, elements);
|
|
var dMap = Map.castFrom<C?, C?, D?, D?>(map);
|
|
|
|
dMap[c] = d;
|
|
// ^
|
|
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
|
// [cfe] A value of type 'C' can't be assigned to a variable of type 'D?'.
|
|
dMap[d] = c;
|
|
// ^
|
|
// [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT
|
|
// [cfe] A value of type 'C' can't be assigned to a variable of type 'D?'.
|
|
}
|