Normalize Kotlin type parameter bound colon spacing - #8558
Merged
Merged
Conversation
The whitespace before the colon of a type parameter bound was stored in the bounds `JContainer.before` with an empty `TypeReferencePrefix`, while `where` constraints on the same `J.TypeParameter` store it in the marker. `SpacesVisitor` only ever looked at the marker, so `fun <T : Number>` was never normalized. Store the space in the marker in both cases, and format type parameter bounds with `beforeColonInNewTypeDefinition`/`afterColonInNewTypeDefinition`, which matches Kotlin conventions (`val x: Int` but `fun <T : Number>`) and puts those previously unused style options to work. Fixes #6613
greg-at-moderne
approved these changes
Aug 20, 2026
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.
The whitespace before the colon of a type parameter bound was stored in the bounds
JContainer.beforewith an emptyTypeReferencePrefixmarker, whilewhereconstraints on the sameJ.TypeParameterstore it in the marker; sinceSpacesVisitoronly ever looked at the marker,fun <T : Number>was never normalized. The parser now stores that space in the marker in both cases, which prints identically but gives formatters a single place to look.SpacesVisitorformats type parameter bounds withbeforeColonInNewTypeDefinition/afterColonInNewTypeDefinitionrather than the declaration-name options, matching Kotlin conventions (val x: Intbutfun <T : Number>) and putting those two previously unused style options to work.class A : B()andobject : Runnablesupertype colons are not normalized either, and variable declarations keep their pre-colon space inJRightPadded.afterrather than the marker (unifying that is the larger LST change tracked in Improve quality of LST: replace applicable markers with LST elements rewrite-kotlin#477).