Suggest `thin` when a `def(...)` closure trait is used as a type

Aperta
#7,610 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
compilers

Direzione di ricerca

Start by running the Dict[String, def(mut Parser, String) raises -> Int] repro and the thin variant to compare the two diagnostics. The current error mentions 'Movable' and AnyTrait[def(...)], so find where the compiler builds the parameter-mismatch message for a closure trait used as a type. Done when the message says 'closure trait', suggests adding thin after the argument list, and includes a fix-it that the LSP can apply.

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

Descrizione

bug_feature_triaged Team: Mojo Compiler

When a def(...) function type without thin appears where a type is expected, the compiler reports a parameter mismatch against AnyTrait[def(...)]. The message is accurate, but it doesn't explain the cause. It doesn't say that def(...) without thin is a closure trait and not a type, or that adding thin makes it a function pointer type.

Repro

@fieldwise_init
struct Parser(Movable):
    var pos: Int
def parse_leaf(mut p: Parser, s: String) raises -> Int:
    return 0
def main() raises:
    var table = Dict[String, def(mut Parser, String) raises -> Int]()
    table["leaf"] = parse_leaf

Current output

error: 'Dict' parameter 'V' has 'Movable' type, but value has type 'AnyTrait[def(mut Parser, String) raises -> Int]'
    var table = Dict[String, def(mut Parser, String) raises -> Int]()
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With def(mut Parser, String) thin raises -> Int, the repro compiles and runs.

It would also be nice if the message said "closure trait", not show AnyTrait[...]. It could also come with a fix-it that inserts thin after the argument list, so the LSP and other tools can apply it.Suggest thin when a def(...) closure trait is used as a type

Lingua principale
Mojo
Stelle
30.2k
Fork
3.2k
Merge medio
6g 20h
PR unite (30g)
25

Preparare l'ambiente

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.

Altre issue di modular/modular

Tutte le issue di modular/modular

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.