microsoft / microsoft/vscode-cpptools
Extract to function incorrectly marks refactoring as unavailable when using for loop with a lambda.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
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:
- Select the lambda and the for loop.
- Press the key combination for extract to function
- Receive a tooltip mentioning the above error
Expected behavior:
Extract to function is successful and prompts with function name.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal C++ example in the issue and reproduce the failure using the Extract to Function command or shortcut in VS Code. Locate the C/C++ extension's extract-to-function refactoring implementation and its control-path validation; done means selecting the lambda and for loop successfully prompts for a function name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, typescript, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100