Irritating implicit return


#1

I find the following behavior with implicit return pretty irritating:

>>> fun calc(a: Int): Int {
...     println(a)
...     a * a
... }
>>> calc(3)
3
0

It would make sense to return 9 or to issue a compilation error, but this behavior doesn’t make any sense. Or do I miss something?

>>> fun calc(a: Int): Int {
...     println(a)
...     return a * a
... }
>>> calc(3)
3
9

With an explicit return everything is as expected.

As far as I know an implicit return is only allowed in single expression funktions, but why is it allowed in the first case then?


#2

This is a bug in the REPL: https://youtrack.jetbrains.com/issue/KT-13015