score:9

Accepted answer

first, try this:

$ scala -e 'def somethingafterreturn(): int = { println("that is ok.."); return 1; println("wtf is going on here?"); 3 }'

no errors, right?

then, try this:

$ scala -ywarn-dead-code -e 'def somethingafterreturn(): int = { println("that is ok.."); return 1; println("wtf is going on here?"); 3 }'

by default, scala ignore unreachable code.

score:0

the compiler sees the code after the return will never get executed and so he ignores it ... so i think

score:1

the compiler allows this because it is syntactically valid.


Related Query

More Query from same tag