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.
Source: stackoverflow.com
Related Query
- Why no dead code warning after return statement?
- Why does this getOrElse statement return type ANY?
- Why does spark-shell print thousands lines of code after count on DataFrame with 3000 columns? What's JaninoRuntimeException and 64 KB?
- Why is a return statement required to allow this while statement to be evaluated properly?
- Why does authorize directive execute after the code it's supposed to protect?
- Why does this code returns Unit, whereas I expect it to return some other values?
- Why is return required in this code block?
- OPAL: Why can SingleOriginReference not be found any more after externalizing code into a method?
- why am i not able to return the Dataframe for this scala code
- Why would an akka router be sending messages to dead letters after startup?
- Why is the return type of a method, a class name in the below code of scala?
- Why does "split" on an empty string return a non-empty array?
- Why does join fail with "java.util.concurrent.TimeoutException: Futures timed out after [300 seconds]"?
- Why does a small change to this Scala code make such a huge difference to performance?
- Why is this Scala code with assignment of a val in a parameter working?
- Why does Scala choose to have the types after the variable names?
- Forward References - why does this code compile?
- Why do I get `java.lang.NoClassDefFoundError: scala/Function1` when I run my code in ScalaIDE?
- Why do I get 'Dead code following this construct' with the following code?
- Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?
- Why sbt runs dependency resolution every time after clean?
- Why doesn't Array's == function return true for Array(1,2) == Array(1,2)?
- Why does Scala require a return type for recursive functions?
- In Scala, why could remainder (%) operator return a negative number?
- Why this scala code reports compilation error: recursive value x needs type
- Execute code before and after specification
- In Scala, why unchecked warning is not issued for type arguments?
- scala: problems with return statement
- Scala collections: why do we need a case statement to extract values tuples in higher order functions?
- Why can a method returning Unit be overridden with method returning String when return types are not explicitly given?
More Query from same tag
- Using scala vararg methods in java
- Why is it possible to instantiate multiple traits in Scala, but not a single one?
- How to read gzip'd file in Scala
- Play Framework 2, why Actions and Requests take a type parameter?
- Importing required external implicits or merging implicits to get one common import
- dependency resolution with sbt for continuous integration
- Using fold or map to convert a collection
- How to fix "error: not found: type CosmosDBSourceProvider" in databricks scala read stream from cosmos db
- dataframe filter gives NullPointerException
- F#: referential transparency of `nameof` operator
- How to join and reduce two datasets with arrays?
- Can't import sqlContext.implicits._ without an error through Jupyter
- Scalaz implementation of Semigroup using advanced Scala features
- Sign CSR using Bouncy Castle
- Filter in functional languages with original non-filtered elements?
- Scala type-safety vs overhead (type vs class)
- How to aggregate on two columns in Spark SQL
- Java Listener interface to Scala
- Can sealed trait contain Tuples?
- using dbpedia spotlight in java or scala
- Scala build process
- read <td>-tag value from a scala for-loop created table
- Remove unique items from sequence
- process a text file with xml column in apache spark scala
- How to create a regex pattern for a specific pattern in json file in scala
- Call play2 template with variable arguments of type Html
- My Kafka Producer code just runs well without any exception, but no data is sent in brokers
- how can I edit the spark mllib source code locally in Intelij?
- Why is Akka HTTP Routing Catching My Exception?
- How to extend case class with type parameter?