|
| 1 | +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:analyzer/src/dart/analysis/experiments.dart'; |
| 6 | +import 'package:analyzer/src/error/codes.dart'; |
| 7 | +import 'package:analyzer/src/generated/engine.dart'; |
| 8 | +import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 9 | + |
| 10 | +import '../dart/resolution/driver_resolution.dart'; |
| 11 | + |
| 12 | +main() { |
| 13 | + defineReflectiveSuite(() { |
| 14 | + defineReflectiveTests(NotInitializedNonNullableStaticFieldTest); |
| 15 | + }); |
| 16 | +} |
| 17 | + |
| 18 | +@reflectiveTest |
| 19 | +class NotInitializedNonNullableStaticFieldTest extends DriverResolutionTest { |
| 20 | + @override |
| 21 | + AnalysisOptionsImpl get analysisOptions => |
| 22 | + AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable]; |
| 23 | + |
| 24 | + test_futureOr_questionArgument_none() async { |
| 25 | + assertNoErrorsInCode(''' |
| 26 | +import 'dart:async'; |
| 27 | +
|
| 28 | +class A { |
| 29 | + static FutureOr<int?> v; |
| 30 | +} |
| 31 | +'''); |
| 32 | + } |
| 33 | + |
| 34 | + test_hasInitializer() async { |
| 35 | + assertNoErrorsInCode(''' |
| 36 | +class A { |
| 37 | + static int v = 0; |
| 38 | +} |
| 39 | +'''); |
| 40 | + } |
| 41 | + |
| 42 | + test_noInitializer() async { |
| 43 | + assertErrorsInCode(''' |
| 44 | +class A { |
| 45 | + static int x = 0, y, z = 2; |
| 46 | +} |
| 47 | +''', [ |
| 48 | + error(CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_STATIC_FIELD, 30, |
| 49 | + 1), |
| 50 | + ]); |
| 51 | + } |
| 52 | + |
| 53 | + test_nullable() async { |
| 54 | + assertNoErrorsInCode(''' |
| 55 | +class A { |
| 56 | + static int? v; |
| 57 | +} |
| 58 | +'''); |
| 59 | + } |
| 60 | + |
| 61 | + test_type_dynamic() async { |
| 62 | + assertNoErrorsInCode(''' |
| 63 | +class A { |
| 64 | + static dynamic v; |
| 65 | +} |
| 66 | +'''); |
| 67 | + } |
| 68 | + |
| 69 | + test_type_dynamic_implicit() async { |
| 70 | + assertNoErrorsInCode(''' |
| 71 | +class A { |
| 72 | + static var v; |
| 73 | +} |
| 74 | +'''); |
| 75 | + } |
| 76 | + |
| 77 | + test_type_never() async { |
| 78 | + assertErrorsInCode(''' |
| 79 | +class A { |
| 80 | + static Never v; |
| 81 | +} |
| 82 | +''', [ |
| 83 | + error(CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_STATIC_FIELD, 25, |
| 84 | + 1), |
| 85 | + ]); |
| 86 | + } |
| 87 | + |
| 88 | + test_type_void() async { |
| 89 | + assertNoErrorsInCode(''' |
| 90 | +class A { |
| 91 | + static void v; |
| 92 | +} |
| 93 | +'''); |
| 94 | + } |
| 95 | +} |
0 commit comments