mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
Generate a diagnostic for language overrides prior to 2.12
Change-Id: Ia10cf89443208ef133dd1ce8d68ee7c6b4129fbb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276800 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Stephen Adams <sra@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
88400bdc42
commit
14ff1f2d35
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
const null0 = /*cfe.Null()*/ null;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
String method() => 'foo';
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
T method1<T>(T t) => t;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
const list0 = /*cfe.List<dynamic>()*/ [];
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
const map0 = /*cfe.Map<dynamic,dynamic>()*/ {};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
// ignore: sdk_version_set_literal
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
const null0 = /*cfe.Null()*/ null;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
String method() => 'foo';
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
T method1<T>(T t) => t;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
const list0 = /*cfe.List<dynamic>()*/ [];
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
const map0 = /*cfe.Map<dynamic,dynamic>()*/ {};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
// ignore: sdk_version_set_literal
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.7
|
||||
|
||||
import 'dart:async';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*class: A:A,Object*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.5
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.5
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.5
|
||||
|
||||
import 'opt_in.dart';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.5
|
||||
|
||||
/*class: Map:Map<K*, V*>,Object*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.5
|
||||
import 'opt_in.dart';
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.5
|
||||
|
||||
/*class: Legacy:Legacy,Object*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.5
|
||||
import 'opt_in.dart';
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
import "opt_in.dart";
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*class: A:A<T*>,Object*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*class: LegacyClass:LegacyClass,Object*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.5
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.5
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
import 'opt_in.dart';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*class: Class1:Class1,Object*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
/*library: nnbd=false*/
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*class: Sink:Object,Sink<T*>*/
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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.
|
||||
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart=2.6
|
||||
|
||||
/*library: nnbd=false*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -288,14 +289,16 @@ void f() {
|
|||
}
|
||||
|
||||
Future<void> test_constructor_single_closure_nnbd_into_legacy() async {
|
||||
addSource('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
addSource('$testPackageLibPath/a.dart', r'''
|
||||
typedef int Callback(int? a);
|
||||
|
||||
class A {
|
||||
A({required Callback callback}) {}
|
||||
}
|
||||
''');
|
||||
await resolveTestCode('''
|
||||
await resolveTestCode('''
|
||||
// @dart = 2.8
|
||||
import 'package:test/a.dart';
|
||||
|
||||
|
@ -304,7 +307,7 @@ void f() {
|
|||
print(a);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
await assertHasFix('''
|
||||
// @dart = 2.8
|
||||
import 'package:test/a.dart';
|
||||
|
||||
|
@ -313,6 +316,9 @@ void f() {
|
|||
print(a);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> test_constructor_single_list() async {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/services/correction/fix.dart';
|
||||
import 'package:analysis_server/src/services/linter/lint_names.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -123,13 +124,15 @@ class B extends A<int> {
|
|||
}
|
||||
|
||||
Future<void> test_method_nullSafety_optIn_fromOptOut() async {
|
||||
createAnalysisOptionsFile(lints: [lintCode]);
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
createAnalysisOptionsFile(lints: [lintCode]);
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
int foo() => 0;
|
||||
}
|
||||
''');
|
||||
await resolveTestCode('''
|
||||
await resolveTestCode('''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -138,13 +141,16 @@ class B extends A {
|
|||
int foo() => super.foo();
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
await assertHasFix('''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
class B extends A {
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> test_method_toString() async {
|
||||
|
|
|
@ -579,7 +579,7 @@ int bar = 1; // 4
|
|||
|
||||
Future<void> test_topLevel_languageVersion_dartDoc() async {
|
||||
await resolveTestCode('''
|
||||
// @dart = 2.8
|
||||
// @dart = 2.19
|
||||
|
||||
/// 1
|
||||
int foo = 1; // 2
|
||||
|
@ -595,7 +595,7 @@ int bar = 1; // 4
|
|||
|
||||
Future<void> test_topLevel_languageVersion_noDartDoc() async {
|
||||
await resolveTestCode('''
|
||||
// @dart = 2.8
|
||||
// @dart = 2.19
|
||||
|
||||
int foo = 1; // 2
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ If you need an unresolved AST, then you can use the following method to access
|
|||
the AST:
|
||||
|
||||
```dart
|
||||
void processFile(AnalysisSession session, String path) async {
|
||||
Future<void> processFile(AnalysisSession session, String path) async {
|
||||
var result = session.getParsedUnit(path);
|
||||
if (result is ParsedUnitResult) {
|
||||
CompilationUnit unit = result.unit;
|
||||
|
@ -66,7 +66,7 @@ If you need a resolved AST, then you need to use the following asynchronous
|
|||
method to access it:
|
||||
|
||||
```dart
|
||||
void processFile(AnalysisSession session, String path) async {
|
||||
Future<void> processFile(AnalysisSession session, String path) async {
|
||||
var result = await session.getResolvedUnit(path);
|
||||
if (result is ResolvedUnitResult) {
|
||||
CompilationUnit unit = result.unit;
|
||||
|
@ -102,7 +102,7 @@ void printMembers(CompilationUnit unit) {
|
|||
if (classMember.name == null) {
|
||||
print(' ${unitMember.name.lexeme}');
|
||||
} else {
|
||||
print(' ${unitMember.name.lexeme}.${classMember.name.lexeme}');
|
||||
print(' ${unitMember.name.lexeme}.${classMember.name!.lexeme}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,11 +75,7 @@ void printMembers(CompilationUnitElement unitElement) {
|
|||
print(classElement.name);
|
||||
for (ConstructorElement constructorElement in classElement.constructors) {
|
||||
if (!constructorElement.isSynthetic) {
|
||||
if (constructorElement.name == null) {
|
||||
print(' ${constructorElement.name}');
|
||||
} else {
|
||||
print(' ${classElement.name}.${constructorElement.name}');
|
||||
}
|
||||
print(' ${constructorElement.displayName}');
|
||||
}
|
||||
}
|
||||
for (FieldElement fieldElement in classElement.fields) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import 'package:analyzer/src/generated/constant.dart';
|
|||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/services/lint.dart';
|
||||
import 'package:analyzer/src/summary/api_signature.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
||||
export 'package:analyzer/dart/analysis/analysis_options.dart';
|
||||
|
@ -157,7 +158,8 @@ class AnalysisOptionsImpl implements AnalysisOptions {
|
|||
|
||||
/// The constraint on the language version for every Dart file.
|
||||
/// Violations will be reported as analysis errors.
|
||||
VersionConstraint? sourceLanguageConstraint;
|
||||
VersionConstraint? sourceLanguageConstraint =
|
||||
noSoundNullSafety ? VersionConstraint.parse('>= 2.12.0') : null;
|
||||
|
||||
ExperimentStatus _contextFeatures = ExperimentStatus();
|
||||
|
||||
|
|
|
@ -2851,13 +2851,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
languageVersionToken,
|
||||
['$sourceLanguageConstraint'],
|
||||
);
|
||||
} else {
|
||||
errorReporter.reportErrorForOffset(
|
||||
CompileTimeErrorCode.ILLEGAL_LANGUAGE_VERSION_OVERRIDE,
|
||||
0,
|
||||
0,
|
||||
['$sourceLanguageConstraint'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:analyzer/src/dart/element/element.dart';
|
|||
import 'package:analyzer/src/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/element/type_system.dart';
|
||||
import 'package:analyzer/src/dart/error/ffi_code.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
|
||||
/// A visitor used to find problems with the way the `dart:ffi` APIs are being
|
||||
/// used. See 'pkg/vm/lib/transformations/ffi_checks.md' for the specification
|
||||
|
@ -172,7 +173,9 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
|
||||
if (!typeSystem.isNonNullableByDefault && inCompound) {
|
||||
if (!noSoundNullSafety &&
|
||||
!typeSystem.isNonNullableByDefault &&
|
||||
inCompound) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
FfiCode.FIELD_INITIALIZER_IN_STRUCT,
|
||||
node,
|
||||
|
@ -1022,7 +1025,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
|
||||
if (!typeSystem.isNonNullableByDefault) {
|
||||
if (!noSoundNullSafety && !typeSystem.isNonNullableByDefault) {
|
||||
for (VariableDeclaration field in fields.variables) {
|
||||
if (field.initializer != null) {
|
||||
_errorReporter.reportErrorForToken(
|
||||
|
|
|
@ -6112,7 +6112,7 @@ CompileTimeErrorCode:
|
|||
|
||||
```dart
|
||||
%uri="lib/part.dart"
|
||||
// @dart = 2.6
|
||||
// @dart = 2.14
|
||||
part of 'test.dart';
|
||||
```
|
||||
|
||||
|
@ -6120,7 +6120,7 @@ CompileTimeErrorCode:
|
|||
must have the same language version as the defining compilation unit:
|
||||
|
||||
```dart
|
||||
// @dart = 2.5
|
||||
// @dart = 2.15
|
||||
part [!'part.dart'!];
|
||||
```
|
||||
|
||||
|
@ -19104,7 +19104,7 @@ HintCode:
|
|||
the word `dart` and the version number:
|
||||
|
||||
```dart
|
||||
[!// @Dart 2.9!]
|
||||
[!// @Dart 2.13!]
|
||||
```
|
||||
|
||||
#### Common fixes
|
||||
|
@ -19113,7 +19113,7 @@ HintCode:
|
|||
the comment to follow the correct format:
|
||||
|
||||
```dart
|
||||
// @dart = 2.9
|
||||
// @dart = 2.13
|
||||
```
|
||||
INVALID_LANGUAGE_VERSION_OVERRIDE_LOCATION:
|
||||
sharedName: INVALID_LANGUAGE_VERSION_OVERRIDE
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:analyzer/dart/element/element.dart';
|
|||
import 'package:analyzer/src/dart/element/member.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -1492,7 +1493,9 @@ bool test(C c) => c.method<bool>(arg: true);
|
|||
}
|
||||
|
||||
test_genericTypeAlias_castsAndTypeChecks_hasTypeParameters() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.9
|
||||
typedef Foo<S> = S Function<T>(T x);
|
||||
|
||||
|
@ -1507,10 +1510,15 @@ main(Object p) {
|
|||
}
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_genericTypeAlias_castsAndTypeChecks_noTypeParameters() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.9
|
||||
typedef Foo = T Function<T>(T x);
|
||||
|
||||
|
@ -1521,6 +1529,9 @@ main(Object p) {
|
|||
}
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_genericTypeAlias_fieldAndReturnType_noTypeParameters() async {
|
||||
|
@ -3123,7 +3134,9 @@ main(Object p) {
|
|||
}
|
||||
|
||||
test_typePromotion_if_is_and_subThenSuper() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
class A {
|
||||
var a;
|
||||
|
@ -3138,6 +3151,9 @@ main(Object p) {
|
|||
}
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_typePromotion_if_is_parenthesized() async {
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:analyzer/src/dart/constant/value.dart';
|
|||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_element.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -23,7 +24,9 @@ main() {
|
|||
@reflectiveTest
|
||||
class ConstantResolutionTest extends PubPackageResolutionTest {
|
||||
test_constructor_nullSafe_fromLegacy_super() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
const A(List<Object> a);
|
||||
}
|
||||
|
@ -33,7 +36,7 @@ class B extends A {
|
|||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.8
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -41,19 +44,24 @@ const a = <dynamic>[];
|
|||
const b = B(a);
|
||||
''');
|
||||
|
||||
var b = findElement.topVar('b');
|
||||
assertType(b.computeConstantValue()!.type, 'B*');
|
||||
var b = findElement.topVar('b');
|
||||
assertType(b.computeConstantValue()!.type, 'B*');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_constructor_nullSafe_fromLegacy_this() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
const A(List<Object> a) : this(a);
|
||||
const A.second(List<Object> a);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.8
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -61,8 +69,11 @@ const a = <dynamic>[];
|
|||
const b = A(a);
|
||||
''');
|
||||
|
||||
var b = findElement.topVar('b');
|
||||
assertType(b.computeConstantValue()!.type, 'A*');
|
||||
var b = findElement.topVar('b');
|
||||
assertType(b.computeConstantValue()!.type, 'A*');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_context_eliminateTypeVariables() async {
|
||||
|
@ -87,25 +98,32 @@ class A<T, U> {
|
|||
}
|
||||
|
||||
test_field_optIn_fromOptOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
static const foo = 42;
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.5
|
||||
import 'a.dart';
|
||||
|
||||
const bar = A.foo;
|
||||
''');
|
||||
|
||||
var bar = findElement.topVar('bar');
|
||||
_assertIntValue(bar, 42);
|
||||
var bar = findElement.topVar('bar');
|
||||
_assertIntValue(bar, 42);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_fromEnvironment_optOut_fromOptIn() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.5
|
||||
|
||||
const cBool = const bool.fromEnvironment('foo', defaultValue: false);
|
||||
|
@ -113,81 +131,100 @@ const cInt = const int.fromEnvironment('foo', defaultValue: 1);
|
|||
const cString = const String.fromEnvironment('foo', defaultValue: 'bar');
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
const vBool = cBool;
|
||||
const vInt = cInt;
|
||||
const vString = cString;
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
DartObjectImpl evaluate(String name) {
|
||||
return findElement.topVar(name).computeConstantValue() as DartObjectImpl;
|
||||
DartObjectImpl evaluate(String name) {
|
||||
return findElement.topVar(name).computeConstantValue()
|
||||
as DartObjectImpl;
|
||||
}
|
||||
|
||||
expect(evaluate('vBool').toBoolValue(), false);
|
||||
expect(evaluate('vInt').toIntValue(), 1);
|
||||
expect(evaluate('vString').toStringValue(), 'bar');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
|
||||
expect(evaluate('vBool').toBoolValue(), false);
|
||||
expect(evaluate('vInt').toIntValue(), 1);
|
||||
expect(evaluate('vString').toStringValue(), 'bar');
|
||||
}
|
||||
|
||||
test_topLevelVariable_optIn_fromOptOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
const foo = 42;
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.5
|
||||
import 'a.dart';
|
||||
|
||||
const bar = foo;
|
||||
''');
|
||||
|
||||
var bar = findElement.topVar('bar');
|
||||
assertType(bar.type, 'int*');
|
||||
_assertIntValue(bar, 42);
|
||||
var bar = findElement.topVar('bar');
|
||||
assertType(bar.type, 'int*');
|
||||
_assertIntValue(bar, 42);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_topLevelVariable_optOut2() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
const a = 42;
|
||||
''');
|
||||
|
||||
newFile('$testPackageLibPath/b.dart', r'''
|
||||
newFile('$testPackageLibPath/b.dart', r'''
|
||||
import 'a.dart';
|
||||
|
||||
const b = a;
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.5
|
||||
import 'b.dart';
|
||||
|
||||
const c = b;
|
||||
''');
|
||||
|
||||
var c = findElement.topVar('c');
|
||||
assertType(c.type, 'int*');
|
||||
_assertIntValue(c, 42);
|
||||
var c = findElement.topVar('c');
|
||||
assertType(c.type, 'int*');
|
||||
_assertIntValue(c, 42);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_topLevelVariable_optOut3() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
const a = int.fromEnvironment('a', defaultValue: 42);
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
const b = a;
|
||||
''');
|
||||
|
||||
var c = findElement.topVar('b');
|
||||
assertType(c.type, 'int*');
|
||||
_assertIntValue(c, 42);
|
||||
var c = findElement.topVar('b');
|
||||
assertType(c.type, 'int*');
|
||||
_assertIntValue(c, 42);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _assertIntValue(VariableElement element, int value) {
|
||||
|
@ -409,14 +446,16 @@ extension E on int {
|
|||
|
||||
/// See https://github.com/dart-lang/sdk/issues/43462
|
||||
test_useLanguageVersionOfEnclosingLibrary() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class Wrapper {
|
||||
final int value;
|
||||
const Wrapper(Object value) : value = value as int;
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.4
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -424,5 +463,8 @@ void f() {
|
|||
const Wrapper(0);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'context_collection_resolution.dart';
|
||||
|
@ -17,13 +18,15 @@ main() {
|
|||
class ForEachElementTest extends PubPackageResolutionTest
|
||||
with WithoutNullSafetyMixin {
|
||||
test_optIn_fromOptOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A implements Iterable<int> {
|
||||
Iterator<int> iterator => throw 0;
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -33,6 +36,9 @@ f(A a) {
|
|||
}
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_withDeclaration_scope() async {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'context_collection_resolution.dart';
|
||||
|
@ -125,7 +126,9 @@ extension E on int {}
|
|||
}
|
||||
|
||||
test_jsonConfigDisablesExtensions_languageOverrideEnables() async {
|
||||
_configureTestWithJsonConfig('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
_configureTestWithJsonConfig('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
|
@ -139,10 +142,13 @@ extension E on int {}
|
|||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.6
|
||||
extension E on int {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analyzer/dart/ast/ast.dart';
|
|||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_element.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'context_collection_resolution.dart';
|
||||
|
@ -339,13 +340,15 @@ A
|
|||
}
|
||||
|
||||
test_optIn_fromOptOut_class() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
const A(int a);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -353,7 +356,7 @@ import 'a.dart';
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@A'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@A'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: SimpleIdentifier
|
||||
|
@ -374,17 +377,22 @@ Annotation
|
|||
base: package:test/a.dart::@class::A::@constructor::new
|
||||
isLegacy: true
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_class_constructor() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
final int a;
|
||||
const A.named(this.a);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -392,8 +400,8 @@ import 'a.dart';
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
var annotation = findNode.annotation('@A');
|
||||
assertResolvedNodeText(annotation, r'''
|
||||
var annotation = findNode.annotation('@A');
|
||||
assertResolvedNodeText(annotation, r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -427,22 +435,27 @@ Annotation
|
|||
isLegacy: true
|
||||
''');
|
||||
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
A*
|
||||
a: int 42
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_class_constructor_withDefault() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
final int a;
|
||||
const A.named({this.a = 42});
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -450,8 +463,8 @@ import 'a.dart';
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
var annotation = findNode.annotation('@A');
|
||||
assertResolvedNodeText(annotation, r'''
|
||||
var annotation = findNode.annotation('@A');
|
||||
assertResolvedNodeText(annotation, r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -478,21 +491,26 @@ Annotation
|
|||
isLegacy: true
|
||||
''');
|
||||
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
A*
|
||||
a: int 42
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_class_getter() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
static const foo = 42;
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -500,7 +518,7 @@ import 'a.dart';
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@A'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@A'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -524,19 +542,24 @@ Annotation
|
|||
isLegacy: true
|
||||
''');
|
||||
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
int 42
|
||||
variable: package:test/a.dart::@class::A::@field::foo
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_getter() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
const foo = 42;
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -544,7 +567,7 @@ import 'a.dart';
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@foo'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@foo'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: SimpleIdentifier
|
||||
|
@ -558,21 +581,26 @@ Annotation
|
|||
isLegacy: true
|
||||
''');
|
||||
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
_assertElementAnnotationValueText(
|
||||
findElement.function('f').metadata[0], r'''
|
||||
int 42
|
||||
variable: package:test/a.dart::@variable::foo
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_prefix_class() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
const A(int a);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart' as a;
|
||||
|
||||
|
@ -580,7 +608,7 @@ import 'a.dart' as a;
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@a.A'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@a.A'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -609,16 +637,21 @@ Annotation
|
|||
base: package:test/a.dart::@class::A::@constructor::new
|
||||
isLegacy: true
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_prefix_class_constructor() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
const A.named(int a);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart' as a;
|
||||
|
||||
|
@ -626,7 +659,7 @@ import 'a.dart' as a;
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@a.A'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@a.A'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -662,16 +695,21 @@ Annotation
|
|||
base: package:test/a.dart::@class::A::@constructor::named
|
||||
isLegacy: true
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_prefix_class_getter() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
static const foo = 0;
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart' as a;
|
||||
|
||||
|
@ -679,7 +717,7 @@ import 'a.dart' as a;
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@a.A'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@a.A'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -705,14 +743,19 @@ Annotation
|
|||
base: package:test/a.dart::@class::A::@getter::foo
|
||||
isLegacy: true
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_prefix_getter() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
const foo = 0;
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart' as a;
|
||||
|
||||
|
@ -720,7 +763,7 @@ import 'a.dart' as a;
|
|||
void f() {}
|
||||
''');
|
||||
|
||||
assertResolvedNodeText(findNode.annotation('@a'), r'''
|
||||
assertResolvedNodeText(findNode.annotation('@a'), r'''
|
||||
Annotation
|
||||
atSign: @
|
||||
name: PrefixedIdentifier
|
||||
|
@ -743,6 +786,9 @@ Annotation
|
|||
base: package:test/a.dart::@getter::foo
|
||||
isLegacy: true
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_value_class_inference_namedConstructor() async {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test/expect.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -21,11 +22,13 @@ main() {
|
|||
class MethodInvocationResolutionTest extends PubPackageResolutionTest
|
||||
with MethodInvocationResolutionTestCases {
|
||||
test_hasReceiver_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
|
@ -33,11 +36,11 @@ main() {
|
|||
a.loadLibrary();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 22, 8),
|
||||
]);
|
||||
error(HintCode.UNUSED_IMPORT, 22, 8),
|
||||
]);
|
||||
|
||||
var node = findNode.methodInvocation('loadLibrary()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
var node = findNode.methodInvocation('loadLibrary()');
|
||||
assertResolvedNodeText(node, r'''
|
||||
MethodInvocation
|
||||
target: SimpleIdentifier
|
||||
token: a
|
||||
|
@ -56,6 +59,9 @@ MethodInvocation
|
|||
staticInvokeType: Future<dynamic>* Function()*
|
||||
staticType: Future<dynamic>*
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_hasReceiver_interfaceQ_Function_call_checked() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'context_collection_resolution.dart';
|
||||
|
@ -18,11 +19,13 @@ main() {
|
|||
class PrefixedIdentifierResolutionTest extends PubPackageResolutionTest
|
||||
with PrefixedIdentifierResolutionTestCases {
|
||||
test_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart' deferred as a;
|
||||
|
||||
|
@ -30,19 +33,22 @@ main() {
|
|||
a.loadLibrary;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNUSED_IMPORT, 22, 8),
|
||||
]);
|
||||
error(HintCode.UNUSED_IMPORT, 22, 8),
|
||||
]);
|
||||
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
var import = findElement.importFind('package:test/a.dart');
|
||||
|
||||
assertPrefixedIdentifier(
|
||||
findNode.prefixed('a.loadLibrary'),
|
||||
element: elementMatcher(
|
||||
import.importedLibrary.loadLibraryFunction,
|
||||
isLegacy: true,
|
||||
),
|
||||
type: 'Future<dynamic>* Function()*',
|
||||
);
|
||||
assertPrefixedIdentifier(
|
||||
findNode.prefixed('a.loadLibrary'),
|
||||
element: elementMatcher(
|
||||
import.importedLibrary.loadLibraryFunction,
|
||||
isLegacy: true,
|
||||
),
|
||||
type: 'Future<dynamic>* Function()*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_enum_read() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'context_collection_resolution.dart';
|
||||
|
@ -35,7 +36,9 @@ enum E<T> {
|
|||
}
|
||||
|
||||
test_functionReference() async {
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
// @dart = 2.7
|
||||
import 'dart:math';
|
||||
|
||||
|
@ -46,18 +49,21 @@ class A {
|
|||
@A([min])
|
||||
main() {}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.COULD_NOT_INFER, 66, 5),
|
||||
]);
|
||||
error(CompileTimeErrorCode.COULD_NOT_INFER, 66, 5),
|
||||
]);
|
||||
|
||||
var identifier = findNode.simple('min]');
|
||||
assertElement(
|
||||
identifier,
|
||||
elementMatcher(
|
||||
findElement.importFind('dart:math').topFunction('min'),
|
||||
isLegacy: true,
|
||||
),
|
||||
);
|
||||
assertType(identifier, 'T* Function<T extends num*>(T*, T*)*');
|
||||
var identifier = findNode.simple('min]');
|
||||
assertElement(
|
||||
identifier,
|
||||
elementMatcher(
|
||||
findElement.importFind('dart:math').topFunction('min'),
|
||||
isLegacy: true,
|
||||
),
|
||||
);
|
||||
assertType(identifier, 'T* Function<T extends num*>(T*, T*)*');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_implicitCall_tearOff_nullable() async {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/dart/ast/extensions.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_element.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'context_collection_resolution.dart';
|
||||
|
@ -24,343 +25,423 @@ class TypeNameResolutionTest extends PubPackageResolutionTest
|
|||
}
|
||||
|
||||
test_optIn_fromOptOut_class() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(A a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_class_generic_toBounds() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<T extends num> {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(A a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<num*>*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<num*>*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_class_generic_toBounds_dynamic() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<T> {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(A a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<dynamic>*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<dynamic>*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_class_generic_typeArguments() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<T> {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(A<int> a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A<int> a'),
|
||||
import_a.class_('A'),
|
||||
'A<int*>*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A<int> a'),
|
||||
import_a.class_('A'),
|
||||
'A<int*>*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_functionTypeAlias() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef F = int Function(bool);
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(F a) {}
|
||||
''');
|
||||
|
||||
var element = import_a.typeAlias('F');
|
||||
var element = import_a.typeAlias('F');
|
||||
|
||||
var typeName = findNode.namedType('F a');
|
||||
assertNamedType(typeName, element, 'int* Function(bool*)*');
|
||||
var typeName = findNode.namedType('F a');
|
||||
assertNamedType(typeName, element, 'int* Function(bool*)*');
|
||||
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: [],
|
||||
);
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: [],
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_functionTypeAlias_generic_dynamic() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef F<T> = T Function(bool);
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(F a) {}
|
||||
''');
|
||||
|
||||
var element = import_a.typeAlias('F');
|
||||
var element = import_a.typeAlias('F');
|
||||
|
||||
var typeName = findNode.namedType('F a');
|
||||
assertNamedType(typeName, element, 'dynamic Function(bool*)*');
|
||||
var typeName = findNode.namedType('F a');
|
||||
assertNamedType(typeName, element, 'dynamic Function(bool*)*');
|
||||
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: ['dynamic'],
|
||||
);
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: ['dynamic'],
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_functionTypeAlias_generic_toBounds() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef F<T extends num> = T Function(bool);
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(F a) {}
|
||||
''');
|
||||
|
||||
var element = import_a.typeAlias('F');
|
||||
var element = import_a.typeAlias('F');
|
||||
|
||||
var typeName = findNode.namedType('F a');
|
||||
assertNamedType(typeName, element, 'num* Function(bool*)*');
|
||||
var typeName = findNode.namedType('F a');
|
||||
assertNamedType(typeName, element, 'num* Function(bool*)*');
|
||||
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: ['num*'],
|
||||
);
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: ['num*'],
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optIn_fromOptOut_functionTypeAlias_generic_typeArguments() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef F<T> = T Function(bool);
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import 'a.dart';
|
||||
|
||||
f(F<int> a) {}
|
||||
''');
|
||||
|
||||
var element = import_a.typeAlias('F');
|
||||
var element = import_a.typeAlias('F');
|
||||
|
||||
var typeName = findNode.namedType('F<int> a');
|
||||
assertNamedType(typeName, element, 'int* Function(bool*)*');
|
||||
var typeName = findNode.namedType('F<int> a');
|
||||
assertNamedType(typeName, element, 'int* Function(bool*)*');
|
||||
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: ['int*'],
|
||||
);
|
||||
assertTypeAlias(
|
||||
typeName.typeOrThrow,
|
||||
element: element,
|
||||
typeArguments: ['int*'],
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_class() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(A a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_class_generic_toBounds() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
class A<T extends num> {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(A a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<num*>',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<num*>',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_class_generic_toBounds_dynamic() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
class A<T> {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(A a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<dynamic>',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A a'),
|
||||
import_a.class_('A'),
|
||||
'A<dynamic>',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_class_generic_typeArguments() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
class A<T> {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(A<int> a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('A<int> a'),
|
||||
import_a.class_('A'),
|
||||
'A<int>',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('A<int> a'),
|
||||
import_a.class_('A'),
|
||||
'A<int>',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_functionTypeAlias() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
typedef F = int Function();
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(F a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('F a'),
|
||||
import_a.typeAlias('F'),
|
||||
'int* Function()',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('F a'),
|
||||
import_a.typeAlias('F'),
|
||||
'int* Function()',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_functionTypeAlias_generic_toBounds() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
typedef F<T extends num> = T Function();
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(F a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('F a'),
|
||||
import_a.typeAlias('F'),
|
||||
'num* Function()',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('F a'),
|
||||
import_a.typeAlias('F'),
|
||||
'num* Function()',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_functionTypeAlias_generic_toBounds_dynamic() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
typedef F<T> = T Function();
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(F a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('F a'),
|
||||
import_a.typeAlias('F'),
|
||||
'dynamic Function()',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('F a'),
|
||||
import_a.typeAlias('F'),
|
||||
'dynamic Function()',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_optOut_fromOptIn_functionTypeAlias_generic_typeArguments() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.7
|
||||
typedef F<T> = T Function();
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'a.dart';
|
||||
|
||||
f(F<int> a) {}
|
||||
''', [
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
|
||||
]);
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('F<int> a'),
|
||||
import_a.typeAlias('F'),
|
||||
'int* Function()',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('F<int> a'),
|
||||
import_a.typeAlias('F'),
|
||||
'int* Function()',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_typeAlias_asInstanceCreation_explicitNew_typeArguments_interfaceType_none() async {
|
||||
|
@ -437,20 +518,25 @@ void f(X<String> a, X<String?> b) {}
|
|||
}
|
||||
|
||||
test_typeAlias_asParameterType_interfaceType_none_inLegacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef X<T> = Map<int, T>;
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'a.dart';
|
||||
void f(X<String> a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('X<String>'),
|
||||
findElement.importFind('package:test/a.dart').typeAlias('X'),
|
||||
'Map<int*, String*>*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('X<String>'),
|
||||
findElement.importFind('package:test/a.dart').typeAlias('X'),
|
||||
'Map<int*, String*>*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_typeAlias_asParameterType_interfaceType_question() async {
|
||||
|
@ -473,20 +559,25 @@ void f(X<int> a, X<int?> b) {}
|
|||
}
|
||||
|
||||
test_typeAlias_asParameterType_interfaceType_question_inLegacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef X<T> = List<T?>;
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'a.dart';
|
||||
void f(X<int> a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('X<int>'),
|
||||
findElement.importFind('package:test/a.dart').typeAlias('X'),
|
||||
'List<int*>*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('X<int>'),
|
||||
findElement.importFind('package:test/a.dart').typeAlias('X'),
|
||||
'List<int*>*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_typeAlias_asParameterType_Never_none() async {
|
||||
|
@ -509,20 +600,25 @@ void f(X a, X? b) {}
|
|||
}
|
||||
|
||||
test_typeAlias_asParameterType_Never_none_inLegacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
typedef X = Never;
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'a.dart';
|
||||
void f(X a) {}
|
||||
''');
|
||||
|
||||
assertNamedType(
|
||||
findNode.namedType('X a'),
|
||||
findElement.importFind('package:test/a.dart').typeAlias('X'),
|
||||
'Null*',
|
||||
);
|
||||
assertNamedType(
|
||||
findNode.namedType('X a'),
|
||||
findElement.importFind('package:test/a.dart').typeAlias('X'),
|
||||
'Null*',
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_typeAlias_asParameterType_Never_question() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -72,15 +73,20 @@ void f<T>(Null n) {
|
|||
}
|
||||
|
||||
test_Null_preNullSafety() async {
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
// @dart=2.9
|
||||
|
||||
void f(Null n) {
|
||||
n as int;
|
||||
}
|
||||
''', [
|
||||
error(HintCode.UNNECESSARY_CAST, 33, 8),
|
||||
]);
|
||||
error(HintCode.UNNECESSARY_CAST, 33, 8),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_nullable_nonNullable() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -47,31 +48,41 @@ class C extends A implements B {}
|
|||
}
|
||||
|
||||
test_class_extends_implements_optOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class I<T> {}
|
||||
class A implements I<int> {}
|
||||
class B implements I<int?> {}
|
||||
''');
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.5
|
||||
import 'a.dart';
|
||||
|
||||
class C extends A implements B {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_class_extends_optIn_implements_optOut() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<T> {}
|
||||
|
||||
class B extends A<int> {}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.5
|
||||
import 'a.dart';
|
||||
|
||||
class C extends B implements A<int> {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_class_extends_with() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -75,17 +76,22 @@ var v = const A(null);
|
|||
}
|
||||
|
||||
test_notGeneric_null_forNonNullable_fromLegacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class C {
|
||||
final int f;
|
||||
const C(a) : f = a;
|
||||
}
|
||||
''');
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.9
|
||||
import 'a.dart';
|
||||
const a = const C(null);
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_notGeneric_null_forNonNullable_fromNullSafe() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -19,13 +20,15 @@ main() {
|
|||
@reflectiveTest
|
||||
class CouldNotInferTest extends PubPackageResolutionTest {
|
||||
test_constructor_nullSafe_fromLegacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class C<T extends Object> {
|
||||
C(T t);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.8
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -33,6 +36,9 @@ void f(dynamic a) {
|
|||
C(a);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_functionType() async {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -39,13 +40,15 @@ class DeprecatedMemberUse_BasicWorkspace_WithoutNullSafetyTest
|
|||
class DeprecatedMemberUse_BasicWorkspaceTest extends PubPackageResolutionTest
|
||||
with DeprecatedMemberUse_BasicWorkspaceTestCases {
|
||||
test_instanceCreation_namedParameter_fromLegacy() async {
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
class A {
|
||||
A({@deprecated int a}) {}
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'package:aaa/a.dart';
|
||||
|
||||
|
@ -53,16 +56,21 @@ void f() {
|
|||
A(a: 0);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 60, 1),
|
||||
]);
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 60, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_methodInvocation_namedParameter_ofFunction_fromLegacy() async {
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
void foo({@deprecated int a}) {}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'package:aaa/a.dart';
|
||||
|
||||
|
@ -70,18 +78,23 @@ void f() {
|
|||
foo(a: 0);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 62, 1),
|
||||
]);
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 62, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_methodInvocation_namedParameter_ofMethod_fromLegacy() async {
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
class A {
|
||||
void foo({@deprecated int a}) {}
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'package:aaa/a.dart';
|
||||
|
||||
|
@ -89,18 +102,23 @@ void f(A a) {
|
|||
a.foo(a: 0);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 67, 1),
|
||||
]);
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 67, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_superConstructorInvocation_namedParameter_fromLegacy() async {
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
|
||||
class A {
|
||||
A({@deprecated int a}) {}
|
||||
}
|
||||
''');
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'package:aaa/a.dart';
|
||||
|
||||
|
@ -108,8 +126,11 @@ class B extends A {
|
|||
B() : super(a: 0);
|
||||
}
|
||||
''', [
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 79, 1),
|
||||
]);
|
||||
error(HintCode.DEPRECATED_MEMBER_USE, 79, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -33,7 +34,9 @@ main() {
|
|||
}
|
||||
|
||||
test_constructor_tearoffs_disabled_grammar_pre_nnbd() async {
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
// @dart=2.9
|
||||
class Foo<X> {
|
||||
const Foo.bar();
|
||||
|
@ -43,9 +46,12 @@ main() {
|
|||
Foo<int>.bar.baz();
|
||||
}
|
||||
''', [
|
||||
error(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 83, 5),
|
||||
error(CompileTimeErrorCode.UNDEFINED_METHOD, 93, 3),
|
||||
]);
|
||||
error(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 83, 5),
|
||||
error(CompileTimeErrorCode.UNDEFINED_METHOD, 93, 3),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_nonFunctionTypeAliases_disabled() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/dart/error/ffi_code.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -17,25 +18,35 @@ main() {
|
|||
class FieldInStructWithInitializerTest extends PubPackageResolutionTest
|
||||
with WithoutNullSafetyMixin {
|
||||
test_instance_withInitializer() async {
|
||||
await assertErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Struct {
|
||||
Pointer p = nullptr;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.FIELD_IN_STRUCT_WITH_INITIALIZER, 54, 1),
|
||||
]);
|
||||
error(FfiCode.FIELD_IN_STRUCT_WITH_INITIALIZER, 54, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_instance_withInitializer2() async {
|
||||
await assertErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode(r'''
|
||||
import 'dart:ffi';
|
||||
class C extends Union {
|
||||
Pointer p = nullptr;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.FIELD_IN_STRUCT_WITH_INITIALIZER, 53, 1),
|
||||
]);
|
||||
error(FfiCode.FIELD_IN_STRUCT_WITH_INITIALIZER, 53, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_instance_withoutInitializer() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/dart/error/ffi_code.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -17,27 +18,37 @@ main() {
|
|||
class FieldInitializerInStructTest extends PubPackageResolutionTest
|
||||
with WithoutNullSafetyMixin {
|
||||
test_fieldInitializer() async {
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
import 'dart:ffi';
|
||||
class C extends Struct {
|
||||
@Int32() int f;
|
||||
C() : f = 0;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.FIELD_INITIALIZER_IN_STRUCT, 70, 5),
|
||||
]);
|
||||
error(FfiCode.FIELD_INITIALIZER_IN_STRUCT, 70, 5),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_fieldInitializer2() async {
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
import 'dart:ffi';
|
||||
class C extends Union {
|
||||
@Int32() int f;
|
||||
C() : f = 0;
|
||||
}
|
||||
''', [
|
||||
error(FfiCode.FIELD_INITIALIZER_IN_STRUCT, 69, 5),
|
||||
]);
|
||||
error(FfiCode.FIELD_INITIALIZER_IN_STRUCT, 69, 5),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_superInitializer() async {
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
// 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 'package:analyzer/dart/analysis/context_root.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:pub_semver/src/version_constraint.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -34,6 +31,7 @@ void f() {}
|
|||
}
|
||||
|
||||
test_hasOverride_less() async {
|
||||
noSoundNullSafety = true;
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
int a = null;
|
||||
|
@ -43,43 +41,15 @@ int a = null;
|
|||
}
|
||||
|
||||
test_hasPackageLanguage_less_hasOverride_greater() async {
|
||||
writeTestPackageConfig(
|
||||
PackageConfigFileBuilder(),
|
||||
languageVersion: '2.9',
|
||||
);
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.12
|
||||
// @dart = 2.14
|
||||
void f() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_hasPackageLanguage_less_noOverride_less() async {
|
||||
writeTestPackageConfig(
|
||||
PackageConfigFileBuilder(),
|
||||
languageVersion: '2.9',
|
||||
);
|
||||
|
||||
await assertErrorsInCode(r'''
|
||||
void f() {}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ILLEGAL_LANGUAGE_VERSION_OVERRIDE, 0, 0),
|
||||
]);
|
||||
}
|
||||
|
||||
test_noOverride() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f() {}
|
||||
''');
|
||||
}
|
||||
|
||||
@override
|
||||
void updateAnalysisOptions({
|
||||
required AnalysisOptionsImpl analysisOptions,
|
||||
required ContextRoot contextRoot,
|
||||
required DartSdk sdk,
|
||||
}) {
|
||||
analysisOptions.sourceLanguageConstraint =
|
||||
VersionConstraint.parse('>= 2.12.0');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -16,16 +17,21 @@ main() {
|
|||
@reflectiveTest
|
||||
class ImportOfLegacyLibraryInoNullSafeTest extends PubPackageResolutionTest {
|
||||
test_legacy_into_legacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
// @dart = 2.9
|
||||
class A {}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'a.dart';
|
||||
|
||||
void f(A a) {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_legacy_into_nullSafe() async {
|
||||
|
@ -43,15 +49,20 @@ void f(A a) {}
|
|||
}
|
||||
|
||||
test_nullSafe_into_legacy() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
import 'a.dart';
|
||||
|
||||
void f(A a) {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_nullSafe_into_nullSafe() async {
|
||||
|
|
|
@ -22,7 +22,7 @@ const a = 0;
|
|||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.8
|
||||
// @dart = 2.12
|
||||
import 'a.dart';
|
||||
|
||||
void f(int e) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
|
@ -26,15 +27,15 @@ class InconsistentLanguageVersionOverrideTest extends PubPackageResolutionTest
|
|||
test_both_different() async {
|
||||
await _checkLibraryAndPart(
|
||||
libraryContent: r'''
|
||||
// @dart = 2.5
|
||||
// @dart = 2.12
|
||||
part 'b.dart';
|
||||
''',
|
||||
partContent: r'''
|
||||
// @dart = 2.6
|
||||
// @dart = 2.13
|
||||
part of 'a.dart';
|
||||
''',
|
||||
libraryErrors: [
|
||||
error(_errorCode, 20, 8),
|
||||
error(_errorCode, 21, 8),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -42,11 +43,11 @@ part of 'a.dart';
|
|||
test_both_same() async {
|
||||
await _checkLibraryAndPart(
|
||||
libraryContent: r'''
|
||||
// @dart = 2.5
|
||||
// @dart = 2.12
|
||||
part 'b.dart';
|
||||
''',
|
||||
partContent: r'''
|
||||
// @dart = 2.5
|
||||
// @dart = 2.12
|
||||
part of 'a.dart';
|
||||
''',
|
||||
libraryErrors: [],
|
||||
|
@ -66,18 +67,23 @@ part of 'a.dart';
|
|||
}
|
||||
|
||||
test_onlyLibrary() async {
|
||||
await _checkLibraryAndPart(
|
||||
libraryContent: r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await _checkLibraryAndPart(
|
||||
libraryContent: r'''
|
||||
// @dart = 2.5
|
||||
part 'b.dart';
|
||||
''',
|
||||
partContent: r'''
|
||||
partContent: r'''
|
||||
part of 'a.dart';
|
||||
''',
|
||||
libraryErrors: [
|
||||
error(_errorCode, 20, 8),
|
||||
],
|
||||
);
|
||||
libraryErrors: [
|
||||
error(_errorCode, 20, 8),
|
||||
],
|
||||
);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_onlyPart() async {
|
||||
|
|
|
@ -49,14 +49,14 @@ int? a;
|
|||
}
|
||||
|
||||
test_lessThanPackage() async {
|
||||
_configureTestPackageLanguageVersion('2.5');
|
||||
_configureTestPackageLanguageVersion('2.19');
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.4
|
||||
// @dart = 2.18
|
||||
class A {}
|
||||
''');
|
||||
_assertUnitLanguageVersion(
|
||||
package: Version.parse('2.5.0'),
|
||||
override: Version.parse('2.4.0'),
|
||||
package: Version.parse('2.19.0'),
|
||||
override: Version.parse('2.18.0'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,21 +35,21 @@ int i = 0;
|
|||
|
||||
test_correct_withMultipleWhitespace() async {
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.0${" "}
|
||||
// @dart = 2.19${" "}
|
||||
int i = 0;
|
||||
''');
|
||||
}
|
||||
|
||||
test_correct_withoutWhitespace() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
//@dart=2.0
|
||||
//@dart=2.19
|
||||
int i = 0;
|
||||
''');
|
||||
}
|
||||
|
||||
test_correct_withWhitespace() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.0
|
||||
// @dart = 2.19
|
||||
int i = 0;
|
||||
''');
|
||||
}
|
||||
|
@ -74,9 +74,9 @@ int i = 0;
|
|||
|
||||
test_invalidOverrideFollowsValidOverride() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.0
|
||||
// @dart = 2.19
|
||||
// comment.
|
||||
// @dart >= 2.0
|
||||
// @dart >= 2.19
|
||||
int i = 0;
|
||||
''');
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ class A {}
|
|||
|
||||
test_location_beforeDeclaration() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.5
|
||||
// @dart = 2.19
|
||||
class A {}
|
||||
''');
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ int i = 0;
|
|||
|
||||
test_noWhitespace() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
//@dart=2.0
|
||||
//@dart=2.19
|
||||
int i = 0;
|
||||
''');
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ int i = 0;
|
|||
test_shebangLine() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
#!/usr/bin/dart
|
||||
// @dart = 2.0
|
||||
// @dart = 2.19
|
||||
int i = 0;
|
||||
''');
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -215,13 +216,15 @@ class B implements A {
|
|||
}
|
||||
|
||||
test_method_parameter_functionTyped_optOut_extends_optIn() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
abstract class A {
|
||||
A catchError(void Function(Object) a);
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -229,16 +232,21 @@ class B implements A {
|
|||
A catchError(void Function(dynamic) a) => this;
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_method_parameter_interfaceOptOut_concreteOptIn() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
void foo(Object a) {}
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -246,6 +254,9 @@ class B extends A {
|
|||
void foo(dynamic a);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_mixedInheritance_1() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -26,24 +27,36 @@ void f() {
|
|||
}
|
||||
|
||||
test_literal_null() async {
|
||||
await assertErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
void f() {
|
||||
null();
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 28, 4),
|
||||
]);
|
||||
error(
|
||||
CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 28, 4),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_type_Null() async {
|
||||
await assertErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
void f(Null a) {
|
||||
a();
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 34, 1),
|
||||
]);
|
||||
error(
|
||||
CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 34, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
|
@ -78,12 +79,14 @@ void f() {}
|
|||
}
|
||||
|
||||
test_constructor_legacy_argumentGiven() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
A({required int a});
|
||||
}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import "a.dart";
|
||||
|
||||
|
@ -91,15 +94,20 @@ void f() {
|
|||
A(a: 0);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_constructor_legacy_missingArgument() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
A({required int a});
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import "a.dart";
|
||||
|
||||
|
@ -107,8 +115,11 @@ void f() {
|
|||
A();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.MISSING_REQUIRED_PARAM, 46, 1),
|
||||
]);
|
||||
error(HintCode.MISSING_REQUIRED_PARAM, 46, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_constructor_nullSafe_argumentGiven() async {
|
||||
|
@ -222,10 +233,12 @@ main() {
|
|||
}
|
||||
|
||||
test_function_legacy_argumentGiven() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
void foo({required int a}) {}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import "a.dart";
|
||||
|
||||
|
@ -233,13 +246,18 @@ void f() {
|
|||
foo(a: 0);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_function_legacy_missingArgument() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
void foo({required int a}) {}
|
||||
''');
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import "a.dart";
|
||||
|
||||
|
@ -247,8 +265,11 @@ void f() {
|
|||
foo();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.MISSING_REQUIRED_PARAM, 46, 3),
|
||||
]);
|
||||
error(HintCode.MISSING_REQUIRED_PARAM, 46, 3),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_functionInvocation() async {
|
||||
|
@ -292,12 +313,14 @@ f() {
|
|||
}
|
||||
|
||||
test_method_legacy_argumentGiven() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
void foo({required int a}) {}
|
||||
}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import "a.dart";
|
||||
|
||||
|
@ -305,15 +328,20 @@ void f(A a) {
|
|||
a.foo(a: 0);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_method_legacy_missingArgument() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
void foo({required int a}) {}
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.7
|
||||
import "a.dart";
|
||||
|
||||
|
@ -321,8 +349,11 @@ void f(A a) {
|
|||
a.foo();
|
||||
}
|
||||
''', [
|
||||
error(HintCode.MISSING_REQUIRED_PARAM, 51, 3),
|
||||
]);
|
||||
error(HintCode.MISSING_REQUIRED_PARAM, 51, 3),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_typedef_function() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -36,12 +37,14 @@ dynamic f() {}
|
|||
}
|
||||
|
||||
test_function_sync_block_Never() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
Never foo() {
|
||||
throw 0;
|
||||
}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart = 2.8
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -49,6 +52,9 @@ int f() {
|
|||
foo();
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_function_sync_block_Null() async {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// 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 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -22,22 +23,27 @@ main() {
|
|||
class MixinInferenceNoPossibleSubstitutionTest extends PubPackageResolutionTest
|
||||
with MixinInferenceNoPossibleSubstitutionTestCases {
|
||||
test_valid_nonNullableMixins_legacyApplication() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<T> {}
|
||||
|
||||
mixin B<T> on A<T> {}
|
||||
mixin C<T> on A<T> {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode('''
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart=2.8
|
||||
import 'a.dart';
|
||||
|
||||
class D extends A<int> with B<int>, C {}
|
||||
''');
|
||||
|
||||
assertType(findNode.namedType('B<int>'), 'B<int*>*');
|
||||
assertType(findNode.namedType('C {}'), 'C<int*>*');
|
||||
assertType(findNode.namedType('B<int>'), 'B<int*>*');
|
||||
assertType(findNode.namedType('C {}'), 'C<int*>*');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -80,12 +81,14 @@ class B extends A {
|
|||
}
|
||||
|
||||
test_super_requiredNamed_legacySubclass_explicitConstructor() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
A({required String s});
|
||||
}
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.8
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -93,20 +96,28 @@ class B extends A {
|
|||
B();
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_super_requiredNamed_legacySubclass_implicitConstructor() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
A({required String s});
|
||||
}O
|
||||
''');
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.8
|
||||
import 'a.dart';
|
||||
|
||||
class B extends A {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_super_requiredNamed_subclass_explicit() async {
|
||||
|
@ -258,7 +269,9 @@ class B extends A {
|
|||
}
|
||||
|
||||
test_super_requiredPositional_subclass_explicit_language214() async {
|
||||
await assertErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.14
|
||||
class A {
|
||||
A(p);
|
||||
|
@ -267,8 +280,12 @@ class B extends A {
|
|||
B();
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, 58, 1),
|
||||
]);
|
||||
error(
|
||||
CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, 58, 1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_super_requiredPositional_subclass_external() async {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/dart/error/hint_codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -36,7 +37,9 @@ void f() {
|
|||
}
|
||||
|
||||
test_legacy() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart=2.9
|
||||
import 'dart:async';
|
||||
|
||||
|
@ -46,6 +49,9 @@ void f() {
|
|||
c.complete(null);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_null() async {
|
||||
|
@ -98,13 +104,18 @@ void f() {
|
|||
}
|
||||
|
||||
test_legacy() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart=2.9
|
||||
void f() {
|
||||
Future<int>.value();
|
||||
Future<int>.value(null);
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_null() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -109,7 +110,9 @@ class A<B> {
|
|||
}
|
||||
|
||||
test_optOut() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.7
|
||||
|
||||
void f() {
|
||||
|
@ -118,5 +121,8 @@ void f() {
|
|||
}
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -24,12 +25,17 @@ Never foo = (throw 42);
|
|||
}
|
||||
|
||||
test_experimentEnabled_libraryOptedOut() async {
|
||||
await verifyVersion('2.7.0', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await verifyVersion('2.7.0', r'''
|
||||
// @dart = 2.7
|
||||
Never foo = (throw 42);
|
||||
''', expectedErrors: [
|
||||
error(StaticWarningCode.SDK_VERSION_NEVER, 15, 5),
|
||||
]);
|
||||
error(StaticWarningCode.SDK_VERSION_NEVER, 15, 5),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -49,25 +50,32 @@ enum E<T extends int> {
|
|||
}
|
||||
|
||||
test_extends_optIn_fromOptOut_Null() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<X extends int> {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
class A1<T extends Null> extends A<T> {}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_extends_optIn_fromOptOut_otherTypeParameter() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
void foo<T extends U, U>() {
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -78,21 +86,29 @@ main() {
|
|||
foo<B, A>();
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_extensionOverride_optIn_fromOptOut_Null() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
extension E<X extends int> on List<X> {
|
||||
void m() {}
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
f() => E<Null>([]).m();
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_functionReference() async {
|
||||
|
@ -146,16 +162,21 @@ void f(CB<F2> a) {}
|
|||
}
|
||||
|
||||
test_instanceCreation_optIn_fromOptOut_Null() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A<X extends int> {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
f() => A<Null>();
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_metadata_matching() async {
|
||||
|
@ -222,17 +243,22 @@ void g() {
|
|||
}
|
||||
|
||||
test_methodInvocation_optIn_fromOptOut_Null() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
void m<X extends int>() {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
f() => A().m<Null>();
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_nonFunctionTypeAlias_body_typeArgument_mismatch() async {
|
||||
|
@ -340,13 +366,15 @@ foo(G g) {}
|
|||
}
|
||||
|
||||
test_redirectingConstructor_optIn_fromOptOut_Null() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
import 'test.dart';
|
||||
|
||||
class A<X extends int> implements B {}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
await assertNoErrorsInCode(r'''
|
||||
// @dart=2.6
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -354,6 +382,9 @@ class B {
|
|||
factory B() = A<Null>;
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_regression_42196() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -153,12 +154,17 @@ class C {
|
|||
}
|
||||
|
||||
test_leastUpperBoundWithNull() async {
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
// @dart = 2.9
|
||||
f(bool b, int i) => (b ? null : i).foo();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.UNDEFINED_METHOD, 50, 3),
|
||||
]);
|
||||
error(CompileTimeErrorCode.UNDEFINED_METHOD, 50, 3),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_method_undefined() async {
|
||||
|
@ -216,15 +222,20 @@ f(M m) {
|
|||
}
|
||||
|
||||
test_method_undefined_onNull() async {
|
||||
await assertErrorsInCode(r'''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode(r'''
|
||||
// @dart = 2.9
|
||||
Null f(int x) => null;
|
||||
main() {
|
||||
f(42).abs();
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.UNDEFINED_METHOD, 55, 3),
|
||||
]);
|
||||
error(CompileTimeErrorCode.UNDEFINED_METHOD, 55, 3),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_static_conditionalAccess_defined() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -46,13 +47,18 @@ f() {
|
|||
}
|
||||
|
||||
test_equal_legacyLibrary() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.5
|
||||
f(int a) {
|
||||
a == null;
|
||||
null == a;
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_equal_notNullable() async {
|
||||
|
@ -109,13 +115,18 @@ f() {
|
|||
}
|
||||
|
||||
test_notEqual_legacyLibrary() async {
|
||||
await assertNoErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertNoErrorsInCode('''
|
||||
// @dart = 2.5
|
||||
f(int a) {
|
||||
a != null;
|
||||
null != a;
|
||||
}
|
||||
''');
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_notEqual_notNullable() async {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
@ -39,7 +40,9 @@ class WrongNumberOfParametersForOperatorTest extends PubPackageResolutionTest {
|
|||
// attempting to use a binary operator with no args as part of a compound
|
||||
// assignment would crash the analyzer. Check that that doesn't happen
|
||||
// anymore.
|
||||
await assertErrorsInCode('''
|
||||
try {
|
||||
noSoundNullSafety = false;
|
||||
await assertErrorsInCode('''
|
||||
// @dart=2.9
|
||||
class C {
|
||||
C operator+() => C();
|
||||
|
@ -49,9 +52,12 @@ void f(C c) {
|
|||
c += 1;
|
||||
}
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, 35, 1),
|
||||
]);
|
||||
error(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, 35,
|
||||
1),
|
||||
]);
|
||||
} finally {
|
||||
noSoundNullSafety = true;
|
||||
}
|
||||
}
|
||||
|
||||
test_correct_number_of_parameters_binary() async {
|
||||
|
|
|
@ -84,6 +84,12 @@ class DocumentationValidator {
|
|||
'CompileTimeErrorCode.UNDEFINED_IDENTIFIER_AWAIT',
|
||||
// Produces multiple diagnostic because of poor recovery.
|
||||
'CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR',
|
||||
|
||||
// This is not reported after 2.12, and the examples don't compile after 3.0.
|
||||
'FfiCode.FIELD_INITIALIZER_IN_STRUCT',
|
||||
// This is not reported after 2.12, and the examples don't compile after 3.0.
|
||||
'FfiCode.FIELD_IN_STRUCT_WITH_INITIALIZER',
|
||||
|
||||
// This no longer works in 3.0.
|
||||
'HintCode.DEPRECATED_COLON_FOR_DEFAULT_VALUE',
|
||||
// The code has been replaced but is not yet removed.
|
||||
|
@ -96,6 +102,7 @@ class DocumentationValidator {
|
|||
// Produces two diagnostics when it should only produce one (see
|
||||
// https://github.com/dart-lang/sdk/issues/43051)
|
||||
'HintCode.UNNECESSARY_NULL_COMPARISON_FALSE',
|
||||
|
||||
// Produces two diagnostics when it should only produce one (see
|
||||
// https://github.com/dart-lang/sdk/issues/43263)
|
||||
'StaticWarningCode.DEAD_NULL_AWARE_EXPRESSION',
|
||||
|
|
|
@ -92,7 +92,6 @@ class SnippetTester {
|
|||
// API, write code to compute the list of imports so that new public API
|
||||
// will automatically be allowed.
|
||||
String imports = '''
|
||||
// @dart = 2.9
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:analyzer/dart/analysis/analysis_context.dart';
|
||||
|
@ -105,7 +104,7 @@ import 'package:analyzer/dart/element/element.dart';
|
|||
import 'package:analyzer/dart/element/visitor.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
void assertNoErrorsInCode(String s) {}
|
||||
Future<void> assertNoErrorsInCode(String s) async {}
|
||||
void test(String s, void Function() f) {}
|
||||
void group(String s, void Function() f) {}
|
||||
''';
|
||||
|
|
|
@ -7619,7 +7619,7 @@ the one being used for the library to which the part belongs.
|
|||
Given a [part file][] named `part.dart` that contains the following:
|
||||
|
||||
{% prettify dart tag=pre+code %}
|
||||
// @dart = 2.6
|
||||
// @dart = 2.14
|
||||
part of 'test.dart';
|
||||
{% endprettify %}
|
||||
|
||||
|
@ -7627,7 +7627,7 @@ The following code produces this diagnostic because the parts of a library
|
|||
must have the same language version as the defining compilation unit:
|
||||
|
||||
{% prettify dart tag=pre+code %}
|
||||
// @dart = 2.5
|
||||
// @dart = 2.15
|
||||
part [!'part.dart'!];
|
||||
{% endprettify %}
|
||||
|
||||
|
@ -9001,7 +9001,7 @@ be lowercase in such a comment and because there's no equal sign between
|
|||
the word `dart` and the version number:
|
||||
|
||||
{% prettify dart tag=pre+code %}
|
||||
[!// @Dart 2.9!]
|
||||
[!// @Dart 2.13!]
|
||||
{% endprettify %}
|
||||
|
||||
#### Common fixes
|
||||
|
@ -9010,7 +9010,7 @@ If the comment is intended to be a language version override, then change
|
|||
the comment to follow the correct format:
|
||||
|
||||
{% prettify dart tag=pre+code %}
|
||||
// @dart = 2.9
|
||||
// @dart = 2.13
|
||||
{% endprettify %}
|
||||
|
||||
### invalid_literal_annotation
|
||||
|
|
|
@ -28,6 +28,7 @@ import 'package:analyzer/src/source/path_filter.dart';
|
|||
import 'package:analyzer/src/task/options.dart';
|
||||
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
|
||||
import 'package:analyzer/src/util/yaml.dart';
|
||||
import 'package:analyzer/src/utilities/legacy.dart';
|
||||
import 'package:analyzer_cli/src/analyzer_impl.dart';
|
||||
import 'package:analyzer_cli/src/batch_mode.dart';
|
||||
import 'package:analyzer_cli/src/error_formatter.dart';
|
||||
|
@ -94,6 +95,7 @@ class Driver implements CommandLineStarter {
|
|||
}
|
||||
_isStarted = true;
|
||||
var startTime = DateTime.now().millisecondsSinceEpoch;
|
||||
noSoundNullSafety = false;
|
||||
|
||||
linter.registerLintRules();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ analyzer:
|
|||
todo: ignore
|
||||
# Allow deprecated calls from within the same package
|
||||
deprecated_member_use_from_same_package: ignore
|
||||
illegal_language_version_override: ignore
|
||||
|
||||
linter:
|
||||
rules:
|
||||
|
|
|
@ -6,6 +6,7 @@ analyzer:
|
|||
errors:
|
||||
todo: ignore
|
||||
deprecated_member_use: ignore
|
||||
illegal_language_version_override: ignore
|
||||
|
||||
exclude:
|
||||
- '**/data/*'
|
||||
|
|
|
@ -6,6 +6,7 @@ analyzer:
|
|||
errors:
|
||||
todo: ignore
|
||||
deprecated_member_use: ignore
|
||||
illegal_language_version_override: ignore
|
||||
unused_local_variable: ignore
|
||||
unused_field: ignore
|
||||
unused_element: ignore
|
||||
|
|
|
@ -18,7 +18,10 @@ const Timeout longTimeout = Timeout(Duration(minutes: 5));
|
|||
|
||||
/// This version of dart is the last guaranteed pre-null safety language
|
||||
/// version:
|
||||
const String dartVersionFilePrefix2_9 = '// @dart = 2.9\n';
|
||||
const String dartVersionFilePrefix2_9 = '''
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.9
|
||||
''';
|
||||
|
||||
void initGlobalState() {
|
||||
log = Logger.standard();
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
include: analysis_options_no_lints.yaml
|
||||
|
||||
analyzer:
|
||||
errors:
|
||||
illegal_language_version_override: ignore
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- curly_braces_in_flow_control_structures
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
include: package:lints/recommended.yaml
|
||||
|
||||
analyzer:
|
||||
errors:
|
||||
illegal_language_version_override: ignore
|
||||
exclude:
|
||||
# These files have intentional errors.
|
||||
- test/lib_ex2.7_test.dart
|
||||
|
|
|
@ -1721,6 +1721,7 @@ class C {
|
|||
|
||||
Future<void> test_removeLanguageVersion() async {
|
||||
await analyze('''
|
||||
// ignore: illegal_language_version_override
|
||||
//@dart=2.6
|
||||
void main() {}
|
||||
''');
|
||||
|
@ -1729,7 +1730,11 @@ void main() {}
|
|||
..removeLanguageVersionComment = true
|
||||
})!;
|
||||
// TODO(mfairhurst): Remove beginning \n once it renders properly in preview
|
||||
expect(previewInfo.applyTo(code!), '\nvoid main() {}\n');
|
||||
expect(previewInfo.applyTo(code!), '''
|
||||
// ignore: illegal_language_version_override
|
||||
|
||||
void main() {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_removeLanguageVersion_after_license() async {
|
||||
|
@ -1737,6 +1742,7 @@ void main() {}
|
|||
// Some licensing stuff here...
|
||||
// Some copyrighting stuff too...
|
||||
// etc...
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.6
|
||||
void main() {}
|
||||
''');
|
||||
|
@ -1749,6 +1755,7 @@ void main() {}
|
|||
// Some licensing stuff here...
|
||||
// Some copyrighting stuff too...
|
||||
// etc...
|
||||
// ignore: illegal_language_version_override
|
||||
|
||||
void main() {}
|
||||
''');
|
||||
|
@ -1756,6 +1763,7 @@ void main() {}
|
|||
|
||||
Future<void> test_removeLanguageVersion_spaces() async {
|
||||
await analyze('''
|
||||
// ignore: illegal_language_version_override
|
||||
// @dart = 2.6
|
||||
void main() {}
|
||||
''');
|
||||
|
@ -1764,11 +1772,16 @@ void main() {}
|
|||
..removeLanguageVersionComment = true
|
||||
})!;
|
||||
// TODO(mfairhurst): Remove beginning \n once it renders properly in preview
|
||||
expect(previewInfo.applyTo(code!), '\nvoid main() {}\n');
|
||||
expect(previewInfo.applyTo(code!), '''
|
||||
// ignore: illegal_language_version_override
|
||||
|
||||
void main() {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_removeLanguageVersion_withOtherChanges() async {
|
||||
await analyze('''
|
||||
// ignore: illegal_language_version_override
|
||||
//@dart=2.6
|
||||
int f() => null;
|
||||
''');
|
||||
|
@ -1782,7 +1795,11 @@ int f() => null;
|
|||
true)
|
||||
})!;
|
||||
// TODO(mfairhurst): Remove beginning \n once it renders properly in preview
|
||||
expect(previewInfo.applyTo(code!), '\nint? f() => null;\n');
|
||||
expect(previewInfo.applyTo(code!), '''
|
||||
// ignore: illegal_language_version_override
|
||||
|
||||
int? f() => null;
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_removeNullAwarenessFromMethodInvocation() async {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue