@@ -137,29 +137,26 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
137137
138138 if (other is VersionRange ) {
139139 // 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;
148144 intersectMin = other.min;
149145 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;
153150 }
154151
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) ) {
158155 intersectMax = other.max;
159156 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 ;
163160 }
164161
165162 if (intersectMin == null && intersectMax == null ) {
@@ -169,18 +166,10 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
169166
170167 // If the range is just a single version.
171168 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;
184173 }
185174
186175 // If we got here, there is an actual range.
0 commit comments