// 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. // Tests local inference errors for the `out` variance modifier. // SharedOptions=--enable-experiment=variance class Covariant {} class Exactly {} class Upper {} class Middle extends Upper {} class Lower extends Middle {} class CovBound { CovBound(T x, void Function(T) y) {} } Exactly inferCovCov(Covariant x, Covariant y) => new Exactly(); Exactly inferCovBound(CovBound x) => new Exactly(); main() { Exactly upper; Exactly middle; Exactly lower; // Lower <: T <: Middle. // We choose Middle. var inferredMiddle = inferCovCov(Covariant(), Covariant()); lower = inferredMiddle; // ^^^^^^^^^^^^^^ // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT // [cfe] A value of type 'Exactly' can't be assigned to a variable of type 'Exactly'. // Lower <: T <: Upper. // We choose Upper. var inferredUpper = inferCovCov(Covariant(), Covariant()); lower = inferredUpper; // ^^^^^^^^^^^^^ // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT // [cfe] A value of type 'Exactly' can't be assigned to a variable of type 'Exactly'. // Inference for Covbound(...) produces Lower <: T <: Upper. // Since T is covariant, we choose Lower as the solution. var inferredCovLower = inferCovBound(CovBound(Lower(), (Upper x) {})); upper = inferredCovLower; // ^^^^^^^^^^^^^^^^ // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT // [cfe] A value of type 'Exactly' can't be assigned to a variable of type 'Exactly'. // Inference for Covbound(...) produces Lower <: T <: Middle. // Since T is covariant, we choose Lower as the solution. var inferredCovLower2 = inferCovBound(CovBound(Lower(), (Middle x) {})); middle = inferredCovLower2; // ^^^^^^^^^^^^^^^^^ // [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT // [cfe] A value of type 'Exactly' can't be assigned to a variable of type 'Exactly'. }