microsoft / microsoft/vscode-cpptools
`auto` lambda parameters are not deduced
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Type: LanguageService
Describe the bug
- OS and Version: Ubuntu 19.10
- VS Code Version: 1.44.2
- C/C++ Extension Version: 0.28.0
- Other extensions you installed (and if the issue persists after disabling them): n/a
- Does this issue involve using SSH remote to run the extension on a remote machine?: no
- A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).
Sometimes functions/methods/constructors take a callable object and it's useful and common to write a lambda directly in the call. However, doing so currently requires spelling the type of the argument in full in order to get VS Code's full support for checking and completion. Consider e.g.
some_future.then([](auto const& value) {
// what is `value`?
});
Given that the type of some_future is known (let's call it whatever_future<std::string>) it seems reasonable given an appropriate definition of whatever_future<T>::then that the type of value is correctly deduced to be std::string const&.
A complete example that demonstrates the problem:
#include <string>
template <typename Callable>
auto make_something(Callable&& callable) {
callable(std::string{"foobar"});
};
auto test() {
make_something([](auto const& something) {
something.size(); // here `something` is just `auto`
});
}
The equivalent in TypeScript works fine:
function makeSomething(callable: (_: string) => void) {
callable("foobar");
}
function test() {
makeSomething(something => {
something.length;
});
}
I note however that TypeScript does have a clear interface type for the callable that explains everything that's needed. In the C++ example the actual definition of the templated function needs to be used, because unless I'm missing something new and shiny with regards to Concepts, there is no good way to express the same information. But I may be wrong on that!
Thanks
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 C++ LanguageService and reproduce the complete example in the issue to confirm that the lambda parameter remains auto. Trace how the known templated callable definition is analyzed, and consider the related TypeScript example for the intended behavior. Done means VS Code identifies something as std::string const& and provides checking and completion inside the lambda.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100