Commit Graph

13956 Commits

Author SHA1 Message Date
Chris Smowton
d103bf65bd Remove inapplicable TODO re: K<->J type substitution
Turns out the two use cases the TODO worried about are already taken care of: `Unit` is replaced with `void` only in contexts where primitives can be used, and `List` and similar only have incompatible extension methods, which are declared by `CollectionsKt` not `List`. This is likely deliberate to enable the Kotlin <-> Java substitution to be implemented simply by kotlinc.
2022-05-10 19:51:17 +01:00
Chris Smowton
d593185a8c Quieten errors relating to generic type aliases
Turns out type aliases are always substituted by the compiler, with the `IrSimpleType.abbreviation` field indicating what the original alias was if any. Therefore we're already extracting the right types. This commit simply omits extracting a kt_type for a type alias that uses type parameters as this certainly won't work at present because we don't have IrTypes for the type parameters declared by the alias and used in its RHS.
2022-05-10 19:51:17 +01:00
Chris Smowton
1d47ea30eb Remove unused function 2022-05-10 19:51:17 +01:00
Chris Smowton
f6db91f294 Update test expectations 2022-05-10 19:51:17 +01:00
Chris Smowton
7dec3f4835 Use EqualityTest for either value or ref comparions, and ReferenceEqualityTest for strictly ref comparison. 2022-05-10 19:51:17 +01:00
Chris Smowton
f95effcf82 Always extract ValueEQ/NEExpr for Kotlin ==/!=
I introduce AnyEqualsExpr for either reference or value equality and AnyEqualityTest for the same concept including not-equals operators, and use them wherever the written QL clearly doesn't care about the difference between reference and value comparison, typically because it is concerned with testing against null or against a primitive constant.
2022-05-10 19:51:17 +01:00
Chris Smowton
a120fab9f7 Complete implementation of equality tests
- Create a new operator representing an infix value [in]equality test, equivalent to Objects.equals(lhs, rhs)
- Continue to use simple equality where it is clearly possible at the callsite
- Note that ieee754equals is the same as Java's == and != operators
2022-05-10 19:51:17 +01:00
Ian Lynagh
97793b58cd Kotlin: Tweak diagnostic writing
In particular, we now write full exception information, so we can
diagnose problems.

We were using `warn` to log errors in some cases, and generally using
lower-level functions than necessary. We now use the appropriate
functions. I've lost the distinction between e.g. ErrorHigh and ErrorSevere
in this, but we can add it back if it's important.
2022-05-10 19:51:16 +01:00
Ian Lynagh
48c4438a78 Kotlin: Rename the final warn function to diagnostic 2022-05-10 19:51:16 +01:00
Ian Lynagh
ee9f9bb07e Kotlin: Move a function 2022-05-10 19:51:16 +01:00
Ian Lynagh
79f80e6541 Kotlin: Rename CODEQL_EXTRACTOR_KOTLIN_WARNING_LIMIT to CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT 2022-05-10 19:51:16 +01:00
Ian Lynagh
a25b411dd0 Kotlin: Rename "warning" to "diagnostic" a lot 2022-05-10 19:51:16 +01:00
Ian Lynagh
458cb850a7 Kotlin: Accept test changes 2022-05-10 19:51:16 +01:00
Ian Lynagh
9296bf3079 Kotlin: Write extractor name to TRAP file metadata 2022-05-10 19:51:16 +01:00
Chris Smowton
629af664c6 Explicitly specify whether a dispatch or an extension receiver is intended 2022-05-10 19:51:16 +01:00
Chris Smowton
377bd8f2e9 Extract String?.plus as either an AddExpr or a call to an intrinsic
If it is used by the compiler to implement the infix plus operator, resugar it and extract a `+` as Java would. If it is literally called by the user (e.g. `(if (x) then "not null" else null).plus(something)`), then extract a call to the real method Intrinsics.stringPlus (a two-arg static method).
2022-05-10 19:51:16 +01:00
Chris Smowton
93e8d5a2d6 Add tests for mutually-recursive types 2022-05-10 19:51:16 +01:00
Chris Smowton
8bb23651ae Extract type parameter bounds 2022-05-10 19:51:16 +01:00
Tamas Vajk
ec5bc8dad5 Add workaround for unbound symbols (get stub from descriptor) 2022-05-10 19:51:16 +01:00
Tamas Vajk
2965e780cc Add local dataflow test for string templates 2022-05-10 19:51:16 +01:00
Tony Torralba
6bd6097ed1 Add taint step for StringTemplateExpr 2022-05-10 19:51:16 +01:00
Tamas Vajk
b7914ed77b Code quality improvements 2022-05-10 19:51:16 +01:00
Tamas Vajk
695b3a6dbd Add fallback symbol lookup for IrFunctionReference extraction 2022-05-10 19:51:16 +01:00
Tamas Vajk
d495badc1e Rename companion object QL class 2022-05-10 19:51:16 +01:00
Tamas Vajk
535610452f Fix missing newline in DB scheme generator 2022-05-10 19:51:16 +01:00
Chris Smowton
b9d8fe72f0 TRAP formatting: adopt Java's standards
* Encode dates with D"" strings
* Truncate exceedingly long string values
* Note that floats don't require any special handling
2022-05-10 19:51:16 +01:00
Tamas Vajk
4adf5829e4 Fix expected files 2022-05-10 19:51:16 +01:00
Tamas Vajk
9ff9bbe1c5 Fix merge conflict 2022-05-10 19:51:16 +01:00
Tamas Vajk
b4beddf2f9 Introduce cast for <unsafe-coerce> calls 2022-05-10 19:51:15 +01:00
Ian Lynagh
8d754f5129 Kotlin: Fix bug in, and performance of, NullGuards::clearlyNotNullExpr 2022-05-10 19:51:15 +01:00
Ian Lynagh
03c1845053 Kotlin: Add a TODO comment 2022-05-10 19:51:15 +01:00
Ian Lynagh
76ca0b2776 Kotlin: Pull Kotlin type for localvars out into its own table 2022-05-10 19:51:15 +01:00
Ian Lynagh
7862229807 Kotlin: Pull Kotlin type for params out into its own table 2022-05-10 19:51:15 +01:00
Ian Lynagh
dc26abe341 Kotlin: Pull Kotlin type for methods/constrs out into their own tables 2022-05-10 19:51:15 +01:00
Ian Lynagh
ee008773dc Kotlin: Pull Kotlin type for fields out into its own table 2022-05-10 19:51:15 +01:00
Ian Lynagh
0f7f90dd4e Kotlin: Add a consistency query for Kotlin types 2022-05-10 19:51:15 +01:00
Ian Lynagh
86bf126ed8 Kotlin: Pull Kotlin type for expressions out into its own table 2022-05-10 19:51:15 +01:00
Tamas Vajk
cd5555a5dd Extract companion objects from interfaces 2022-05-10 19:51:15 +01:00
Tamas Vajk
53f40a3f31 Do not extract fake properties 2022-05-10 19:51:15 +01:00
Tamas Vajk
5c38b4e84d Extract expression body 2022-05-10 19:51:15 +01:00
Chris Smowton
4d408159aa When extracting a call to an inherited method, substitute the callee's type parameters appropriately. 2022-05-10 19:51:15 +01:00
Chris Smowton
8c9c37ca47 Revert "Kotlin: Extract fake overrides for now"
This reverts commit a1ffa7b66b6bc1a9b6fd93da60e7a16c0dc2fb21.
2022-05-10 19:51:15 +01:00
Ian Lynagh
16a27f5258 Kotlin: Provide a way for tests to cause an exception 2022-05-10 19:51:15 +01:00
Ian Lynagh
89eae2407b Kotlin: Improve error handling
Each compilation, and each file within a cmopilation, now gets a
"result" indicating whether it had recoverable or non-recoverable
errors.
2022-05-10 19:51:15 +01:00
Tamas Vajk
4c68b583de Do not report negative index warning on extension parameters 2022-05-10 19:51:15 +01:00
Ian Lynagh
8d15d0acfb Kotlin: Extract fake overrides for now
When we have Kotlin:

class A {
    fun foo(z: OB<G1, G2>.B<E1, E2>) {
        val foo = z.someFun()
    }
}

and Java:

public class OB<S1, S2> extends OC<F1, F2> {
        public class B<T1, T2> extends OC<F1, F2>.C<D1, D2, T1, T2> {
        }
}

class OC<U1, U2> {
        public class C<X1, X2, Y1, Y2> {
            int someFun() {
                return 5;
            }
        }
}

the `someFun` call is to a fake override, and has 4 type arguments.
If we treat it as calling the real function, then 6 type are expected,
and we get IndexOutOfBoundsException when we try to reorder the
type parameters in orderTypeArgsLeftToRight.

So for now, we just extract the fake overrides, so that we at least
don't crash.
2022-05-10 19:51:15 +01:00
Ian Lynagh
46ccd45833 Kotlin: Add tests for fake overrides 2022-05-10 19:51:15 +01:00
Chris Smowton
fdb1668cff CommentExtractor: use actual file label instead of hopefully correctly guessing its string form 2022-05-10 19:51:15 +01:00
Tamas Vajk
bb7e01988a Change kotlin dependency version from 1.6.0-RC2 to 1.6.10 2022-05-10 19:51:15 +01:00
Chris Smowton
0d90148f3e Prefer the Kotlin extractor's version of trap files 2022-05-10 19:51:15 +01:00