Skip to content

fix: clarify operator grouping and resolve an ambiguous path-string overload#80

Merged
OmarAlJarrah merged 1 commit into
mainfrom
fix/codeql-quality-alerts
Jul 16, 2026
Merged

fix: clarify operator grouping and resolve an ambiguous path-string overload#80
OmarAlJarrah merged 1 commit into
mainfrom
fix/codeql-quality-alerts

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Three arithmetic/bitwise expressions leaned on operator precedence alone with no visual grouping cue -- IPv4 octet packing, and Punycode's generalized-integer encoder and bias adaptation. Each nests two operators of different precedence on one line, which reads ambiguously and is exactly the shape CodeQL's "whitespace contradicts operator precedence" check flags. Extracting the higher-precedence sub-expression into a named local fixes the readability issue directly, with identical arithmetic.

Separately, ComponentPath.Segments and ComponentPath each declared an extension function named toUriPathString, differing only by receiver type. Kotlin resolves extension overloads by the receiver's static type, not its runtime type, so a caller holding a ComponentPath-typed reference to a Segments value (without a smart cast) always lands on the general dispatcher, never the specific encoder -- correct today only because the dispatcher's when branch calls back into the specific one deliberately. Renaming the Segments-specific one to toSegmentsPathString removes the overload entirely so dispatch can no longer depend on which static type a future caller happens to have.

All four are pure refactors -- no behavior change, no test updates needed.

Test plan

  • ./gradlew :kuri:jvmTest :kuri:ktlintCheck :kuri:detekt :kuri:apiCheck -- all green, no public API surface change

…verload

Three nested bitwise/arithmetic expressions (IPv4 octet packing, and
Punycode's generalized-integer encoder and bias adaptation) relied on
operator precedence alone with no visual grouping cue. Extract the
higher-precedence sub-expression into a named local in each case so the
intent is unambiguous to both readers and static analysis.

Also give ComponentPath.Segments' path-string encoder a distinct name
(toSegmentsPathString) instead of overloading it with ComponentPath's
dispatcher under the same toUriPathString name. Kotlin resolves extension
overloads by the receiver's static type, so keeping the name shared invited
a future caller with a ComponentPath-typed (rather than smart-cast
Segments-typed) receiver to silently land on the general dispatcher instead
of the specific encoder.

Pure refactors: no behavior change, no test updates needed.
@OmarAlJarrah
OmarAlJarrah merged commit 108089f into main Jul 16, 2026
11 checks passed
@OmarAlJarrah
OmarAlJarrah deleted the fix/codeql-quality-alerts branch July 16, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant