Summary

The mutator mockAuthentication does not compile when used in Kotlin code. The same applies for mutators that use mockAuthentication internally, for example mockUser(UserDetails).

Error:(141, 29) Kotlin: Type parameter bound for T in fun mockAuthentication(p0: Authentication!): T! where T : MockServerConfigurer! is not satisfied: inferred type WebTestClientConfigurer! is not a subtype of MockServerConfigurer!

Sample

this.client
        .mutateWith(mockAuthentication(TestingAuthenticationToken("principal", "credentials")))
        .get()
        .uri("/")
        .exchange()

Kotlin version is 1.3.70

Comment From: mindhaq

I can confirm this for mockUser(UserDetails).

spring-security 5.3.1 kotlin 1.3.71

Comment From: rwinch

@mindhaq Would you mind creating another ticket for that please?

Comment From: mindhaq

@rwinch my case is actually already mentioned in the ticket description, so I guess there is no need for another ticket which would only be a duplicate of this one. I'll clarify my comment.

Comment From: sendilkumarn

Yeah same here, It looks like Kotlin cannot infer the bounded types. check out here for the failing compilation.

Comment From: mindhaq

In my case, this compiles now with Kotlin 1.4.

spring-security 5.3.4 kotlin 1.4.10

Comment From: eleftherias

This is fixed in Kotlin 1.4 and greater, where the Kotlin team added a new type inference algorithm. Users on Kotlin 1.3.40 can opt to use the new algorithm by setting:

kotlinOptions {
    freeCompilerArgs += '-XXLanguage:+NewInference'
}