On 2014-03-14 18:22:19 +0000, Jacob Carlborg <d...@me.com> said:

On 2014-03-14 13:09, Michel Fortin wrote:

But before you can consider building such a tool, you'll have to
convince Walter that the locations of tokens should be tracked more
precisely in the frontend. Currently the frontend remembers only the
file and line of any token it finds. You can't implement a refactoring
with that. Last time that came in in a discussion (about error messages
showing the exact location of the error), the idea was shut down on the
ground that storing better location info would slow down the compiler.

This as already been implemented [1]. DMD (git master) now supports the -vcolumns flag to display error message with information about the column.

[1] https://github.com/D-Programming-Language/dmd/pull/3077

Makes me think, instead of generating patches or altering code, we could take the clang approach and simply suggest fixes during compilation. This is what suggested fixes looks like in clang:

page.mm:67:8: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
        if (x = 4)
            ~~^~~
page.mm:67:8: note: place parentheses around the assignment to silence this warning
        if (x = 4)
              ^
            (    )
page.mm:67:8: note: use '==' to turn this assignment into an equality comparison
        if (x = 4)
              ^
              ==

The two "note:" messages are the two possible suggested fixes.

If you're using Xcode, the IDE will actually parse those notes and let you choose between the two proposed fixes in a popup menu.
http://i.stack.imgur.com/UqIqm.png

--
Michel Fortin
michel.for...@michelf.ca
http://michelf.ca

Reply via email to