[
https://issues.apache.org/jira/browse/GROOVY-11263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17802304#comment-17802304
]
ASF GitHub Bot commented on GROOVY-11263:
-----------------------------------------
daniellansun commented on PR #2023:
URL: https://github.com/apache/groovy/pull/2023#issuecomment-1875821378
We can add a option to prevent or warn dead code or disable check totally.
Here is the table to show how mainstream programming language to handle dead
code. Most of them prevent or warn the dead code, so I think it's good choice
for Groovy to align with most of them.
| Language | Allows Consecutive `return` (Dead Code) | Compiler/Interpreter
Behavior |
|----------|---------------------------------------|-------------------------------|
| Java | No | Marks as unreachable
code, may cause a compile error. |
| C++ | Yes | Might warn but allows
compilation. |
| C# | No | Identifies unreachable
code, causes a compile error. |
| Python | Yes | Does not prevent dead
code, allows execution. |
| Scala | Yes | Might issue a warning
but allows compilation. |
| Kotlin | No | Detects unreachable
code, causes a compile error. |
| JavaScript | Yes | Does not check for
dead code at compile time. |
> Analyze dead code
> -----------------
>
> Key: GROOVY-11263
> URL: https://issues.apache.org/jira/browse/GROOVY-11263
> Project: Groovy
> Issue Type: Improvement
> Reporter: Daniel Sun
> Priority: Major
> Labels: breaking_change
> Fix For: 5.x
>
>
> As we all know, source code is meant for developers to read, and the less
> redundant code there is, the more developer-friendly it becomes, but Groovy
> allows dead code after {{throw}}, {{return}}, {{break}} and {{continue}}, e.g.
> {code:java}
> def m() {
> return
> def a = 1
> }
> {code}
> It's better to avoid such dead code.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)