google / google/closure-templates

compiler crashes with integer overflow when evaluating expressions

Open
#54 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
700
Forks
199
Avg merge
2d 12h
Merged PRs (30d)
26

Description

```
{namespace examples.overflow}

/**
* test
*/
{template .test}
{let $y: 1000 * 1000 * 1000 * 1000 /}
{/template}
```

Crashes with the following exception:

```
$ java -jar target/soy-2.5.0-SNAPSHOT-SoyToJsSrcCompiler.jar --outputPathFormat simple.js --srcs hello.soy
INTERNAL SOY ERROR.
Please open an issue at https://github.com/google/closure-templates/issues with this stack trace and repro steps
java.lang.IllegalStateException: Casting long to integer results in overflow: 1000000000000
at com.google.common.base.Preconditions.checkState(Preconditions.java:200)
at com.google.template.soy.data.restricted.IntegerData.integerValue(IntegerData.java:130)
at com.google.template.soy.data.internalutils.InternalValueUtils.convertPrimitiveDataToExpr(InternalValueUtils.java:66)
at com.google.template.soy.sharedpasses.opti.SimplifyExprVisitor.attemptPreeval(SimplifyExprVisitor.java:231)
at com.google.template.soy.sharedpasses.opti.SimplifyExprVisitor.visitExprNode(SimplifyExprVisitor.java:204)
```

Reproduced with the compiler at head.

This is perfectly valid javascript because numbers are doubles? And in Java, it should convert to double or long?

Relatedly, it's not clear to me why the soy compiler is trying to evaluate the expression at all? This seems like something the Java or JS compiler would be more effective at.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.