Skip to content

Commit 001102c

Browse files
committed
Sort overloads in error messages
1 parent 80e62bd commit 001102c

File tree

2 files changed

+1099
-1619
lines changed

2 files changed

+1099
-1619
lines changed

libjsonexpr/src/eval.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ expected<json, error> eval(
9898
std::string message = "ambiguous overload of '" +
9999
std::string{f.name} + "' for types (" +
100100
arg_types + ")\n" + "note: candidates are:";
101+
102+
std::vector<std::string> available;
101103
for (const auto& [key, value] : map) {
102104
if (is_match(arg_types, key)) {
103-
message +=
104-
"\n " + std::string{f.name} + "(" + key + ")";
105+
available.push_back(key);
105106
}
106107
}
107108

109+
for (const auto& key : available) {
110+
message += "\n " + std::string{f.name} + "(" + key + ")";
111+
}
112+
108113
return unexpected(node_error(n, message));
109114
}
110115

@@ -117,7 +122,14 @@ expected<json, error> eval(
117122
std::string message = "no overload of '" + std::string{f.name} +
118123
"' accepts the provided types (" + arg_types + ")\n" +
119124
"note: available overloads:";
125+
126+
std::vector<std::string> available;
120127
for (const auto& [key, value] : map) {
128+
available.push_back(key);
129+
}
130+
131+
std::sort(available.begin(), available.end());
132+
for (const auto& key : available) {
121133
message += "\n " + std::string{f.name} + "(" + key + ")";
122134
}
123135

0 commit comments

Comments
 (0)