-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Kotlin: fix cases where type variables were used out of scope #9123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin: fix cases where type variables were used out of scope #9123
Conversation
// References to SomeGeneric<T1, T2, ...> where SomeGeneric is declared SomeGeneric<T1, T2, ...> are extracted | ||
// as if they were references to the unbound type SomeGeneric. | ||
val extractedTypeArgs = when { | ||
c.symbol.isKFunction() && typeArgs != null && typeArgs.isNotEmpty() -> listOf(typeArgs.last()) | ||
extractClass.symbol.isKFunction() && typeArgs != null && typeArgs.isNotEmpty() -> listOf(typeArgs.last()) | ||
extractClass.fqNameWhenAvailable == FqName("kotlin.jvm.functions.FunctionN") && typeArgs != null && typeArgs.isNotEmpty() -> listOf(typeArgs.last()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test case for this? How come we didn't see this issue before? We have tests that cover big-arity functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add one -- I think we simply didn't notice or care that the type extracted was FunctionN<FirstArgumentType>
not FunctionN<ReturnType>
. It's probably not a critical bug but rather a weird surprise waiting for someone down the line.
Are the kotlin CI tests running on this PR? If not, I think it would make sense to open the PR still in the private repo. |
@tamasvajk it appears yes they are-- in recent runs of the semmle-code job
I believe our integration tests are not running however: I'll make a PR to fix this later today. |
Ah no I take it back, we do run the Kotlin integration tests. To check: do we have the right file filters selecting when the integration tests run, and do we need a single-language tests job for Kotlin? |
6024ec6
to
2f55999
Compare
@tamasvajk added a test -- if you revert the commit "Fix extracted type arguments of kotlin.jvm.functions.FunctionN" then you'll see the FunctionN type arguments change improperly (note their pretty-printed names work but the actual argument disagrees):
|
2f55999
to
189b555
Compare
Requires semmle-code PR https://github.com/github/semmle-code/pull/42569 |
The selection of type variables mentioned in a particular class previously didn't work as intended, so the consistency query would always pass.
Otherwise references to type variables declared on kotlin.Xyz.someFunction can refer to its Java equivalent java.Xyz.someFunction if it has one.
…rameters I had forgotten that the Java QL lib regards a ParameterizedType as either an instantiation Generic<String>, or the unbound declaration Generic<T>.
…nterface implementations For example, in implementing Producer<T> by an actual lambda of type () -> Int, the return type should be Int, not T. This produced type-variable-out-of-scope consistency check failures.
Previously we accidentally extracted an argument type instead of the result type.
…lements that declare type parameters.
This makes debugging a little easier.
These are mainly moving the source locations and type specialisations in SAM-converted methods.
The Java extractor assigns a type with unbound type variables to the result of ImmutableSortedMap.of calls.
6180996
to
e722c99
Compare
…gs relating to this query
One test failure is expected (taken care of by the corresponding internal PR); one is an unrelated failure also affecting |
This is temporarily based on #9122 -- the real diff is smowton/codeql@smowton/admin/update-kotlin...smowton:smowton/fix/type-variable-in-scope-consistency