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

Extract to function incorrectly marks refactoring as unavailable when using for loop with a lambda. #12711

Open
KKhanhH opened this issue Sep 13, 2024 · 0 comments
Labels
bug Feature: Extract to function Extract to function (free function or member function) investigate: repro This issue's repro steps needs to be investigated/confirmed Language Service

Comments

@KKhanhH
Copy link

KKhanhH commented Sep 13, 2024

Environment

  • OS and Version: Windows 10
  • VS Code Version: 1.91.1
  • C/C++ Extension Version: 1.21.6
  • If using SSH remote, specify OS of remote machine:

Bug Summary and Steps to Reproduce

Bug Summary:
When using a lambda with a return value inside of a for loop, cpptools will not allow for extracting to function refactor. The extract to function button is grayed out in the context menu with no reason as to why. When the keyboard shortcut is used (ctrl-shift-r & ctrl-e), the reason given for not being able to extract is because the for loop has control paths that exit without the return value.

Minimal reproducible example:

std::vector<int> testFunction(int a, int b, int size) {
    std::vector<int> vec;
    auto testAdd = [&]() {
        return a+b;
    };
    for(int i = 0; i < size; i++) {
        vec.push_back(a+b);
    }
}

Steps to reproduce:

  1. Select the lambda and the for loop.
  2. Press the key combination for extract to function
  3. Receive a tooltip mentioning the above error

Expected behavior:
Extract to function is successful and prompts with function name.

@sean-mcmanus sean-mcmanus added bug Language Service investigate: repro This issue's repro steps needs to be investigated/confirmed Feature: Extract to function Extract to function (free function or member function) labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Feature: Extract to function Extract to function (free function or member function) investigate: repro This issue's repro steps needs to be investigated/confirmed Language Service
Projects
Status: No status
Development

No branches or pull requests

2 participants