Bug 460870 - Code completions turns . into -> for floating point number
Summary: Code completions turns . into -> for floating point number
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: git master
Platform: Compiled Sources Linux
: NOR minor
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-22 22:30 UTC by Benjamin Huth
Modified: 2023-04-17 16:24 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.11.230400


Attachments
illustrating video (363.43 KB, video/mp4)
2022-10-22 22:30 UTC, Benjamin Huth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Huth 2022-10-22 22:30:06 UTC
Created attachment 153129 [details]
illustrating video

SUMMARY
In some rare circumstances, the code completion turns . into an ->, when typing floating point values without leading zero. I found this inside of aggregate initialization of a std::array, but did not check if there are other circumstances where this also happens. See also the attached video.
A reproducible code example would be this:

#include <array>
struct S {double a, double b};

int main() {
    std::array<S, 1> a = {{
     {0.6, /* here type a dot, and it will be converted to an arrow */ }
    }};
}


If someone gives me a pointer where to start I'm willing to try fixing this myself.


STEPS TO REPRODUCE
1. Put the code example in a cmake c++ project
2. try to type a floatingpoint number like .5 without leading 0 in the aggregate initializer

OBSERVED RESULT
code completion turns . into ->

EXPECTED RESULT
code completion does nothing

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 36 - Kernel 5.19
(available in About System)
KDE Plasma Version: 5.25.5
KDE Frameworks Version: 5.99.0
Qt Version: 5.15.6
Comment 1 Igor Kushnir 2022-10-23 03:16:40 UTC
Search for "->" (with quotes) in KDevelop source code. I think the relevant results are in MemberAccessReplacer::replaceCurrentAccess() in file plugins/clang/codecompletion/context.cpp. Other bugs about incorrect . to -> replacements have been reported. I've experienced such a bug myself a few years ago.
Comment 2 Igor Kushnir 2022-10-24 06:38:20 UTC
Bug 432774 reports another wrong "." to "->" replacement.
Comment 3 Benjamin Huth 2022-12-04 16:08:18 UTC
Git commit 560c06ffb01dff577b58e3f2026ece17c49a0ed0 by Benjamin Huth, on behalf of Benjamin Huth.
Committed on 04/12/2022 at 11:26.
Pushed by igorkushnir into branch 'master'.

Code completion: Fix '.' to '->' for some cases

There are some situations where KDevelop erroneously replaces a '.' with
a '->', e.g. for floating point numbers some specific aggregate
initializers.
This fixes this (at least for some situations) by checking if clang
reports a parse issue with a dot-to-arrow substitution.
A new unit test is added to check the correct behaviour for the
situation described in bug 460870. To check this, the code
completion unit tests needed to be extended a bit: It is now possible
to pass the expected code to the test that is then compared with the
actual result.
FIXED-IN: 5.11.230400

M  +19   -4    plugins/clang/codecompletion/context.cpp
M  +69   -20   plugins/clang/tests/test_codecompletion.cpp

https://invent.kde.org/kdevelop/kdevelop/commit/560c06ffb01dff577b58e3f2026ece17c49a0ed0