I found another very interesting quirk that I cann...
# scripting
o
I found another very interesting quirk that I cannot explain to myself... How can it be that there is a difference in what the Kotlin compiler does when comparing internal IntelliJ / Gradle compilation with script compilation? I had this function definition in my internal scripting language:
Copy code
@TransformationDsl
    infix fun <D : Any, VO> SetOperation<S, D>.by(valueMapper: ValueMapper<Any?, VO>) =
        apply { source = source.map(valueMapper) }
When this function is used in "normal IntelliJ" contexts, a call like this compiles and works just fine:
Copy code
set optional "overallWeightTransportation" from "GrossWeightTransportationQuantity" by unitCodeMapper
If you look very closely to my generics, the generic type
VO
is not really relevant to this function, it has not bounds, the usage of the parameter
valueMapper
when passed to the
map
function does not care about this generic type, as
map
accepts everything. I did not realize this was over-engineered until when compiled with the script compiler I got this error:
Copy code
set optional "overallWeightTransportation" from "GrossWeightTransportationQuantity" by unitCodeMapper //later mandatory
                                                                                    ^^ Cannot infer type for this parameter. Specify it explicitly.
                                                                                    ^^ Not enough information to infer type argument for 'VO'.
The key question is now: why does it work just fine in IntelliJ, but not in scripting compilation? Solution for my immediate problem was to replace
VO
with
*
of course... but the question remains... ;-)
c
Maybe a difference between K1 and K2?
o
In IntellJ I'm using K2... In the scripting env I really don't know what is used. But the strangest part is: in Kotlin 1.9 this was not a compile error while in Kotlin 2.1 - only using the script compiler - it is...