Skip to content

Commit

Permalink
Analyze SDK with non-nullable experiment enabled, update MockSdk.
Browse files Browse the repository at this point in the history
Initial:  https://dart-review.googlesource.com/c/sdk/+/134401
Reverted: https://dart-review.googlesource.com/c/sdk/+/134802

Internal presubmit is green.
https://test.corp.google.com/ui#id=OCL:294345942:BASE:297377939:1582738004318:fb4ae9fe

Change-Id: I25e6445bd0241a89850dff3d88ece0edd768053a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135241
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Feb 26, 2020
1 parent 12d610e commit c9884cc
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class B extends A {
''');
}

/// TODO(scheglov) This test will fail with NNBD SDK.
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/1997')
Future<void> test_method_toString() async {
await resolveTestUnit('''
class A {
Expand Down
39 changes: 2 additions & 37 deletions pkg/analyzer/lib/src/dart/analysis/feature_set_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/context/packages.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';

class FeatureSetProvider {
/// This flag will be turned to `true` and inlined when we un-fork SDK,
/// so that the only SDK is the Null Safe SDK.
static const isNullSafetySdk = false;

static final _preNonNullableVersion = Version(2, 7, 0);
static const isNullSafetySdk = true;

final FeatureSet _sdkFeatureSet;
final Packages _packages;
Expand Down Expand Up @@ -58,11 +55,7 @@ class FeatureSetProvider {
@required FeatureSet packageDefaultFeatureSet,
@required FeatureSet nonPackageDefaultFeatureSet,
}) {
var sdkFeatureSet = _determineSdkFeatureSet(
resourceProvider,
sourceFactory,
packageDefaultFeatureSet,
);
var sdkFeatureSet = FeatureSet.fromEnableFlags(['non-nullable']);

return FeatureSetProvider._(
sdkFeatureSet: sdkFeatureSet,
Expand All @@ -71,32 +64,4 @@ class FeatureSetProvider {
nonPackageDefaultFeatureSet: nonPackageDefaultFeatureSet,
);
}

/// Read `dart:core` file and determine if SDK in non-nullable by default.
///
/// If it is, use the [defaultFeatureSet], which might have enabled
/// [Feature.non_nullable], so SDK will be parsed and resolved as
/// non-nullable.
///
/// Otherwise, restrict the SDK language to the maximum known now.
static FeatureSet _determineSdkFeatureSet(
ResourceProvider resourceProvider,
SourceFactory sourceFactory,
FeatureSet defaultFeatureSet,
) {
var objectSource = sourceFactory.forUri('dart:core/object.dart');
if (objectSource == null) {
objectSource = sourceFactory.forUri('dart:core');
}

try {
var objectFile = resourceProvider.getFile(objectSource.fullName);
var objectContent = objectFile.readAsStringSync();
if (!objectContent.contains('bool operator ==(Object other)')) {
return defaultFeatureSet.restrictToVersion(_preNonNullableVersion);
}
} catch (_) {}

return defaultFeatureSet;
}
}
Loading

0 comments on commit c9884cc

Please sign in to comment.