Coercion hint suggests the inner type when the mismatch is nested
I maintainer di solito rispondono entro 1 giorno
Una pull request collegata è già stata integrata.
- #9053 di @cknitt — integrata
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- ocaml
- Ambito
- compilers
Direzione di ricerca
La correzione è in compiler/ml/error_message_utils.ml: individua dove il suggerimento di coercion viene costruito a partire da target_type e modificalo per usare top_level_types. Compila lo snippet ReScript dell'issue per riprodurre il suggerimento errato. Fatto quando la coercion suggerita è (make :> unit => iterable<int>) e l'esempio compila.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When a type mismatch is nested inside another type, the "compatible at runtime" hint suggests a coercion to the inner type instead of the whole expected type, and the suggested code doesn't compile.
let consume = (_f: unit => Iterable.t<int>) => ()
let make: unit => Generator.t<int, unit, unit> = %raw(`function* () { yield 1 }`)
let () = consume(make)
This has type: unit => Generator.t<int, unit, unit>
But this function argument is expecting: unit => Iterable.t<int>
The incompatible parts:
Generator.t<int, unit, unit> (defined as Generator.t<int, unit, unit>) vs
Iterable.t<int> (defined as iterable<int>)
Possible solutions:
- These types are compatible at runtime. You can use the coercion operator to convert to the expected type: (make :> iterable<int>)
Applying the suggestion fails with Type unit => Generator.t<int, unit, unit> is not a subtype of iterable<int>. The right suggestion is (make :> unit => iterable<int>), which compiles.
Cause
In compiler/ml/error_message_utils.ml, the hint checks Ctype.subtype on the top-level types of the trace (top_level_types, "Coercion should always target the top level types"), but builds the rewrite from target_type, which is the inner incompatible pair. Printing the top-level expected type instead should fix it.
(The doubled Generator.t<…> (defined as Generator.t<…>) in the same output is #8997.)
- Lingua principale
- OCaml
- Stelle
- 7.5k
- Fork
- 484
- Merge medio
- 20h 19m
- PR unite (30g)
- 242
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rescript-lang/rescript
-
Record coercion can construct a private record from outside its moduleForse già presa @cknitt l’ha presa oggi. Aperta
Difficoltà 4/5 1-2 giorni Idoneità per principianti 52/100
rescript-lang/rescript#9124 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
rescript-lang/rescript#9123 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 55/100
rescript-lang/rescript#9122 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
rescript-lang/rescript#9109 ·
I maintainer di solito rispondono entro 1 giorno
-
Formatter: five cases where comments and doc comments are placed wronglyForse già presa @cknitt l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
rescript-lang/rescript#9107 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rescript-lang/rescript
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
CanadaHonk/porffor#426 ·
-
[MLIR][TOSA] Assertion in verifyBlockScaledTensorType when a tosa op result type is not a tensorApertacrash mlir:tosa
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
llvm/llvm-project#236561 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
A-lexer
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
oxc-project/oxc#28320 ·
I maintainer di solito rispondono entro 1 giorno
-
[python] Python library model: str(None) is modelled as an unconstrained string instead of "None"Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
area:codegen backend:spirv bug direction:input
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno