dart-sdk/tests/language/type_variable/static_context_test.dart
Robert Nystrom 51fe275a62 Migrate "t" directory language tests off @compile-error.
The "@compile-error" comment is an old not-great way of defining static
error tests.

See: https://github.com/dart-lang/sdk/issues/45634
Change-Id: I4c2840deffe5d790a22facebbcc8a02c1cb98020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296425
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2023-04-20 19:55:31 +00:00

25 lines
808 B
Dart

// Copyright (c) 2012, 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.
// A type variable can't be referenced in a static class
class A<T> {
static int method() {
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY
// [cfe] A non-null value must be returned since the return type 'int' doesn't allow null.
// error, can't reference a type variable in a static context
var foo = new T();
// ^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC
// [cfe] Couldn't find constructor 'T'.
}
}
main() {
A.method();
}