[SOLVED] `abs(_:)` returns negative numbers in Int extension

I think there is definitely a bug in the syntax highlighter here.

If you write print(-1.f()) in Swift Playgrounds for iPad, then you’ll see that -1 is highlighted as a numeric literal, despite the fact that the - is not part of the numeric literal. The - should instead be highlighted as a function.

image

This even happens if you use parentheses in the expression, resulting in one parenthesis having a different color than the rest:

image

I haven’t tested this on my Mac yet, but it seems likely that Xcode has this bug too. Visual Studio Code’s syntax highlighter also has this bug when parentheses aren’t used, but behaves correctly when parentheses are used.

1 Like