diff --git a/java/src/com/google/template/soy/jbcsrc/ExpressionCompiler.java b/java/src/com/google/template/soy/jbcsrc/ExpressionCompiler.java index 0451f9eaba..76747396e9 100644 --- a/java/src/com/google/template/soy/jbcsrc/ExpressionCompiler.java +++ b/java/src/com/google/template/soy/jbcsrc/ExpressionCompiler.java @@ -1615,7 +1615,7 @@ private SoyExpression visitFieldAccess(SoyExpression baseExpr, FieldAccessNode n if (sourceMethod != null) { Optional externApi = ExternAdaptors.asExtern(sourceMethod, args); if (externApi.isPresent()) { - return callExtern(externApi.get(), args); + return callExtern(externApi.get(), args, node.getType()); } return sourceFunctionCompiler.compile(node, sourceMethod, args, parameters, detacher); } @@ -1771,7 +1771,7 @@ var record = (RecordLiteralNode) node.getChild(1); visitAllParams(node, ImmutableList.builder().add(baseExpr)); Optional externApi = ExternAdaptors.asExtern(sourceMethod, args); if (externApi.isPresent()) { - return callExtern(externApi.get(), args); + return callExtern(externApi.get(), args, node.getType()); } return sourceFunctionCompiler.compile(node, sourceMethod, args, parameters, detacher); } @@ -2023,13 +2023,14 @@ SoyExpression visitPluginFunction(FunctionNode node) { return callExtern( ExternAdaptors.asExtern( (SoyJavaExternFunction) fn, args, node.getType(), node.getAllowedParamTypes()), - args); + args, + node.getType()); } else if (fn instanceof SoyJavaSourceFunction) { ImmutableList args = visitAllParams(node); return sourceFunctionCompiler.compile( node, (SoyJavaSourceFunction) fn, args, parameters, detacher); } else if (fn instanceof Extern) { - return callExtern((Extern) fn, visitAllParams(node)); + return callExtern((Extern) fn, visitAllParams(node), node.getType()); } else if (fn == FunctionNode.FUNCTION_POINTER) { FunctionType functionType = node.getNameExpr().getType().asType(FunctionType.class); SoyRuntimeType soyReturnType = ExternCompiler.getRuntimeType(functionType.getReturnType()); @@ -2107,7 +2108,8 @@ private ImmutableList visitAllParams( return builder.build(); } - private SoyExpression callExtern(Extern extern, List params) { + private SoyExpression callExtern( + Extern extern, List params, SoyType resolvedReturnType) { SourceLogicalPath path = extern.getPath(); JavaImpl javaImpl = extern.getJavaImpl(); boolean hasJavaImpl = javaImpl != null || extern.hasAutoImpl(); @@ -2125,7 +2127,7 @@ private SoyExpression callExtern(Extern extern, List params) { linkStatically = hasJavaImpl && owningFile.getSoyFileKind() == SoyFileKind.SRC; } FunctionType functionType = extern.getSignature(); - SoyRuntimeType soyReturnType = ExternCompiler.getRuntimeType(functionType.getReturnType()); + SoyRuntimeType soyReturnType = ExternCompiler.getRuntimeType(resolvedReturnType); boolean requiresRenderContext = !linkStatically || requiresRenderContext(extern); if (extern.isJavaAsync()) { @@ -2199,7 +2201,7 @@ private SoyExpression callExtern(Extern extern, List params) { externCall = ExternCompiler.adaptReturnType( getTypeInfoForJavaImpl(javaImpl.returnType().className()).type(), - functionType.getReturnType(), + resolvedReturnType, externCall); // Allow ExternSourceFunction to return a boxed value. if (isDefinitelyAssignableFrom(SOY_VALUE_TYPE, externCall.resultType())) {