Skip to content

ADT unions are prone to member naming conflicts #1862

Description

@kubukoz

Given:

$version: "2"
namespace a

@smithy4s.meta#adt union U { a: a#A, b: b#A }

structure A{}

and

$version: "2"

namespace b

structure A {}

Generating code will cause compilation conflicts in U:

[error] ./a/U.scala:47:3
[error] A is already defined as class A
[error] ./a/U.scala:51:3
[error] A is already defined as object A
[error] ./a/U.scala:26:16
[error] object A in object U does not take parameters
[error]   def a(): A = A()
[error]                ^
[error] ./a/U.scala:27:16
[error] object A in object U does not take parameters
[error]   def a(): A = A()
[error]                ^
[error] ./a/U.scala:43:38
[error] object A in object U does not take parameters
[error]     val schema: Schema[A] = constant(A()).withId(id).addHints(hints)
[error]                                      ^
[error] ./a/U.scala:27:7
[error] Conflicting definitions:
[error] def a(): a.U.A in object U at line 26 and
[error] def a(): a.U.A in object U at line 27
[error] have the same type (): a.U.A after erasure.
[error]
[error] Consider adding a @targetName annotation to one of the conflicting definitions
[error] for disambiguation.
[error]   def a(): A = A()
[error]       ^

Relevant code:

  def a(): A = A()
  def a(): A = A()

  final case class A() extends U {
    def $ordinal: Int = 0
  }

  object A {
...
  }
  final case class A() extends U {
    def $ordinal: Int = 1
  }

  object A {
 ...
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenIssues relating to code generation rather than runtime code

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions