[ https://issues.apache.org/jira/browse/GROOVY-10156?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-10156: --------------------------------- Labels: bytecode enum (was: bytecode) > Unreachable bytecode in switch statement > ---------------------------------------- > > Key: GROOVY-10156 > URL: https://issues.apache.org/jira/browse/GROOVY-10156 > Project: Groovy > Issue Type: Improvement > Components: Compiler > Affects Versions: 3.0.8 > Environment: JVM: 11.0.11 (Oracle Corporation 11.0.11+9-LTS-194) > OS: Mac OS X 10.16 x86_64 > Reporter: Damir Murat > Priority: Minor > Labels: bytecode, enum > > When switching over an enum, and for two or more case branches, groovy > generates unreachable bytecode for each case branch except the last one. > For example > {code:java} > package mypackage > import groovy.transform.CompileStatic > @CompileStatic > class SwitchDemo { > void mySwitchMethod(MyEnum myEnum) { > switch (myEnum) { > case MyEnum.ONE: > println "ONE" > break > case MyEnum.TWO: > println "TWO" > break > case MyEnum.THREE: > println "TWO" > break > default: > println "default" > break > } > } > } > @CompileStatic > enum MyEnum { > ONE, TWO, THREE > } > {code} > generates bytecode sequences like > {code:java} > ... > L8 > L9 > LINENUMBER 12 L9 > GOTO L10 > L3 > L11 > LINENUMBER 12 L11 > ALOAD 2 > GETSTATIC mypackage/MyEnum.TWO : Lmypackage/MyEnum; > INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.isCase > (Ljava/lang/Object;Ljava/lang/Object;)Z > IFEQ L12 > L10 > ... > {code} > It looks like the first four lines above are not necessary. This results in > {noformat} > nop, nop, athrow > {noformat} > sequences in generated java bytecode. > It would be great if this can be cleaned up and fixed. My scenario is related > to JaCoCo reports which are not accurate and a bit confusing for switch > statements. > Tnx -- This message was sent by Atlassian Jira (v8.20.10#820010)