https://kotlinlang.org logo
Title
d

dsavvinov

04/19/2018, 4:32 PM
Let us move to thread, as this seems to cause quite a lot of clutter in global channel.
Now you're calling sequence of
plus
on
1000
instead of a whole hours-millis value. This is because dot-call
.
takes precedence over multiplication: https://kotlinlang.org/docs/reference/grammar.html#precedence This works as expected for me:
val millis: Long = (calendar.get(Calendar.HOUR_OF_DAY).toLong() * 60 * 60 * 1000)
        .plus(calendar.get(Calendar.MINUTE).toLong() * 60 * 1000)
        .plus(calendar.get(Calendar.SECOND).toLong() * 1000)
        .plus(calendar.get(Calendar.MILLISECOND).toLong())

 val millis2: Long = calendar.get(Calendar.HOUR_OF_DAY).toLong() * 60 * 60 * 1000 +
        calendar.get(Calendar.MINUTE).toLong() * 60 * 1000 +
        calendar.get(Calendar.SECOND).toLong() * 1000 +
        calendar.get(Calendar.MILLISECOND).toLong()

 Assert.assertEquals(millis, millis2)
@alvico
I don't think Kotlin is much different from other languages here. If you have some proposals regarding our grammar, feel free to share them in #language-proposals or in our tracker (kotl.in/issue)
a

alvico

04/19/2018, 4:38 PM
Well it's the first language that I've found that multiline sum doesn't work :S
something I can do in java without any problems
and the fact that it compiles and executes is very annoying. what one would expect of this operation
d

dsavvinov

04/19/2018, 4:41 PM
It certainly works, as I've demonstrated above. Because users can override operators, in general case one can expect anything from such operation (e.g. such constructions make perfect sense for DSLs). As I've said, for primitive types we could do better and report that expression is unused. You can watch for updates on this ticket https://youtrack.jetbrains.com/issue/KT-12073
a

alvico

04/19/2018, 4:41 PM
I'm happy with a warning
Sorry if I sounded a bit harsh, was frustrated after a whole day debugging a simple operation
I just couldn't imagine that a primitive operation wouldn't work in multiline sintax
d

dsavvinov

04/19/2018, 4:46 PM
was frustrated after a whole day debugging a simple operation
Yep, I certianly understand it. Sorry for that 🙂
a

alvico

04/19/2018, 4:47 PM
np, thanks for the quick answer and feedback anyway
p

poohbar

04/19/2018, 5:56 PM
It's a best practice to end multiline math operations with an operator so that you know that there is another line coming. So I am ok with it working this way. An IntelliJ warning on the line with the unused expression would be a welcome addition though.
2