dimsuz
11/20/2020, 12:18 AMval property: String? in src/main and then in src/test I have if (property != null) property.length and this gives an error that property cannot be smart-casted, because it's defined in a different module. But it's the same [gradle] module!
Also I have just moved this class + its test from another module where there was no such error. Why can this happen? Drives me nuts. Tried to compile outside an IDE from console, same errors...turansky
11/20/2020, 12:22 AMnanodeath
11/20/2020, 12:23 AM?.let {}dimsuz
11/20/2020, 12:24 AMdimsuz
11/20/2020, 12:25 AMturansky
11/20/2020, 1:41 AMJoost Klitsie
11/20/2020, 7:37 AMval property: String?
get() = if (Random.nextInt(0, 100) < 50) null else "Its over 50"
then this: if (property != null) property.length might definitely throw null which might give issues with smartcastingJoost Klitsie
11/20/2020, 7:37 AMproperty?.length and not the good old fashioned java way of if (something != null)Vampire
11/20/2020, 8:29 AMinternal. Tests are compiled separately from the production code. Smart casts have some restrictions, like they don't work with custom getters or delegation, as then on each call the result could be different. If the to be smart-casted property is in a different module (compilation unit), then the code where the property is could be changed to a custom getter but the code where the smart cast was done is not recompiled as the other module stays binary compatible.dimsuz
11/20/2020, 9:01 AMinternal modifier which I then removed! My clame "nothing changed" was wrong above 😞 I didn't know that src/main and src/test are considered different "modules".Vampire
11/20/2020, 10:01 AMdimsuz
11/20/2020, 10:36 AM