Skip to content

Commit

Permalink
Fix bug with externs returning nullable versions of Java primitives.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 679285563
  • Loading branch information
Jesse-Good authored and copybara-github committed Sep 26, 2024
1 parent e5ad046 commit e1dbc7b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions java/src/com/google/template/soy/jbcsrc/ExternCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,22 @@ private static Expression adaptImplicitParameter(ConstantVariables vars, TypeInf
* <p>In some cases (e.g. List) we happen to tolerate the extern returning null.
*/
static Expression adaptReturnType(Type returnType, SoyType soyReturnType, Expression externCall) {
boolean nullish = SoyTypes.isNullish(soyReturnType);
Type externType = externCall.resultType();

if (externType.equals(BytecodeUtils.BOXED_INTEGER_TYPE)) {
if (!nullish && externType.equals(BytecodeUtils.BOXED_INTEGER_TYPE)) {
return JbcSrcExternRuntime.UNBOX_INTEGER.invoke(externCall);
} else if (externType.equals(Type.INT_TYPE)) {
return BytecodeUtils.numericConversion(externCall, Type.LONG_TYPE);
} else if (externType.equals(BytecodeUtils.BOXED_LONG_TYPE)) {
} else if (!nullish && externType.equals(BytecodeUtils.BOXED_LONG_TYPE)) {
return JbcSrcExternRuntime.UNBOX_LONG.invoke(externCall);
} else if (externType.equals(BytecodeUtils.BOXED_DOUBLE_TYPE)) {
} else if (!nullish && externType.equals(BytecodeUtils.BOXED_DOUBLE_TYPE)) {
return JbcSrcExternRuntime.UNBOX_DOUBLE.invoke(externCall);
} else if (externType.equals(Type.FLOAT_TYPE)) {
return BytecodeUtils.numericConversion(externCall, Type.DOUBLE_TYPE);
} else if (externType.equals(BytecodeUtils.BOXED_FLOAT_TYPE)) {
} else if (!nullish && externType.equals(BytecodeUtils.BOXED_FLOAT_TYPE)) {
return JbcSrcExternRuntime.UNBOX_FLOAT.invoke(externCall);
} else if (externType.equals(BytecodeUtils.BOXED_BOOLEAN_TYPE)) {
} else if (!nullish && externType.equals(BytecodeUtils.BOXED_BOOLEAN_TYPE)) {
return JbcSrcExternRuntime.UNBOX_BOOLEAN.invoke(externCall);
} else if (externType.equals(BytecodeUtils.OBJECT.type())
|| externType.equals(BytecodeUtils.NUMBER_TYPE)) {
Expand Down

0 comments on commit e1dbc7b

Please sign in to comment.