Skip to content

Typo correction should be smarter about context #143509

@AaronBallman

Description

@AaronBallman

Currently, typo correction has very little intelligence about the context of the typo being corrected. As a result, we fail to suggest corrections as well as we could. For example:

This case fails to recognize we're in a context where we expect one of a handful of keywords:

struct S {
  S() = defaul;
};

https://godbolt.org/z/o4snPEGve
(The same applies in many other circumstances; we should have a general mechanism that filters keywords by context.)

This case fails to recognize a type is invalid (but only in C) and suggests we replace lock by long:

void func() {
  long x;
  x = (lock);
}

https://godbolt.org/z/cxbjbE1bP

This case fails to recognize that only a type is valid:

int lang;
int main() {
  (void)(ling)12;
}

https://godbolt.org/z/hc3rnrbKz

I expect more examples exist. The thrust of the request is to make typo correction a bit more situationally aware whenever possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"enhancementImproving things as opposed to bug fixing, e.g. new or missing featurequality-of-implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions