Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Coercion hint suggests the inner type when the mismatch is nested

Offen Anfängerfreundlich
#9,037 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
75/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
ocaml
Bereich
compilers

Rechercherichtung

Der Fix ist in compiler/ml/error_message_utils.ml: finde heraus, wo der Coercion-Hinweis aus target_type erstellt wird, und ändere ihn, um top_level_types zu verwenden. Kompiliere den ReScript-Schnipsel aus dem issue, um den falschen Hinweis zu reproduzieren. Erledigt, wenn die vorgeschlagene Coercion (make :> unit => iterable<int>) ist und das Beispiel kompiliert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.)

Vorherrschende Sprache
OCaml
Sterne
7.5k
Forks
483
Ø Merge
19 Std. 35 Min.
Gemergte PRs (30 T.)
208

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus rescript-lang/rescript

Alle Issues in rescript-lang/rescript

Ähnliche Issues

Weitere Issues zu Compilers

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.