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 generates duplicate methods for records depending on parameter usage order #2367

Closed
sriram-da opened this issue Aug 1, 2019 · 1 comment · Fixed by #2651
Closed
Assignees
Labels
component/java-ecosystem Java development experience

Comments

@sriram-da
Copy link

Hi,
We have discovered a few cases where a DAML record type with one or more type parameters results in the Java codegen creating classes that have duplicate functions defined in them. It appears the Java compiler complains that the functions are duplicate due to type erasure (?)

-- The following variations of a "StageCompleted" type result in Java code being generated with duplicate functions in a single class
data StageCompleted stage completionClause =
    StageCompleted with completionClause: completionClause; stageName: stage
  deriving (Eq, Show)
data StageCompleted stage completionClause =
    StageCompleted (completionClause, stage)
  deriving (Eq, Show)
data StageCompleted stage completionClause =
    StageCompleted (stage, completionClause, stage)
  deriving (Eq, Show)
data StageCompleted stage completionClause =
    StageCompleted (stage, stage)
  deriving (Eq, Show)
data StageCompleted stage =
    StageCompleted (stage, stage)
  deriving (Eq, Show)

Interestingly, changing the order of usage of the type parameters within the data type to reflect the order of declaration results in correct Java code generation

-- The following results in error free Java code gen
data StageCompleted stage completionClause =
    StageCompleted with stage: stage; completionClause: completionClause
  deriving (Eq, Show)
data StageCompleted completionClause stage =
    StageCompleted with completionClause: completionClause; stageName: stage
  deriving (Eq, Show)
data StageCompleted stage completionClause =
    StageCompleted (completionClause)
  deriving (Eq, Show)
@stefanobaghino-da stefanobaghino-da self-assigned this Aug 1, 2019
@stefanobaghino-da stefanobaghino-da added the component/java-ecosystem Java development experience label Aug 1, 2019
@stefanobaghino-da stefanobaghino-da changed the title Java codegen is generating duplicate functions Java codegen generates duplicate methods for records depending on parameter usage order Aug 23, 2019
@stefanobaghino-da
Copy link
Contributor

To complete the details needed to work on this ticket, typeclass derivation has no impact on the issue.

For readability and to make all cases compile, the following represents a minimal DAML source file that reproduces the issue (as tested against 997212c):

-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

daml 1.2
module ParametersOrder where

data Case1 first second =
    Case1 with second: second; first: first

data Case2 first second =
    Case2 (second, first)

data Case3 first second =
    Case3 (first, second, first)

data Case4 first second =
    Case4 (first, first)

data Case5 first =
    Case5 (first, first)

data Case6 first second =
    Case6 with first: first; second: second

data Case7 first second =
    Case7 with first: first; second: second

data Case8 first second =
    Case8 (second)

As already mentioned, cases 6-8 do not cause any issue.

Cases 1-5 produce duplicate fromValue and toValue methods, to decode and encode generated classes into their Protobuf representation: once the parameters to said methods are in the order presented in the type signature, the second time in the order provided in the constructor signature. The body of the methods is identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/java-ecosystem Java development experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants