Skip to content

Kotlin: cover 2.4.20 language features - #22462

Draft
andersfugmann wants to merge 18 commits into
andersfugmann/kotlin-2.4.20rcfrom
andersfugmann/kotlin-2.4.20-language-features
Draft

Kotlin: cover 2.4.20 language features#22462
andersfugmann wants to merge 18 commits into
andersfugmann/kotlin-2.4.20rcfrom
andersfugmann/kotlin-2.4.20-language-features

Conversation

@andersfugmann

@andersfugmann andersfugmann commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Add focused extraction coverage for six Kotlin language constructs. Five constructs already lower to supported IR and only require tests. Context parameters require both tests and extractor changes. There are no production QL library changes.

Callable references with context parameters are not covered because Kotlin 2.4.20-RC2 rejects them.

Changes

Test metadata records the first supported compiler and required language mode for each fixture. The .ql files added under test directories are test queries, not production QL changes.

Feature First supported compiler Test coverage Extractor change Production QL change
Context parameters 2.2.20-Beta2 Added Required None
JVM 21 when using invokedynamic 2.2.20-Beta2 Added None None
Collection literals 2.4.0 Added None None
Full multi-field value classes 2.4.20-RC2 Added None None
Short-form name-based destructuring 2.4.20-RC2 Added None None
Companion blocks and extensions 2.4.20-RC2 Added None None

Context parameters

Kotlin 2.2.20-Beta2 introduced the unified parameter and argument layout used by context parameters. The compatibility layer now:

  • extracts context parameters as callable parameters;
  • maps implicit context arguments to the corresponding parameters;
  • preserves stable parameter indices around dispatch and extension receivers;
  • handles context parameters on function calls and property accessors.

Implicit context argument locations are normalised because supported compiler versions represent these generated reads differently. Other expression locations are unchanged.

Validation

  • Built every standalone and embeddable extractor variant.
  • Ran each feature test with every compiler that accepts its syntax.
  • Ran the context-parameter function, getter, and setter coverage from 2.2.20-Beta2 through 2.4.20-RC2.
  • Ran all 3,453 Kotlin 2 tests with 2.4.20-RC2 in four sequential shards.
  • Kept existing expected output unchanged and did not disable tests.

Stack

This pull request is stacked on #22404 and should be reviewed after it.

andersfugmann and others added 10 commits August 28, 2026 14:15
Add focused coverage for an abstract value base class and a concrete
multi-field subclass with property overrides, inheritance, and a secondary
constructor.

The existing extractor represents these constructs correctly. This commit
adds coverage only and requires no extractor change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add focused coverage for short-form name-based destructuring where the
selected property is not the first declared field. Check the resolved getter
and data flow from the selected field to the destructured local.

The existing extractor selects the property by name correctly. This commit
adds coverage only and requires no extractor change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add regression coverage for context parameters on a function and an
extension-property getter. Record callable parameters and implicit call
arguments.

Without the follow-up fix, the test reports missing context parameters,
missing arguments, and database consistency errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Treat Kotlin 2.4 IR context parameters as callable value parameters and map
member-access arguments using their parameter kinds instead of assuming that
all non-regular parameters form a prefix.

This restores context parameters and implicit arguments while preserving
dispatch and extension receiver handling. The change is confined to the
Kotlin 2.4 compatibility source set.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extend the context-parameter regression test to an extension-property setter.
Check the extension receiver, context argument, assigned value, and resolved
setter call.

The preceding extractor fix already handles this case correctly. This commit
adds coverage only and requires no additional extractor change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add focused coverage for a collection literal resolved through a companion
operator fun of. Check the call target, arguments, result type, locations,
and element data flow through the resulting collection.

The existing extractor handles the lowered call correctly. This commit adds
coverage only and requires no extractor change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add focused coverage for a companion-block function and companion extension
function and property. Check declaration ownership, property accessors,
resolved calls, and data flow.

The existing extractor handles the lowered declarations and calls correctly.
This commit adds coverage only and requires no extractor change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a JVM 21 regression test for when generation using invokedynamic. The
same expected source AST also passes with inline when generation.

The backend choice does not change the IR observed by the extractor. This
commit adds coverage only and requires no extractor change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the secondary constructor's Long conversion with a String overload.
This preserves coverage for non-trivial value-class construction without
exercising an unrelated primitive-conversion diagnostic.

This is a test-only refinement and does not change extractor behaviour.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Derive Kotlin 2.4 parameter indices from preceding context and regular
parameters while reserving the Java parameter slot for an extension receiver.

This removes negative context-parameter indices and prevents setter parameter
label collisions found by the consistency checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@andersfugmann
andersfugmann force-pushed the andersfugmann/kotlin-2.4.20-language-features branch from 8eb2160 to 701a005 Compare August 28, 2026 14:09
Run the full multi-field value class fixture only with Kotlin 2.4.20-RC2 or later in K2 mode. Earlier supported compilers reject the tested syntax even with the FullValueClasses language feature enabled.\n\nThis is coverage metadata only. Existing extraction remains correct and no extractor change is required.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Run the short-form name-based destructuring fixture only with Kotlin 2.4.20-RC2 or later in K2 mode. Earlier supported compilers reject the tested combination of full value classes and name-based destructuring options.\n\nThis is coverage metadata only. Existing extraction remains correct and no extractor change is required.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Run the function, getter, and setter context-parameter fixture from Kotlin 2.2.20-Beta2 onwards in K2 mode. This is the earliest supported compiler that accepts the exact fixture with -Xcontext-parameters.\n\nThe wider gate makes the existing regression test applicable to earlier compilers so their extraction behaviour can be assessed rather than assuming the fix is specific to Kotlin 2.4.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Run the custom collection literal fixture from Kotlin 2.4.0 onwards in K2 mode. Earlier supported compilers reject the tested CollectionLiterals language feature.\n\nThis is coverage metadata only. Existing extraction remains correct and no extractor change is required.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Run the companion block and companion extension fixture only with Kotlin 2.4.20-RC2 or later in K2 mode. Earlier supported compilers reject -Xcompanion-blocks-and-extensions.\n\nThis is coverage metadata only. Existing extraction remains correct and no extractor change is required.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Run the invokedynamic when-expression fixture from Kotlin 2.2.20-Beta2 onwards in K2 mode, and require Java 21 for its configured JVM target. Earlier supported compilers reject the tested backend option.\n\nThis is coverage metadata only. Existing source-level extraction remains correct and no extractor change is required.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the unified parameter and argument layout introduced in Kotlin 2.2.20-Beta2 so context parameters and their implicit call arguments are included before the old accessors disappear in Kotlin 2.4.\n\nAssign parameter indices after excluding receiver slots, and give compiler-generated context arguments a stable whole-file location when the earlier compiler supplies inconsistent offsets. This fixes the version-gated function, getter, and setter regression test without changing its expected output. Earlier compilers retain the legacy compatibility implementation because they do not accept the tested context-parameter syntax.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the shared whole-file location for implicit context arguments across Kotlin 2.2.20-Beta2 through 2.4.20-RC2. Kotlin 2.3.20 reports broad source ranges for these generated reads while other versions report synthetic offsets, although the extracted argument semantics are identical.\n\nNormalising only implicit arguments to context parameters keeps one focused expected result across supported compilers without weakening the assertions or changing unrelated expression locations.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant