Commit Graph

1190 Commits

Author SHA1 Message Date
Chris Smowton
d700fddfdd Kotlin: handle default parameter values inherited from an overridden function 2022-11-02 13:57:53 +00:00
Tamas Vajk
1d3f4826a9 Fix failing internal checkß 2022-11-02 13:57:11 +01:00
Chris Smowton
39520e54ea Restore enum class exclusion from constructor default parameters 2022-11-02 11:28:13 +00:00
Tamas Vajk
145e2093f3 Kotlin: Remove code duplication 2022-11-02 11:46:33 +01:00
Chris Smowton
4910bf12e9 Kotlin vararg constructors: don't call a default-parameter constructor just because there are no varargs
This is the constructor case of https://github.com/github/codeql/pull/10909
2022-11-01 19:28:56 +00:00
Tamas Vajk
91972d1d1f Kotlin: Fix location (start position) of method calls 2022-10-31 21:08:15 +01:00
Tamás Vajk
e356720c73 Merge pull request #11014 from tamasvajk/kotlin-for-loop-var
Kotlin: Resugar `for` loops
2022-10-31 14:48:21 +01:00
Tamas Vajk
4cd0f1ca66 Apply code review findings 2022-10-31 08:43:53 +01:00
Chris Smowton
b370497f96 Avoid split overrides 2022-10-29 18:23:45 +01:00
Chris Smowton
8266a22332 Kotlin: fix method types when an inherited method implements a collection type
In this circumstance the compiler seems to generate a specialised version of the implementing function with its argument type replaced by the interface-implementing child class' type parameter. However it stores a back-pointer to the real declared function, which we should use as the call target.
2022-10-29 11:29:04 +01:00
Chris Smowton
d9744c81b7 Merge pull request #11017 from smowton/smowton/fix/kotlin-wildcard-suppression-annotation
Kotlin: fix wildcard suppression where the annotation applies to a parent type/argument.
2022-10-28 18:33:07 +01:00
Chris Smowton
d6e2f5f4a8 Use ?.not() to negate a nullable boolean 2022-10-28 16:13:55 +01:00
Chris Smowton
1e1c9f639c Avoid Kotlin 1.5+ function firstNotNullOfOrNull 2022-10-28 16:13:55 +01:00
Chris Smowton
24f87ac963 Kotlin: fix wildcard suppression where the annotation applies to a parent type/argument.
In the process I also fix the missed case where suppression can be switched off using a parameterized annotation.
2022-10-28 16:13:55 +01:00
Tamas Vajk
803a97df7f Kotlin: Resugar for loops with tuples as loop variables 2022-10-28 14:55:50 +02:00
Tamas Vajk
841340b266 Kotlin: Resugar for loops 2022-10-28 14:55:50 +02:00
Chris Smowton
366410ee9e Fix incorrect parameter ordering 2022-10-28 12:58:23 +01:00
Chris Smowton
45a4cd89a6 Kotlin: specialise extension receivers the same as other function parameters
This arises when a generic class extends one of its parameters; for example, `class G<T> { val T.v; get() = 1 }`, where specialisation `G<List>` should generate a method specialisation `getV(List)`.
2022-10-27 18:31:19 +01:00
Chris Smowton
28b6e263ec Kotlin: reintroduce pointless wildcards when a Java declaration explicitly uses them
For example, Java code might use `HasOutVariance<? extends String>`, or `HasInVariance<? super Object>`, both of which are needless wildcards and which the Kotlin extractor would previously have refused to reintroduce due to their not specifying a larger type than their bound. However this led to inconsistency with Java extraction, which
extracts the type as it appears in source.

This seems to particularly happen with generated code, e.g. the output of the Kotlin protobuf compiler.
2022-10-26 20:05:27 +01:00
Chris Smowton
004f4be5fb Kotlin: don't try to call nonexistent j.l.Number.toChar
Previously we thought this could be callable because Kotlin's view of `j.l.Integer` inherits `k.Number` which defines `toChar`.
2022-10-25 17:09:05 +01:00
Chris Smowton
c4ba644dfd Merge pull request #10952 from smowton/smowton/fix/java-interface-redeclares-tostring
Kotlin: extract interface redeclarations of `Object` methods
2022-10-25 11:29:10 +01:00
Chris Smowton
843f847960 Merge pull request #10921 from smowton/smowton/fix/ignore-enhanced-nullability
Kotlin: ignore enhanced nullability when extracting primitive types
2022-10-24 19:43:04 +01:00
Chris Smowton
c6f4742f29 Kotlin: extract interface redeclarations of Object methods
Due to a probable compiler bug (?) the redeclaration looks like a fake symbol, leading to Java dispatching against a declaration that Kotlin doesn't believe exists.
2022-10-24 12:45:07 +01:00
Chris Smowton
86e99c497d Merge pull request #10930 from smowton/smowton/fix/external-property-overloads
Kotlin: give external extension properties with matching name and file distinct trap filenames
2022-10-24 11:32:37 +01:00
Chris Smowton
00800017fd Kotlin: make internal constructors' trap labels consistent with the Java extractor
Previously we accidentally named these something like <init>$main, which is a name-mangling the Kotlin compiler applies to internal methods but not to constructors, which look to Java just like regular public constructors.
2022-10-21 16:48:37 +01:00
Chris Smowton
42d6968c20 Kotlin: give external extension properties with matching name and file distinct trap filenames 2022-10-21 14:28:53 +01:00
Chris Smowton
5e28e5a170 Merge pull request #10909 from smowton/smowton/fix/kotlin-varargs-dataflow
Kotlin: Fix varargs dataflow, and varargs default handling
2022-10-21 13:32:34 +01:00
Chris Smowton
b80bf4a73e Account for route to IrSimpleType.kotlinType changing as of v1.7.0 2022-10-21 11:55:15 +01:00
Ian Lynagh
2e6d6e1538 Merge pull request #10894 from igfoo/igfoo/psi
Kotlin: Refactor PSI handling
2022-10-21 11:43:49 +01:00
Chris Smowton
1fe9e8457f Kotlin: Fix varargs dataflow, and varargs default handling
Dataflow requires accounting for the fact that the varargs parameter isn't necessarily last in the parameter list in a couple more places. Default handling just requires that if the only null parameter is the varargs argument, and it has no default value, then no $default method is required-- the caller is expected to simply pass nothing (at QL
/ source level) or an empty array (at JVM level).
2022-10-21 11:14:41 +01:00
Chris Smowton
7889d9cffa Kotlin: ignore enhanced nullability when extracting primitive types
Otherwise we'll mistake `@NotNull Integer` for `int` and similar, causing a mismatch vs. Java signatures.
2022-10-21 10:55:26 +01:00
Chris Smowton
ac013f9d19 Merge pull request #10889 from smowton/smowton/fix/enum-entry-class-warning
Kotlin: Don't warn on extracting an enum-entry class
2022-10-20 22:08:29 +01:00
Chris Smowton
f2749a8878 Don't warn on extracting an enum-entry class 2022-10-20 16:09:45 +01:00
Ian Lynagh
291330c7e1 Kotlin: Small code simplification 2022-10-20 12:29:48 +01:00
Chris Smowton
e868cdf91b Merge pull request #9876 from smowton/smowton/feature/interface-forwarding
Kotlin: implement default interface forwarding
2022-10-20 10:17:47 +01:00
Ian Lynagh
74a4061508 Kotlin: Refactor PSI handling
We were giving warnings about comments, when we were actually trying to
populate numlines.
2022-10-19 18:02:24 +01:00
Chris Smowton
c6b62c934b Merge pull request #10853 from smowton/smowton/fix/specialised-anon-classes
Kotlin: extract called private methods of specialised types, and specialised instances of anonymous types
2022-10-19 16:48:28 +01:00
Chris Smowton
14b8892ced Don't create interface forwarders for other interfaces, and target super accesses correctly
Intermediate interfaces don't need interface forwarders, since the Kotlin compiler won't try to make them non-abstract by synthesising methods.

Super references should always target an immediate superclass, not the ancestor containing the intended implementation.
2022-10-19 15:37:06 +01:00
Chris Smowton
7ba9a31766 Use US spelling 2022-10-19 10:41:29 +01:00
Josh Soref
0bc19506e7 spelling: reinitialised
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-10-19 04:59:16 -04:00
Josh Soref
0079ee3d54 spelling: annotation
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-10-19 04:59:16 -04:00
Chris Smowton
2713b3ee06 Comment extraction: don't treat anonymous classes differently 2022-10-18 11:10:29 +01:00
Tamás Vajk
0069fd9681 Merge pull request #10860 from tamasvajk/kotlin-clinit-static
Kotlin: Add `static` modifier to `clinit`
2022-10-18 11:39:34 +02:00
Chris Smowton
50f99d8e82 Don't produce interface forwarders directed at an abstract target 2022-10-18 10:31:01 +01:00
Chris Smowton
67aa6c7737 Merge pull request #10822 from smowton/smowton/feature/kotlin-collection-literals
Koltin: support collection literals
2022-10-18 09:45:59 +01:00
Tamas Vajk
b67a8877a7 Kotlin: Add static modifier to clinit 2022-10-18 09:26:06 +02:00
Tamás Vajk
543e2f5aab Merge pull request #10678 from tamasvajk/kotlin-type-param-modifiers
Kotlin: Extract type parameter modifiers (`reified`, `in`, `out`)
2022-10-18 09:10:57 +02:00
Chris Smowton
baaa06391c Extract interface forwarders with public visiblity 2022-10-17 18:43:12 +01:00
Chris Smowton
4201031ae0 Restrict interface override synthesis to cases where both the overriding class and the interface are Kotlin-defined.
If the interface is Java-defined and it provides a default interface implementation then real class-file default methods are being used and kotlinc won't synthesise anything. If the loaded .class file wasn't made by Kotlin, then we see all the real methods and there is no need to synthesise anything either.
2022-10-17 18:38:13 +01:00
Chris Smowton
e8a35983ee Implement Kotlin default interface method forwarding
Kotlin's implementation of defaults depends on the -Xjvm-default setting (or the @JvmDefault deprecated annotation, not implemented here): by default, actual interface class files don't use default method, and any class that would inherit one instead implements the interface calling a static method defined on TheInterface$DefaultImpls. With
-Xjvm-default=all or =all-compatibility, real interface default methods are emitted, with the latter retaining the DefaultImpls methods so that other Kotlin can use it.

Here I adopt a hybrid solution: create a real default method implementation, but also emit a forwarding method like `@override int f(int x) { return super.TheInterface.f(x); }`, because the Java extractor will see `MyClass.f` in the emitted class file and try to dispatch directly to it. The only downside is that we emit a default interface
method body for a prototype that will appear to be `abstract` to the Java extractor and which it will extract as such. I work around this by tolerating the combination `default abstract` in QL. The alternative would be to fully mimic the DefaultImpls approach, giving 100% fidelity to kotlinc's strategy and therefore no clash with the Java
extractor's view of the world.
2022-10-17 18:38:13 +01:00