blob: f5c34583f2a30125eb97c8cf9fdf52e9268b3a0b [file] [log] [blame]
// Copyright (c) 2019, 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 Note that neither the regular spread nor the null-aware spread
/// have any affect on [null] values inside the sequence being spread. As far as
/// the language is concerned, [null] is a perfectly valid value for a sequence
/// to contain:
///
/// var things = [2, null, 3];
/// var more = [1, ...things, 4]; // [1, 2, null, 3, 4].
/// var also = [1, ...?things, 4]; // [1, 2, null, 3, 4].
///
/// If you want to skip over [null] elements in a sequence, you can do so
/// explicitly:
///
/// var things = [2, null, 3];
/// var more = [1, ...things.where((thing) => thing != null), 4];
/// // [1, 2, 3, 4].
/// @description Checks that [null] element is allowed inside the spreadable
/// element in the map.
/// @author iarkh@unipro.ru
import "../../Utils/expect.dart";
Map things = {1: 2, 2: null, 3: 3};
main() {
Map more = {4: 4, ...things, 5: 10};
Expect.mapEquals({4: 4, 1: 2, 2: null, 3: 3, 5: 10}, more);
Map more1 = {4: 4, ...?things, 5: 10};
// ^^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '...?' has type 'Map<dynamic, dynamic>' which excludes null.
Expect.mapEquals({4: 4, 1: 2, 2: null, 3: 3, 5: 10}, more1);
}