Skip to content

Conversation

flofriday
Copy link

There were a couple of problems in Kotlins number literal parsing.
This PR adapts it to conform to the grammar described in the Language Spec chapter 1.2.3 Literals.

Unsigned suffixes

In Kotlin 1.5 unsigned numbers were introduced, including the suffixes u and U for number literals and while the following examples are valid Kotlin now they weren't correctly highlighted:

val u1 = 123u
val u2 = 123U
val u3 = 123uL
val u4 = 0b0101UL
val u5 = 0Xff0088u

Leading dot floating point literals

In Kotlin number literals can start with a leading dot.

val f1 = .1
val f2 = .123
val f3 = .123e+12f

Long suffix must be uppercase

Unlike Java only the uppercase L is a valid suffix.

// Valid
val correct = 123L

// Error:  Use 'L' instead of 'l'.
val wrong = 123l

Double suffix doesn't exist

Unlike Java there isn't a suffix to indicate that a number is a double.

// Valid
val correct = 123L

// Error
val wrong1 = 123D
val wrong1 = 123d

@flofriday
Copy link
Author

@microsoft-github-policy-service agree

@flofriday flofriday force-pushed the fix-kotlin-number-literals branch from 4b5d6ed to 4c1dd64 Compare September 4, 2025 18:07
@flofriday flofriday force-pushed the fix-kotlin-number-literals branch from 4c1dd64 to 011b69b Compare September 23, 2025 23:42
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