mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:09:49 +00:00
48608ce9bc
Change-Id: I8e21f82dc241a63f78fb1f6a25669b1aa633788c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152080 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
92 lines
3.1 KiB
Dart
92 lines
3.1 KiB
Dart
// 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 erroneous field usage for the `in` variance modifier.
|
|
|
|
// SharedOptions=--enable-experiment=variance
|
|
|
|
class A<in T> {
|
|
final T a = throw "uncalled";
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
final T Function() b = () => throw "uncalled";
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
T get c => throw "uncalled";
|
|
//^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// ^
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position in the return type.
|
|
|
|
late T d;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
covariant late T e;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
T? f = null;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
}
|
|
|
|
mixin BMixin<in T> {
|
|
final T a = throw "uncalled";
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
final T Function() b = () => throw "uncalled";
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
T get c => throw "uncalled";
|
|
//^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// ^
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position in the return type.
|
|
|
|
late T d;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
covariant late T e;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
|
|
T? f = null;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
}
|
|
|
|
abstract class C<in T> {
|
|
T get a;
|
|
//^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// ^
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position in the return type.
|
|
}
|
|
|
|
class D<in T> extends C<T> {
|
|
var a;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD
|
|
// [cfe] Can't use 'in' type variable 'T' in an 'out' position.
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.WRONG_TYPE_PARAMETER_VARIANCE_POSITION
|
|
// [cfe] Field 'a' should be initialized because its type 'T' doesn't allow null.
|
|
}
|