Skip to content

fix(kotlin): count character literals - #790

Merged
boyter merged 1 commit into
boyter:masterfrom
LuisFigueroaG:fix/kotlin-char-literals
Oct 18, 2026
Merged

boyter merged 1 commit into
boyter:masterfrom
LuisFigueroaG:fix/kotlin-char-literals

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

Kotlin only had " as a quote, so a character literal holding one, like '"', opened a string that ran to the next " in the file and turned the comments and blank lines in between into code. For example:

fun isQuote(c: Char): Boolean {
    if (c == '"') {
        return true
    }
    // a comment
    return c == '\''
}

was counted as all code.

This adds ' as a quote, and the backtick too, so the apostrophe in a backticked test name like `it doesn't crash` doesn't open a character literal of its own (adding ' on its own turned such test files into all code). The Kotlin counter behind --exp-per-language-counters gets the same two quotes, so it keeps agreeing with the generic loop. I ran it against okhttp and kotlinx.coroutines with SCC_DIFF_KOTLIN_CORPUS and the two agreed on all 1612 files.

On okhttp this mostly gives back comment and blank lines in files that use '"', such as HttpHeaders.kt and MultipartBody.kt. The one file that got worse is RequestTest.kt, which has a """ raw string containing both " and an apostrophe; raw strings aren't modelled for Kotlin yet, and that would be a separate change.

I explicitly license this contribution under the MIT licence.

Kotlin only declared the double quote, so a character literal holding
one, such as '"', opened a string that ran on to the next " in the file
and turned the comments and blank lines in between into code.

Declare ' as a quote, and the backtick as well, so the apostrophe in a
backticked name like `it doesn't crash` does not open a character
literal of its own. The Kotlin counter is taught the same two quotes so
it keeps agreeing with the generic loop.
@pr-insights pr-insights Bot added M/complexity Normal or medium complexity M/size Normal or medium sized change labels Oct 14, 2026
@boyter
boyter merged commit 8e8f3d7 into boyter:master Oct 18, 2026
4 checks passed
@boyter

boyter commented Oct 18, 2026

Copy link
Copy Markdown
Owner

TY

@LuisFigueroaG
LuisFigueroaG deleted the fix/kotlin-char-literals branch October 20, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M/complexity Normal or medium complexity M/size Normal or medium sized change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants