@@ -68,25 +68,70 @@ class Incompatibility {
68
68
Incompatibility ._(this .terms, this .cause);
69
69
70
70
String toString () {
71
+ if (cause == IncompatibilityCause .dependency) {
72
+ assert (terms.length == 2 );
73
+
74
+ var depender = terms.first;
75
+ var dependee = terms.last;
76
+ assert (depender.isPositive);
77
+ assert (! dependee.isPositive);
78
+
79
+ if (depender.constraint.isAny) {
80
+ return "all versions of ${_terseRef (depender )} "
81
+ "depend on ${dependee .package .toTerseString ()}" ;
82
+ } else {
83
+ return "${depender .package .toTerseString ()} depends on "
84
+ "${dependee .package .toTerseString ()}" ;
85
+ }
86
+ } else if (cause == IncompatibilityCause .sdk) {
87
+ assert (terms.length == 1 );
88
+ assert (terms.first.isPositive);
89
+
90
+ // TODO(nweiz): Include more details about the expected and actual SDK
91
+ // versions.
92
+ if (terms.first.constraint.isAny) {
93
+ return "no versions of ${_terseRef (terms .first )} "
94
+ "are compatible with the current SDK" ;
95
+ } else {
96
+ return "${terms .first .package .toTerseString ()} is incompatible with "
97
+ "the current SDK" ;
98
+ }
99
+ } else if (cause == IncompatibilityCause .noVersions) {
100
+ assert (terms.length == 1 );
101
+ assert (terms.first.isPositive);
102
+ return "no versions of ${_terseRef (terms .first )} "
103
+ "match ${terms .first .constraint }" ;
104
+ } else if (isFailure) {
105
+ return "version solving failed" ;
106
+ }
107
+
71
108
if (terms.length == 1 ) {
72
109
var term = terms.single;
73
- return "${term .package .toTerseString ()} is "
74
- "${term .isPositive ? 'forbidden' : 'required' }" ;
110
+ if (term.constraint.isAny) {
111
+ return "${_terseRef (term )} is "
112
+ "${term .isPositive ? 'forbidden' : 'required' }" ;
113
+ } else {
114
+ return "${term .package .toTerseString ()} is "
115
+ "${term .isPositive ? 'forbidden' : 'required' }" ;
116
+ }
75
117
}
76
118
77
119
if (terms.length == 2 ) {
78
120
var term1 = terms.first;
79
121
var term2 = terms.last;
80
- if (term1.isPositive != term2.isPositive) {
81
- var positive = (term1.isPositive ? term1 : term2).package;
82
- var negative = (term1.isPositive ? term2 : term1).package;
83
- return "if ${positive .toTerseString ()} then ${negative .toTerseString ()}" ;
84
- } else if (term1.isPositive) {
85
- return "${term1 .package .toTerseString ()} is incompatible with "
86
- "${term2 .package .toTerseString ()}" ;
87
- } else {
88
- return "either ${term1 .package .toTerseString ()} or "
89
- "${term2 .package .toTerseString ()}" ;
122
+ if (term1.isPositive == term2.isPositive) {
123
+ if (term1.isPositive) {
124
+ var package1 = term1.constraint.isAny
125
+ ? _terseRef (term1)
126
+ : term1.package.toTerseString ();
127
+ var package2 = term2.constraint.isAny
128
+ ? _terseRef (term2)
129
+ : term2.package.toTerseString ();
130
+ return "$package1 is incompatible with $package2 " ;
131
+ } else {
132
+ return "either ${term1 .package .toTerseString ()} or "
133
+ "${term2 .package .toTerseString ()}" ;
134
+ }
90
135
}
91
136
}
92
137
@@ -97,11 +142,24 @@ class Incompatibility {
97
142
}
98
143
99
144
if (positive.isNotEmpty && negative.isNotEmpty) {
100
- return "if ${positive .join (' and ' )} then ${negative .join (' and ' )}" ;
145
+ if (positive.length == 1 ) {
146
+ var positiveTerm = terms.firstWhere ((term) => term.isPositive);
147
+ if (positiveTerm.constraint.isAny) {
148
+ return "all versions of ${_terseRef (positiveTerm )} require "
149
+ "${negative .join (' or ' )}" ;
150
+ } else {
151
+ return "${positive .first } requires ${negative .join (' or ' )}" ;
152
+ }
153
+ } else {
154
+ return "if ${positive .join (' and ' )} then ${negative .join (' or ' )}" ;
155
+ }
101
156
} else if (positive.isNotEmpty) {
102
157
return "one of ${positive .join (' or ' )} must be false" ;
103
158
} else {
104
159
return "one of ${negative .join (' or ' )} must be true" ;
105
160
}
106
161
}
162
+
163
+ /// Returns a terse representation of term's package ref.
164
+ String _terseRef (Term term) => term.package.toRef ().toTerseString ();
107
165
}
0 commit comments