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

Compiler warning on mismatching case/spelling #15848

Closed
arnetheduck opened this issue Nov 5, 2020 · 3 comments
Closed

Compiler warning on mismatching case/spelling #15848

arnetheduck opened this issue Nov 5, 2020 · 3 comments

Comments

@arnetheduck
Copy link
Contributor

Nim allows identifiers that differ in cAse and sp_ell_ing - however, the spelling used in the declaration can be considered canonical.

For security-critical code, the introduction of alternate spellings can lead to vulnerabilities code injection (specially considering name clashes in larger project), and makes it harder to audit the code using tooling that is unaware of the naming, and generally creates confusion for developers reading the code.

As such, we would benefit from a compiler flag that, similar to --styleCheck, emits a warning when an alternate spelling is used, along with an option to disable it per-module, per-symbol or per-use (via pragmas?)

@Araq
Copy link
Member

Araq commented Nov 5, 2020

Well --styleCheck exists and to disable it per-module, use this construct

when defined(nimHasStyleChecks):
  {.push styleChecks: off.}

# code here

when defined(nimHasStyleChecks):
  {.pop.} # {.push styleChecks: off.}

What else do you need?

@arnetheduck
Copy link
Contributor Author

the style check is slightly different - it checks that symbols adhere to NEP-1 - ie that variables use the right capitalization etc - but for various reasons, we might be using a different style for some symbols, and what we need is that the compiler only checks that usage matches the declaration.

@Araq
Copy link
Member

Araq commented Nov 5, 2020

Ah ok.

Araq added a commit that referenced this issue May 7, 2021
@Araq Araq closed this as completed in 51f3ef6 May 7, 2021
narimiran pushed a commit that referenced this issue May 14, 2021
(cherry picked from commit 51f3ef6)
narimiran pushed a commit that referenced this issue May 17, 2021
(cherry picked from commit 51f3ef6)
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
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

2 participants