Integer default values on `Float` input fields generate code that does not compile (Java and Kotlin)

Aperta
#1,015 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@0z5a ci sta già lavorando.

Dal 17/11/2026.

  • #1016 di @0z5a — aperta
  • #1017 di @lucasoliveira04 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
graphql, java, kotlin

Direzione di ricerca

Start by reading the Java and Kotlin code generation paths that emit defaults for GraphQL Float input fields, then inspect the tests covering generated input types and builders. Reproduce with the schema in the issue and compile generated code for Java, Kotlin, and Kotlin2. Done when integer defaults such as 1 and [1, 2.5] generate valid floating point values across the reported cases.

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

Descrizione

Describe the bug

GraphQL accepts an integer literal as the default value of a Float input field (ratio: Float = 1). Codegen copies the literal as is, so the generated field is a Double/Double? initialized with an Int. Java rejects this for nullable fields and lists, and Kotlin rejects it for every case (nullable, non-null and list). Issue #787 and PR #803 fixed Float! = 0.0 in Kotlin; the integer-literal form is still broken in both generators.

To reproduce

input ExampleInput {
    ratio: Float = 1
    minRatio: Float! = 0
    ratios: [Float] = [1, 2.5]
}

Generate Java types (default config) and compile them:

error: incompatible types: int cannot be converted to java.lang.Double
error: incompatible types: inference variable T has incompatible bounds

(the same two errors are reported again for the builder). minRatio compiles in Java only because double minRatio = 0 uses a primitive.

Kotlin (language = KOTLIN):

error: initializer type mismatch: expected 'Double?', actual 'Int'.
error: initializer type mismatch: expected 'Double', actual 'Int'.
error: initializer type mismatch: expected 'List<Double?>?', actual 'List<Number & Comparable<*>>'.

Kotlin2 (generateKotlinNullableClasses = true):

error: argument type mismatch: actual type is 'Int', but 'Double?' was expected.
error: argument type mismatch: actual type is 'Int', but 'Double' was expected.
error: argument type mismatch: actual type is 'List<Number & Comparable<*>>', but 'List<Double?>?' was expected.

Expected behavior

The schema is valid. The GraphQL spec (Float, input coercion) accepts integer input values and coerces them to Float by adding an empty fractional part, so 1 should become 1.0. Expected output: Double ratio = 1.0;, Arrays.asList(1.0, 2.5) in Java, and ratio: Double? = 1.0, listOf(1.0, 2.5) in Kotlin.

Integer defaults on Float input fields are common in hand-written schemas, for example quantity: Float = 1 or fee: Float = 0.

Environment

dgs-codegen main (6aa5bdaa), macOS arm64. Reproduced with the unit tests in the linked PR.

This issue was drafted with Claude Code (claude-opus-5-5); the results above are from the runs described.

Lingua principale
Kotlin
Stelle
220
Fork
123
Merge medio
1g 6h
PR unite (30g)
23

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 Netflix/dgs-codegen

Tutte le issue di Netflix/dgs-codegen

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.