// 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 '../../static_type_helper.dart'; // This test checks whether a local boolean variable can be used to perform type // promotion, for various ways of declaring and assigning to it. // // For the boolean, we test all combinations of: // - type `bool`, `Object`, `Object?`, or `dynamic` // - late or non-late // - final or non-final // - assigned at initialization time or later // For the promoted variable, we test all combinations of: // - parameter, unmodified from its initial value // - parameter, assigned later // - local variable, assigned at initialization // - local variable, assigned later parameterUnmodified(int? x) { { late final bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final bool b = x != null; if (b) x.expectStaticType>(); } { final bool b; b = x != null; if (b) x.expectStaticType>(); } { bool b = x != null; if (b) x.expectStaticType>(); } { bool b; b = x != null; if (b) x.expectStaticType>(); } { late final Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final dynamic b = x != null; if (b) x.expectStaticType>(); } { final dynamic b; b = x != null; if (b) x.expectStaticType>(); } { dynamic b = x != null; if (b) x.expectStaticType>(); } { dynamic b; b = x != null; if (b) x.expectStaticType>(); } } parameterModifiedLater(int? x, int? y) { x = y; { late final bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final bool b = x != null; if (b) x.expectStaticType>(); } { final bool b; b = x != null; if (b) x.expectStaticType>(); } { bool b = x != null; if (b) x.expectStaticType>(); } { bool b; b = x != null; if (b) x.expectStaticType>(); } { late final Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final dynamic b = x != null; if (b) x.expectStaticType>(); } { final dynamic b; b = x != null; if (b) x.expectStaticType>(); } { dynamic b = x != null; if (b) x.expectStaticType>(); } { dynamic b; b = x != null; if (b) x.expectStaticType>(); } } localVariableInitialized(int? y) { int? x = y; { late final bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final bool b = x != null; if (b) x.expectStaticType>(); } { final bool b; b = x != null; if (b) x.expectStaticType>(); } { bool b = x != null; if (b) x.expectStaticType>(); } { bool b; b = x != null; if (b) x.expectStaticType>(); } { late final Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final dynamic b = x != null; if (b) x.expectStaticType>(); } { final dynamic b; b = x != null; if (b) x.expectStaticType>(); } { dynamic b = x != null; if (b) x.expectStaticType>(); } { dynamic b; b = x != null; if (b) x.expectStaticType>(); } } localVariableModifiedLater(int? y) { int? x; x = y; { late final bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late bool b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late bool b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final bool b = x != null; if (b) x.expectStaticType>(); } { final bool b; b = x != null; if (b) x.expectStaticType>(); } { bool b = x != null; if (b) x.expectStaticType>(); } { bool b; b = x != null; if (b) x.expectStaticType>(); } { late final Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late Object? b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b as bool) x.expectStaticType>(); } { late Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { final Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { Object? b; b = x != null; // We don't currently recognize that `b as bool` has the same value as `b`, // so we don't promote. TODO(paulberry): should we? if (b as bool) x.expectStaticType>(); } { late final dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late final dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { late dynamic b = x != null; // We don't promote based on the initializers of late locals because we // don't know when they execute. if (b) x.expectStaticType>(); } { late dynamic b; b = x != null; // We do promote based on assignments to late locals because we do know when // they execute. if (b) x.expectStaticType>(); } { final dynamic b = x != null; if (b) x.expectStaticType>(); } { final dynamic b; b = x != null; if (b) x.expectStaticType>(); } { dynamic b = x != null; if (b) x.expectStaticType>(); } { dynamic b; b = x != null; if (b) x.expectStaticType>(); } } main() { parameterUnmodified(null); parameterUnmodified(0); parameterModifiedLater(null, null); parameterModifiedLater(null, 0); localVariableInitialized(null); localVariableInitialized(0); localVariableModifiedLater(null); localVariableModifiedLater(0); }