microsoft / microsoft/vscode-cpptools

`auto` lambda parameters are not deduced

Aperta
#5,527 5 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug Language Service more votes needed Visual Studio
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il C++ LanguageService e riproduci l’esempio completo nell’issue per confermare che il parametro della lambda rimanga auto. Traccia come viene analizzata la definizione nota del callable templated e considera l’esempio correlato in TypeScript per il comportamento previsto. Il lavoro è completato quando VS Code identifica something come std::string const& e fornisce controllo e completamento all’interno della lambda.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
devtools
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.