Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private static Expression adaptImplicitParameter(ConstantVariables vars, TypeInf
}

private SoyExpression adaptReturnExpression(SoyExpression raw, SoyRuntimeType type) {
return raw.coerceTo(type.runtimeType());
return raw.coerceTo(type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ protected Statement visitAssignmentNode(AssignmentNode node) {
// ASM has no common type for object v. primitive representations. So we need to coerce the
// new value to fix within the bounds of the old value. This is mostly boxed v. unboxed and
// numeric conversions among primitives.
newValue = newValue.coerceTo(letOrParam.accessor().resultType());
newValue = newValue.coerceToTypeOf(letOrParam.accessor());

if (letOrParam instanceof Variable) {
// This is assignment on a let.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,34 @@ public SoyExpression coerceTo(Type runtimeType) {
// Field may be a subclass of SoyValue, so need to perform a cast.
return SoyExpression.forSoyValue(
boxed.soyType(), boxed.delegate.checkedCast(runtimeType));
} else if (BytecodeUtils.STRING_TYPE.equals(runtimeType)) {
} else if (runtimeType.equals(BytecodeUtils.STRING_TYPE)) {
return this.unboxAsStringOrJavaNull();
}
// Unhandled cases where we have a boxed value (list, message) but require an
// unboxed value.
}
return this;
}

public SoyExpression coerceTo(SoyRuntimeType soyRuntimeType) {
if (soyRuntimeType.runtimeType().equals(BytecodeUtils.LIST_TYPE)) {
Expression unboxed = unboxAsListOrJavaNull();
return (unboxed instanceof SoyExpression)
? (SoyExpression) unboxed
: SoyExpression.forList(soyRuntimeType.asListType(), unboxed);
} else if (!soyRuntimeType.isBoxed() && soyRuntimeType.isKnownProtoOrUnionOfProtos()) {
Expression unboxed = unboxAsMessageOrJavaNull(soyRuntimeType.runtimeType());
return (unboxed instanceof SoyExpression)
? (SoyExpression) unboxed
: SoyExpression.forProto(soyRuntimeType, unboxed);
}
return coerceTo(soyRuntimeType.runtimeType());
}

public SoyExpression coerceToTypeOf(Expression expression) {
if (expression instanceof SoyExpression) {
return coerceTo(((SoyExpression) expression).soyRuntimeType());
}
return coerceTo(expression.resultType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1631,10 +1631,12 @@ protected void visitExternNode(ExternNode node) {
JsDoc.Builder jsDocBuilder = JsDoc.builder();
for (FunctionType.Parameter param : node.getType().getParameters()) {
JsType jsType = getJsTypeForParamForDeclaration(param.getType());
jsDocBuilder.addParam("p$" + param.getName(), jsType.typeExpr());
jsDocBuilder.addParam("p$" + param.getName(), jsType.typeExpr()).addGoogRequires(jsType);
}
jsDocBuilder.addParameterizedAnnotation(
"return", getJsTypeForParamForDeclaration(node.getType().getReturnType()).typeExpr());
JsType returnType = getJsTypeForParamForDeclaration(node.getType().getReturnType());
jsDocBuilder
.addParameterizedAnnotation("return", returnType.typeExpr())
.addGoogRequires(returnType);

Statement body = generateAutoExtern(auto);
Expression function = Expressions.function(jsDocBuilder.build(), body);
Expand Down
Loading