Today, I made a silly mistake. Here is the gist of it:
func fubar () -> [String, String] {
return ("fu", "bar")
}
It took me a while to figure out what was wrong because of the way Xcode
presents the diagnostic messages.
If I compile the above code from the command line, the compiler emits these diagnostics, in correct order, the most relevant error message first:
rvt.swift:1:25: error: expected ']' in array type
1 | func fubar () -> [String, String] {
| | `- error: expected ']' in array type
| `- note: to match this opening '['
2 | return ("fu", "bar")
3 | }
rvt.swift:1:25: error: consecutive statements on a line must be separated by ';'
1 | func fubar () -> [String, String] {
| `- error: consecutive statements on a line must be separated by ';'
2 | return ("fu", "bar")
3 | }
rvt.swift:1:25: error: expected expression
1 | func fubar () -> [String, String] {
| `- error: expected expression
2 | return ("fu", "bar")
3 | }
rvt.swift:1:6: error: expected '{' in body of function declaration
1 | func fubar () -> [String, String] {
| `- error: expected '{' in body of function declaration
2 | return ("fu", "bar")
3 | }
However, when compiled in Xcode
, the error messages appear reordered:
Consecutive statements on a line must be separated by ';'
Expected ']' in array type to match this opening '['
Expected '{' in body of function declaration
Expected expression
This makes it hard to spot silly mistakes.
Xcode
should simply present the most relevant error message first:
Expected ']' in array type to match this opening '['
Is there a reason why Xcode
reorders the error messages?