Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java codegen produces invalid code for keys composed of tuples #1728

Closed
jberthold-da opened this issue Jun 18, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@jberthold-da
Copy link
Member

commented Jun 18, 2019

The latest changes to include keys into the generated Java code from a DAML model unfortunately produce invalid java code when the key type is tuple.
To reproduce, I used the Wolpertinger.daml example:

$ git diff
diff --git a/language-support/java/codegen/src/ledger-tests/daml/Wolpertinger.daml b/language-support/java/codegen/src/ledger-tests/daml/Wolpertinger.daml
index 163c7569..78e33da7 100644
--- a/language-support/java/codegen/src/ledger-tests/daml/Wolpertinger.daml
+++ b/language-support/java/codegen/src/ledger-tests/daml/Wolpertinger.daml
@@ -30,8 +30,8 @@ template Wolpertinger
     where
         signatory owner
 
-        key WolpertingerKey owner age : WolpertingerKey
-        maintainer key.owner
+        key (owner, age) : (Party, Decimal)
+        maintainer key._1
 
         agreement name <> " has " <> show wings <> " wings and is " <> show age <> " years old."
 
$ bazel build language-support/java/codegen:ledger-tests-model.jar
...
Building language-support/java/codegen/libledger-tests-model.jar.jar (1 source jar) failed (Exit 1): java failed: error executing command  ...
Execution platform: @io_tweag_rules_haskell//haskell/platforms:linux_x86_64_nixpkgs
/tests/wolpertinger/Wolpertinger.java:233: error: method map in class Optional<T> cannot be applied to given types;
      return fromIdAndRecord(event.getContractId(), event.getArguments(), event.getAgreementText(), event.getContractKey().map(Tuple2<String, BigDecimal>::fromValue));
                                                                                                                          ^
  required: Function<? super Value,? extends U>
  found: Tuple2<Str[...]Value
  reason: cannot infer type-variable(s) a,b
    (actual and formal argument lists differ in length)
  where U,T,a,b are type-variables:
    U extends Object declared in method <U>map(Function<? super T,? extends U>)
    T extends Object declared in class Optional
    a extends Object declared in method <a,b>fromValue(Value,Function<Value,a>,Function<Value,b>)
    b extends Object declared in method <a,b>fromValue(Value,Function<Value,a>,Function<Value,b>)
Target //language-support/java/codegen:ledger-tests-model.jar failed to build
INFO: Elapsed time: 2.644s, Critical Path: 2.20s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
$ 

Obviously the resulting code would not match the scala file in that test, but what fails here is actually the java compilation.
The fromValue function on Tuple2 requires two additional arguments to convert the components of the pair.
See #1586 (comment) on the relevant PR.

@stefanobaghino-da

This comment has been minimized.

Copy link
Member

commented Jun 18, 2019

On it, thanks for the report.

@stefanobaghino-da

This comment has been minimized.

Copy link
Member

commented Jun 18, 2019

Adding further detail as I investigate the bug: the codegen is broken for any key that takes type parameters, with tuples being a very important use case.

stefanobaghino-da added a commit that referenced this issue Jun 18, 2019

@mergify mergify bot closed this in #1743 Jun 18, 2019

mergify bot added a commit that referenced this issue Jun 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.