Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

viluon
Copy link

@viluon viluon commented Jun 19, 2025

This change aims to improve source location tracking for purposes of error reporting. I deliberately maintained backwards compatibility, however the (original) choice of textOffset for determining the line number is questionable, as it typically points to the node's identifier rather than to the actual start of the node in the source code.

For example, in the test for f1, the reported FileLocation points to the start of the identifier f1 rather than to the keyword void.

@Location
void f1(@Location int p2) {

}

I would argue a more correct implementation would use startOffset rather than textOffset, perhaps exposing textOffset via another property of FileLocation. I'm happy to make changes here but went with the backwards-compatible default.

One more thing that occurred to me is that these line & column coordinates could be tracked in smaller classes still and exposed as two (or more) pairs in FileLocation, e.g. something like

data class FileLocation(
    val filePath: String,
    val start: SourceCoordinates, // based on startOffset
    val end: SourceCoordinates,
    val text: SourceCoordinates, // an extension based on textOffset
) : Location()

might be a better model. Such a backwards-incompatible API change might be rejected outright or take too long to incorporate and I'd personally prefer some column information rather than none. I'm happy to propose the necessary changes if maintainers are willing.

@viluon
Copy link
Author

viluon commented Sep 8, 2025

Are there any maintainers available for review? Perhaps @hfmehmed or @ting-yuan?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant