cypher-codegen: account for fallback argument types in coalesce inference#86
Merged
Conversation
coalesce(<nullable Double>, 0) currently infers Double, ignoring the integer-literal fallback. When the property is null the runtime yields the integer literal as a database Integer object, which the Double decoder rejects. The leading-arg type must widen to Long to stay decodable. Adds a synthetic Sample vertex whose properties are named by their type and nullability role (no domain concepts), plus regression guards for the non-null and same-type cases that must stay unchanged. Generated with AI Co-Authored-By: AI <ai@example.com>
coalesce returns the first non-null argument, so its result type must unify the candidates, not just take the leading one. Walk arguments left→right (stopping at the first non-nullable one — later ones are unreachable), stripping nullable and unifying scalars: equal types collapse to that type; two numeric scalars (Long/Double in any mix) collapse to Long, the integer-tolerant superset that accepts database integers and passes floats through; anything else keeps the leading type. This makes coalesce(<nullable Double>, 0) infer Long so the emitted column decodes the integer literal the runtime yields when the property is null, while leaving non-nullable and same-type cases unchanged. Generated with AI Co-Authored-By: AI <ai@example.com>
jbmusso
force-pushed
the
fix/coalesce-integer-inference
branch
from
June 6, 2026 12:14
2d738f5 to
7cb5199
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
coalesce(x, ...)inferred its result type as the first argument only, stripped of nullable — ignoring the fallback arguments. When a nullableDoubleproperty is coalesced with an integer literal (coalesce(n.score, 0)), the property's type (Double) wins, so the emitted column isSchema.Number. But at runtime, when the property is null, the database returns the integer literal0as anIntegerobject, whichSchema.Numberrejects → decode crash.Fix
coalescereturns the first non-null argument, so the result type must unify the candidates:Long/Doublein any mix) collapse toLong— the integer-tolerant decoder is the numeric superset (accepts database integers, passes floats through); anything else keeps the leading argument's type.So
coalesce(<nullable Double>, 0) → Long, whilecoalesce(<non-null Double>, …) → Doubleandcoalesce(<String>, …) → Stringare unchanged. The decoded TS type staysnumber, so there's no consumer type breakage.Tests
coalesce(s.nullableDouble, 0)must inferLong(failed before, returnedDouble).Long, non-nullLong, non-nullString.Samplevertex whose properties are named by their type/nullability role — no domain concepts.Patch changeset included (
0.4.1 → 0.4.2).Generated with AI