Bug 387994

Summary: All variable in body and parameter in a global lambda hightlighted as global variables
Product: [Applications] kdevelop Reporter: Guillaume Racicot <gufideg>
Component: Language Support: CPP (Clang-based)Assignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.2.2
Attachments: Acual result of hightlighting
Expected result of hightlighting
Expected result of hightlighting (fixed)

Description Guillaume Racicot 2017-12-17 18:39:34 UTC
Created attachment 109431 [details]
Acual result of hightlighting

When declaring a global lambda, or sending a lambda into a function inside the global scope, all parameters of the lambda and variables in the body of the lambda are hightlighed light pink, as of they were all in the global scope.

Expected result:
All variables and parameter to be hightlighted in different colors.
Comment 1 Guillaume Racicot 2017-12-17 18:40:05 UTC
Created attachment 109432 [details]
Expected result of hightlighting
Comment 2 Guillaume Racicot 2017-12-17 18:59:48 UTC
Created attachment 109433 [details]
Expected result of hightlighting (fixed)

Please refer to this one, the previous edited screenshot contained errors
Comment 3 Milian Wolff 2017-12-18 14:56:43 UTC
how did you "fix" it?

Anyway, easy to reproduce. Here's an MWE:


int sum(int foo, int bar) {
    return foo + bar;
}

auto sum_lambda = [](int foo, int bar) {
    return foo + bar;
};

int sum_lambda_wrapped(int bla, int blub)
{
    return [](int foo, int bar) {
        return foo + bar;
    }(bla, blub);
}
Comment 4 Guillaume Racicot 2017-12-18 15:09:32 UTC
The fixed version of my screenshot simply removed the colored highlighting for the lambda names, since they are global themselves.
Comment 5 Milian Wolff 2017-12-18 16:18:43 UTC
I mean: how did you get the correct highlighting? Do you have a patch available?
Comment 6 Guillaume Racicot 2017-12-18 17:29:47 UTC
Ah! I simply enclosed all lambda in a function, took a screenshot and edited out the function in gimp. I didn't found a magic workaround for that unfortunately :)
Comment 7 Milian Wolff 2018-03-14 22:51:44 UTC
Git commit 335786a16731b093bf6b027c8c51ef653425b73a by Milian Wolff, on behalf of Guillaume Racicot.
Committed on 14/03/2018 at 22:51.
Pushed by mwolff into branch 'master'.

Make lambda introduce a context in DU chain

Summary:
Lambda in clang completion were not introducing a context. This
had the effect of making all local variable in a global lambda
highlighted as a global

Reviewers: #kdevelop, mwolff

Reviewed By: #kdevelop, mwolff

Subscribers: kfunk, mwolff, kdevelop-devel

Differential Revision: https://phabricator.kde.org/D11303

M  +8    -3    plugins/clang/duchain/builder.cpp
M  +21   -0    plugins/clang/tests/test_duchain.cpp
M  +1    -0    plugins/clang/tests/test_duchain.h

https://commits.kde.org/kdevelop/335786a16731b093bf6b027c8c51ef653425b73a
Comment 8 Kevin Funk 2018-03-15 18:47:48 UTC
Git commit dd038eb1a8fb4d663fe03eb6bd6ebf16d8ace3d0 by Kevin Funk, on behalf of Guillaume Racicot.
Committed on 15/03/2018 at 18:39.
Pushed by kfunk into branch '5.2'.

Make lambda introduce a context in DU chain

Summary:
Lambda in clang completion were not introducing a context. This
had the effect of making all local variable in a global lambda
highlighted as a global

Reviewers: #kdevelop, mwolff

Reviewed By: #kdevelop, mwolff

Subscribers: kfunk, mwolff, kdevelop-devel

Differential Revision: https://phabricator.kde.org/D11303

(cherry picked from commit 335786a16731b093bf6b027c8c51ef653425b73a)

M  +8    -3    plugins/clang/duchain/builder.cpp
M  +21   -0    plugins/clang/tests/test_duchain.cpp
M  +1    -0    plugins/clang/tests/test_duchain.h

https://commits.kde.org/kdevelop/dd038eb1a8fb4d663fe03eb6bd6ebf16d8ace3d0