@@ -137,29 +137,26 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
137
137
138
138
if (other is VersionRange ) {
139
139
// Intersect the two ranges.
140
- var intersectMin = min;
141
- var intersectIncludeMin = includeMin;
142
- var intersectMax = max;
143
- var intersectIncludeMax = includeMax;
144
-
145
- if (other.min == null ) {
146
- // Do nothing.
147
- } else if (intersectMin == null || intersectMin < other.min) {
140
+ Version intersectMin;
141
+ bool intersectIncludeMin;
142
+ if (allowsLower (this , other)) {
143
+ if (strictlyLower (this , other)) return VersionConstraint .empty;
148
144
intersectMin = other.min;
149
145
intersectIncludeMin = other.includeMin;
150
- } else if (intersectMin == other.min && ! other.includeMin) {
151
- // The edges are the same, but one is exclusive, make it exclusive.
152
- intersectIncludeMin = false ;
146
+ } else {
147
+ if (strictlyLower (other, this )) return VersionConstraint .empty;
148
+ intersectMin = this .min;
149
+ intersectIncludeMin = this .includeMin;
153
150
}
154
151
155
- if (other.max == null ) {
156
- // Do nothing.
157
- } else if (intersectMax == null || intersectMax > other.max ) {
152
+ Version intersectMax;
153
+ bool intersectIncludeMax;
154
+ if (allowsHigher ( this , other) ) {
158
155
intersectMax = other.max;
159
156
intersectIncludeMax = other.includeMax;
160
- } else if (intersectMax == other.max && ! other.includeMax) {
161
- // The edges are the same, but one is exclusive, make it exclusive.
162
- intersectIncludeMax = false ;
157
+ } else {
158
+ intersectMax = this .max;
159
+ intersectIncludeMax = this .includeMax ;
163
160
}
164
161
165
162
if (intersectMin == null && intersectMax == null ) {
@@ -169,18 +166,10 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
169
166
170
167
// If the range is just a single version.
171
168
if (intersectMin == intersectMax) {
172
- // If both ends are inclusive, allow that version.
173
- if (intersectIncludeMin && intersectIncludeMax) return intersectMin;
174
-
175
- // Otherwise, no versions.
176
- return VersionConstraint .empty;
177
- }
178
-
179
- if (intersectMin != null &&
180
- intersectMax != null &&
181
- intersectMin > intersectMax) {
182
- // Non-overlapping ranges, so empty.
183
- return VersionConstraint .empty;
169
+ // Because we already verified that the lower range isn't strictly
170
+ // lower, there must be some overlap.
171
+ assert (intersectIncludeMin && intersectIncludeMax);
172
+ return intersectMin;
184
173
}
185
174
186
175
// If we got here, there is an actual range.
0 commit comments