mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[cfe] Fix uri in nnbd error
+ add support for configurations in messages tests Closes #40789 Change-Id: I00b241df0e090a4736974e12598085d902ae9c77 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137560 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
b9f2c264ef
commit
51bc38f26c
12 changed files with 243 additions and 8 deletions
|
@ -2473,7 +2473,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
|
|||
modifiers |= initializingFormalMask;
|
||||
}
|
||||
FormalParameterBuilder formal = new FormalParameterBuilder(
|
||||
metadata, modifiers, type, name, this, charOffset, importUri)
|
||||
metadata, modifiers, type, name, this, charOffset, fileUri)
|
||||
..initializerToken = initializerToken
|
||||
..hasDeclaredInitializer = (initializerToken != null);
|
||||
return formal;
|
||||
|
@ -3198,14 +3198,14 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
|
|||
isNonNullableByDefault),
|
||||
formal.charOffset,
|
||||
formal.name.length,
|
||||
fileUri);
|
||||
formal.fileUri);
|
||||
} else {
|
||||
addProblem(
|
||||
templateOptionalNonNullableWithoutInitializerError.withArguments(
|
||||
formal.name, formal.variable.type, isNonNullableByDefault),
|
||||
formal.charOffset,
|
||||
formal.name.length,
|
||||
fileUri);
|
||||
formal.fileUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -532,9 +532,7 @@ OperatorParameterMismatch2/example: Fail
|
|||
OperatorWithOptionalFormals/analyzerCode: Fail
|
||||
OperatorWithOptionalFormals/example: Fail
|
||||
OptionalNonNullableWithoutInitializerError/analyzerCode: Fail
|
||||
OptionalNonNullableWithoutInitializerError/example: Fail
|
||||
OptionalNonNullableWithoutInitializerWarning/analyzerCode: Fail
|
||||
OptionalNonNullableWithoutInitializerWarning/example: Fail
|
||||
OverrideFewerNamedArguments/example: Fail
|
||||
OverrideFewerPositionalArguments/example: Fail
|
||||
OverrideMismatchNamedParameter/example: Fail
|
||||
|
|
|
@ -3936,10 +3936,18 @@ ValueForRequiredParameterNotProvidedWarning:
|
|||
|
||||
OptionalNonNullableWithoutInitializerError:
|
||||
template: "Optional parameter '#name' should have a default value because its type '#type' doesn't allow null."
|
||||
configuration: nnbd-strong
|
||||
script:
|
||||
- method1({int a}) {}
|
||||
- method2([int a]) {}
|
||||
|
||||
OptionalNonNullableWithoutInitializerWarning:
|
||||
template: "Optional parameter '#name' doesn't have a default value and its type '#type' doesn't allow null."
|
||||
configuration: nnbd-weak
|
||||
severity: WARNING
|
||||
script:
|
||||
- method1({int a}) {}
|
||||
- method2([int a]) {}
|
||||
|
||||
FieldNonNullableWithoutInitializerError:
|
||||
template: "Field '#name' should be initialized because its type '#type' doesn't allow null."
|
||||
|
|
|
@ -30,9 +30,14 @@ import "package:yaml/yaml.dart" show YamlList, YamlMap, YamlNode, loadYamlNode;
|
|||
import 'package:front_end/src/api_prototype/compiler_options.dart'
|
||||
show CompilerOptions;
|
||||
|
||||
import 'package:front_end/src/api_prototype/experimental_flags.dart'
|
||||
show ExperimentalFlag;
|
||||
|
||||
import 'package:front_end/src/api_prototype/memory_file_system.dart'
|
||||
show MemoryFileSystem;
|
||||
|
||||
import 'package:front_end/src/base/nnbd_mode.dart' show NnbdMode;
|
||||
|
||||
import 'package:front_end/src/compute_platform_binaries_location.dart'
|
||||
show computePlatformBinariesLocation;
|
||||
|
||||
|
@ -65,6 +70,23 @@ class MessageTestDescription extends TestDescription {
|
|||
this.example, this.problem);
|
||||
}
|
||||
|
||||
class Configuration {
|
||||
final NnbdMode nnbdMode;
|
||||
|
||||
const Configuration(this.nnbdMode);
|
||||
|
||||
CompilerOptions apply(CompilerOptions options) {
|
||||
if (nnbdMode != null) {
|
||||
options.experimentalFlags[ExperimentalFlag.nonNullable] = true;
|
||||
options.performNnbdChecks = true;
|
||||
options.nnbdMode = nnbdMode;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
static const Configuration defaultConfiguration = const Configuration(null);
|
||||
}
|
||||
|
||||
class MessageTestSuite extends ChainContext {
|
||||
final List<Step> steps = const <Step>[
|
||||
const Validate(),
|
||||
|
@ -119,6 +141,7 @@ class MessageTestSuite extends ChainContext {
|
|||
const String spellingPostMessage = "\nIf the word(s) look okay, update "
|
||||
"'spell_checking_list_messages.txt' or "
|
||||
"'spell_checking_list_common.txt'.";
|
||||
Configuration configuration;
|
||||
|
||||
Source source;
|
||||
List<String> formatSpellingMistakes(
|
||||
|
@ -285,6 +308,16 @@ class MessageTestSuite extends ChainContext {
|
|||
}
|
||||
break;
|
||||
|
||||
case "configuration":
|
||||
if (value == "nnbd-weak") {
|
||||
configuration = const Configuration(NnbdMode.Weak);
|
||||
} else if (value == "nnbd-strong") {
|
||||
configuration = const Configuration(NnbdMode.Strong);
|
||||
} else {
|
||||
throw new ArgumentError("Unknown configuration '$value'.");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
unknownKeys.add(key);
|
||||
}
|
||||
|
@ -296,6 +329,10 @@ class MessageTestSuite extends ChainContext {
|
|||
example.allowMoreCodes = exampleAllowMoreCodes;
|
||||
}
|
||||
}
|
||||
for (Example example in examples) {
|
||||
example.configuration =
|
||||
configuration ?? Configuration.defaultConfiguration;
|
||||
}
|
||||
|
||||
MessageTestDescription createDescription(
|
||||
String subName, Example example, String problem,
|
||||
|
@ -434,6 +471,8 @@ abstract class Example {
|
|||
|
||||
bool allowMoreCodes = false;
|
||||
|
||||
Configuration configuration;
|
||||
|
||||
Example(this.name, this.expectedCode);
|
||||
|
||||
YamlNode get node;
|
||||
|
@ -559,8 +598,11 @@ class PartWrapExample extends Example {
|
|||
final Example example;
|
||||
@override
|
||||
final bool allowMoreCodes;
|
||||
|
||||
PartWrapExample(String name, String code, this.allowMoreCodes, this.example)
|
||||
: super(name, code);
|
||||
: super(name, code) {
|
||||
configuration = example.configuration;
|
||||
}
|
||||
|
||||
@override
|
||||
Uint8List get bytes => throw "Unsupported: PartWrapExample.bytes";
|
||||
|
@ -650,14 +692,14 @@ class Compile extends Step<Example, Null, MessageTestSuite> {
|
|||
List<DiagnosticMessage> messages = <DiagnosticMessage>[];
|
||||
|
||||
await suite.compiler.batchCompile(
|
||||
new CompilerOptions()
|
||||
example.configuration.apply(new CompilerOptions()
|
||||
..sdkSummary = computePlatformBinariesLocation(forceBuildDir: true)
|
||||
.resolve("vm_platform_strong.dill")
|
||||
..target = new VmTarget(new TargetFlags())
|
||||
..fileSystem = new HybridFileSystem(suite.fileSystem)
|
||||
..packagesFileUri = dotPackagesUri
|
||||
..onDiagnostic = messages.add
|
||||
..environmentDefines = const {},
|
||||
..environmentDefines = const {}),
|
||||
main,
|
||||
output);
|
||||
|
||||
|
|
11
pkg/front_end/testcases/nnbd/non_nullable_optional.dart
Normal file
11
pkg/front_end/testcases/nnbd/non_nullable_optional.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
part 'non_nullable_optional_part.dart';
|
||||
|
||||
main() {}
|
||||
|
||||
method1({int a}) {}
|
||||
|
||||
method2([int a]) {}
|
|
@ -0,0 +1,34 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
//
|
||||
// Problems in library:
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:9:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method1({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:11:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method2([int a]) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:7:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method3({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:9:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method4([int a]) {}
|
||||
// ^
|
||||
//
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
part non_nullable_optional_part.dart;
|
||||
static method main() → dynamic
|
||||
;
|
||||
static method method1({core::int a}) → dynamic
|
||||
;
|
||||
static method method2([core::int a]) → dynamic
|
||||
;
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method3({core::int a}) → dynamic
|
||||
;
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method4([core::int a]) → dynamic
|
||||
;
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
//
|
||||
// Problems in library:
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:9:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method1({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:11:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method2([int a]) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:7:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method3({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:9:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method4([int a]) {}
|
||||
// ^
|
||||
//
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
part non_nullable_optional_part.dart;
|
||||
static method main() → dynamic {}
|
||||
static method method1({core::int a = #C1}) → dynamic {}
|
||||
static method method2([core::int a = #C1]) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method3({core::int a = #C1}) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method4([core::int a = #C1]) → dynamic {}
|
||||
|
||||
constants {
|
||||
#C1 = null
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
//
|
||||
// Problems in library:
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:9:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method1({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:11:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method2([int a]) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:7:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method3({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:9:14: Error: Optional parameter 'a' should have a default value because its type 'int' doesn't allow null.
|
||||
// method4([int a]) {}
|
||||
// ^
|
||||
//
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
part non_nullable_optional_part.dart;
|
||||
static method main() → dynamic {}
|
||||
static method method1({core::int a = #C1}) → dynamic {}
|
||||
static method method2([core::int a = #C1]) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method3({core::int a = #C1}) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method4([core::int a = #C1]) → dynamic {}
|
||||
|
||||
constants {
|
||||
#C1 = null
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
//
|
||||
// Problems in library:
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:9:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method1({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:11:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method2([int a]) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:7:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method3({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:9:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method4([int a]) {}
|
||||
// ^
|
||||
//
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
part non_nullable_optional_part.dart;
|
||||
static method main() → dynamic {}
|
||||
static method method1({core::int a = #C1}) → dynamic {}
|
||||
static method method2([core::int a = #C1]) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method3({core::int a = #C1}) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method4([core::int a = #C1]) → dynamic {}
|
||||
|
||||
constants {
|
||||
#C1 = null
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
//
|
||||
// Problems in library:
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:9:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method1({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional.dart:11:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method2([int a]) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:7:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method3({int a}) {}
|
||||
// ^
|
||||
//
|
||||
// pkg/front_end/testcases/nnbd/non_nullable_optional_part.dart:9:14: Warning: Optional parameter 'a' doesn't have a default value and its type 'int' doesn't allow null.
|
||||
// method4([int a]) {}
|
||||
// ^
|
||||
//
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
part non_nullable_optional_part.dart;
|
||||
static method main() → dynamic {}
|
||||
static method method1({core::int a = #C1}) → dynamic {}
|
||||
static method method2([core::int a = #C1]) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method3({core::int a = #C1}) → dynamic {}
|
||||
static method /* from org-dartlang-testcase:///non_nullable_optional_part.dart */ method4([core::int a = #C1]) → dynamic {}
|
||||
|
||||
constants {
|
||||
#C1 = null
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
part of 'non_nullable_optional.dart';
|
||||
|
||||
method3({int a}) {}
|
||||
|
||||
method4([int a]) {}
|
|
@ -1277,6 +1277,7 @@ nnbd/no_null_shorting: TextSerializationFailure
|
|||
nnbd/no_null_shorting_explicit_extension: TextSerializationFailure
|
||||
nnbd/no_null_shorting_extension: TextSerializationFailure
|
||||
nnbd/non_nullable_field_initialization: TextSerializationFailure
|
||||
nnbd/non_nullable_optional: TextSerializationFailure
|
||||
nnbd/not_definitely_unassigned_late_local_variables: TextSerializationFailure
|
||||
nnbd/nsm_from_opt_in: TextSerializationFailure
|
||||
nnbd/null_access: TextSerializationFailure
|
||||
|
|
Loading…
Reference in a new issue