mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Issue 53142. Ignore pre-release field when reporting sdk_version_since.
Bug: https://github.com/dart-lang/sdk/issues/53142 Change-Id: Ifeff83ef56cd560a850e012bcabfebf63c391353 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319302 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
6194209b28
commit
3564f5c163
|
@ -48,6 +48,7 @@ import 'package:analyzer/src/lint/linter_visitor.dart';
|
|||
import 'package:analyzer/src/services/lint.dart';
|
||||
import 'package:analyzer/src/task/strong/checker.dart';
|
||||
import 'package:analyzer/src/util/performance/operation_performance.dart';
|
||||
import 'package:analyzer/src/utilities/extensions/version.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
|
@ -478,7 +479,11 @@ class LibraryAnalyzer {
|
|||
var sdkVersionConstraint = _analysisOptions.sdkVersionConstraint;
|
||||
if (sdkVersionConstraint != null) {
|
||||
SdkConstraintVerifier verifier = SdkConstraintVerifier(
|
||||
errorReporter, _libraryElement, _typeProvider, sdkVersionConstraint);
|
||||
errorReporter,
|
||||
_libraryElement,
|
||||
_typeProvider,
|
||||
sdkVersionConstraint.withoutPreRelease,
|
||||
);
|
||||
unit.accept(verifier);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:analyzer/dart/element/type.dart';
|
|||
import 'package:analyzer/dart/element/type_provider.dart';
|
||||
import 'package:analyzer/error/listener.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/utilities/extensions/version.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
||||
/// A visitor that finds code that assumes a later version of the SDK than the
|
||||
|
@ -253,22 +254,3 @@ class SdkConstraintVerifier extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension on VersionConstraint {
|
||||
bool requiresAtLeast(Version version) {
|
||||
final self = this;
|
||||
if (self is Version) {
|
||||
return self >= version;
|
||||
}
|
||||
if (self is VersionRange) {
|
||||
final min = self.min;
|
||||
if (min == null) {
|
||||
return false;
|
||||
} else {
|
||||
return min >= version;
|
||||
}
|
||||
}
|
||||
// We don't know, but will not complain.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
54
pkg/analyzer/lib/src/utilities/extensions/version.dart
Normal file
54
pkg/analyzer/lib/src/utilities/extensions/version.dart
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) 2023, 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.
|
||||
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
||||
extension VersionConstraintExtension on VersionConstraint {
|
||||
/// The same constraint, but only with major, minor, patch fields.
|
||||
///
|
||||
/// Excludes pre-release and build fields, useful when developing against
|
||||
/// not yet release version of Dart SDK.
|
||||
VersionConstraint get withoutPreRelease {
|
||||
switch (this) {
|
||||
case Version version:
|
||||
return version.withoutPreRelease;
|
||||
case VersionRange range:
|
||||
return VersionRange(
|
||||
min: range.min?.withoutPreRelease,
|
||||
includeMin: range.includeMin,
|
||||
max: range.max?.withoutPreRelease,
|
||||
includeMax: range.includeMax,
|
||||
);
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
bool requiresAtLeast(Version version) {
|
||||
final self = this;
|
||||
if (self is Version) {
|
||||
return self >= version;
|
||||
}
|
||||
if (self is VersionRange) {
|
||||
final min = self.min;
|
||||
if (min == null) {
|
||||
return false;
|
||||
} else {
|
||||
return min >= version;
|
||||
}
|
||||
}
|
||||
// We don't know, but will not complain.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
extension VersionExtension on Version {
|
||||
/// The same version, but only with major, minor, patch fields.
|
||||
///
|
||||
/// Excludes pre-release and build fields, useful when developing against
|
||||
/// not yet release version of Dart SDK.
|
||||
Version get withoutPreRelease {
|
||||
return Version(major, minor, patch);
|
||||
}
|
||||
}
|
|
@ -654,6 +654,21 @@ class A {}
|
|||
await verifyVersion('>=2.15.0', '''
|
||||
import 'dart:foo';
|
||||
|
||||
void f(A a) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_constraints_greaterOrEq_equal_preRelease() async {
|
||||
_addDartFooLibrary(r'''
|
||||
import 'dart:_internal';
|
||||
|
||||
@Since('2.15')
|
||||
class A {}
|
||||
''');
|
||||
|
||||
await verifyVersion('>=2.15.0-pre', '''
|
||||
import 'dart:foo';
|
||||
|
||||
void f(A a) {}
|
||||
''');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue