mirror of
https://github.com/github/codeql.git
synced 2025-12-19 18:33:16 +01:00
These feature substituted types according to their declaring generic specialisation, with wildcards that reach top-level being converted to their upper or lower bound depending on usage context. This commit also includes an incidental fix such that constructors declare their return-type as unit, consistent with the Java extractor.
28 lines
533 B
Kotlin
28 lines
533 B
Kotlin
class Generic<T>(init: T) {
|
|
|
|
var stored = init
|
|
|
|
fun identity2(param: T): T = identity(param)
|
|
fun identity(param: T): T = param
|
|
fun getter(): T = stored
|
|
fun setter(param: T) { stored = param }
|
|
|
|
}
|
|
|
|
fun user() {
|
|
|
|
val invariant = Generic<String>("hello world")
|
|
invariant.identity("hello world")
|
|
invariant.identity2("hello world")
|
|
|
|
val projectedOut: Generic<out String> = invariant
|
|
projectedOut.getter()
|
|
|
|
val projectedIn: Generic<in String> = invariant
|
|
projectedIn.setter("hi planet")
|
|
projectedIn.getter()
|
|
|
|
}
|
|
|
|
|