mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Introduce missing tests for immediate SpEL compilation for Elvis operator
This commit is contained in:
@@ -98,7 +98,11 @@ public class Elvis extends SpelNodeImpl {
|
||||
|
||||
@Override
|
||||
public void generateCode(MethodVisitor mv, CodeFlow cf) {
|
||||
// exit type descriptor can be null if both components are literal expressions
|
||||
// If both elements are literals and the expression was not previously
|
||||
// evaluated in interpreted mode -- or if getValueInternal() did not
|
||||
// properly invoke computeExitTypeDescriptor() -- we may get here without
|
||||
// the exit descriptor having been computed, so we must ensure the exit
|
||||
// descriptor has been computed before proceeding.
|
||||
computeExitTypeDescriptor();
|
||||
|
||||
cf.enterCompilationScope();
|
||||
|
||||
+17
@@ -1470,6 +1470,23 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/String");
|
||||
}
|
||||
|
||||
@Test
|
||||
void elvisWithImmediateCompilation() {
|
||||
expression = parser.parseExpression("'a' ?: 'b'");
|
||||
// Both literals, so we can compile immediately without having previously
|
||||
// evaluated the expression.
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(String.class)).isEqualTo("a");
|
||||
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/String");
|
||||
|
||||
expression = parser.parseExpression("null ?: 'a'");
|
||||
// Both literals, so we can compile immediately without having previously
|
||||
// evaluated the expression.
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(String.class)).isEqualTo("a");
|
||||
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/Object");
|
||||
}
|
||||
|
||||
@Test // gh-19758
|
||||
void elvisMiscellaneous() {
|
||||
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
|
||||
|
||||
Reference in New Issue
Block a user