Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce Location type for line/col (maybe also type OneBasedIndex = distinct int for line numbers etc that start at 1) #638

Open
timotheecour opened this issue Mar 5, 2021 · 0 comments

Comments

@timotheecour
Copy link
Owner

timotheecour commented Mar 5, 2021

refs nim-lang#17257 (comment)

goal: type safety, self documenting, avoid off by 1 bugs (compiler uses multiple conventions interchangeably which has been source of off by 1 bugs when dealing with line numbers, columns etc)

plausible implementation

  • internally represent line numbers as starting from 0
  • but when rendering via toLocation, add +1, eg:
template toLocation*(result: var string, file: string | cstring, line: int, col: int) =

# would become:
type OneBasedIndex = distinct int
proc `$`(a: OneBasedIndex): string = $(a.int + 1)
template toLocation*(result: var string, file: string | cstring, line: int | OneBasedIndex, col: int | OneBasedIndex) =
@timotheecour timotheecour changed the title type OneBasedIndex = distinct int for line numbers etc that start at 1 introduce Location type for line/col (maybe also type OneBasedIndex = distinct int for line numbers etc that start at 1) Mar 12, 2021
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

No branches or pull requests

1 participant