Analyzer: avoid dynamic calls while examining Yaml

Change-Id: If569c74bad1d3762deb4cc74ea617d291ec33619
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190727
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Sam Rawlins
2021-03-12 16:50:37 +00:00
committed by commit-bot@chromium.org
parent ef01825d44
commit e1414089cf
4 changed files with 8 additions and 4 deletions
@@ -157,7 +157,7 @@ class PubspecValidator {
}
for (var dependency in declaredDevDependencies.entries) {
var packageName = dependency.key;
var packageName = dependency.key as YamlNode;
if (declaredDependencies.containsKey(packageName)) {
_reportErrorForNode(reporter, packageName,
PubspecWarningCode.UNNECESSARY_DEV_DEPENDENCY, [packageName.value]);
+5 -1
View File
@@ -118,8 +118,12 @@ class Merger {
merged[k] = v;
});
m2.nodes.forEach((k, v) {
// TODO(srawlins): The key should always be a [YamlNode], but is not (see
// https://pub.dev/documentation/yaml/latest/yaml/YamlMap/nodes.html).
// We could write an extension method which does this cast for us.
var value = (k as YamlNode).value;
var mergedKey =
merged.keys.firstWhere((key) => key.value == k.value, orElse: () => k)
merged.keys.firstWhere((key) => key.value == value, orElse: () => k)
as YamlScalar;
var o1 = merged[mergedKey];
if (o1 != null) {
@@ -287,7 +287,7 @@ class PackageBuildWorkspace extends Workspace {
// pubspec, to know the package name that package:build will assume.
if (dartToolBuildDir.exists && pubspec.exists) {
try {
final yaml = loadYaml(pubspec.readAsStringSync());
final yaml = loadYaml(pubspec.readAsStringSync()) as YamlMap;
final packageName = yaml['name'] as String;
final generatedRootPath = provider.pathContext
.joinAll([folder.path, ..._generatedPathParts]);
+1 -1
View File
@@ -68,7 +68,7 @@ part of 'experiments.dart';
features = <String, dynamic>{};
Map yamlFeatures = experimentsYaml['features'];
for (MapEntry entry in yamlFeatures.entries) {
String category = entry.value['category'] ?? 'language';
String category = (entry.value as YamlMap)['category'] ?? 'language';
if (category != "language") {
// Skip a feature with a category that's not language. In the future
// possibly allow e.g. 'analyzer' etc.