0

why it gives an error?

when i run the following code in sololearn, it gives errors. fun main(args: Array<String>) { var arr : Array<Int>= arrayOf(1, 2, 3); println(arr[0]); println(arr[1]); println(arr[2]); } but when i run it after adding a space before "=" then it gives no error. fun main(args: Array<String>) { var arr : Array<Int> = arrayOf(1, 2, 3); println(arr[0]); println(arr[1]); println(arr[2]); }

18th Jun 2020, 7:27 AM
SLUser
2 odpowiedzi
+ 5
Splitting input into tokens has no knowledge of how they are going to be used so it always looks for the longest valid string. Since >= is a token for greater equal, that will always be returned over the greater and the equal tokens you expected. A smarter compiler could discover that and adjust in the syntax check, but the 1.3 version generates the same error (SoloLearn is 1.1).
18th Jun 2020, 5:55 PM
John Wells
John Wells - avatar
+ 3
The kotlin compiler seems to confuse >= with a greater than operator. [Edit] Greater equal🤦‍♂️
18th Jun 2020, 7:40 AM
Kevin ★