Skip to content

Commit

Permalink
Panic if asked to generate multi-argument invokes (#1599)
Browse files Browse the repository at this point in the history
Presently, Java code generation does not support the
`MultiArgumentInputs` field on invokes. When set, this flag instructs
the generation of functions that take multiple independent arguments
instead of a single object containing all arguments. For example,
instead of:

```java
Class.function(FunctionArgs.build().setA(a).setB(b).build());
```

we might generate:

```java
Class.function(a, b);
```

Since it is not supported, the correct behaviour is to panic and abort
code generation, as we do in other languages with this limitation (e.g.
Python). Currently, however, Java does not, proceeding instead to
generate incorrect code. This change fixes that, panicking if
`MultiArgumentInputs` is true. This is technically breaking, but a bug
fix (and in theory, any SDKs we have generated would already be
panicking for Python, so the feeling is that this likely not a highly
used feature).

Fixes #1598
  • Loading branch information
lunaris authored Jan 21, 2025
1 parent 06f5259 commit 44a0778
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
- Bump core SDK versions in generated code
- Emit plugin download URL in default resource options of the generated SDKs

### Bug Fixes

### Bug Fixes

- Panic when asked to generate SDKs involving multi-argument invokes
7 changes: 7 additions & 0 deletions pkg/codegen/java/gen_program_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package java

import (
"fmt"
"io"
"math/big"
"strings"
Expand Down Expand Up @@ -322,6 +323,12 @@ func (g *generator) GenFunctionCallExpression(w io.Writer, expr *model.FunctionC
// Assuming the existence of the following helper method
g.Fgenf(w, "computeFileBase64Sha256(%v)", expr.Args[0])
case pcl.Invoke:
if expr.Signature.MultiArgumentInputs {
err := fmt.Errorf("Java program-gen does not implement MultiArgumentInputs for function '%v'",
expr.Args[0])
panic(err)
}

fullyQualifiedType, funcName := g.functionImportDef(expr.Args[0])
if !g.emittedTypeImportSymbols.Has(fullyQualifiedType) {
// the fully qualified name isn't emitted
Expand Down

0 comments on commit 44a0778

Please sign in to comment.