Skip to content

fix: add import references when needed #1281

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

Merged

Conversation

sugmanue
Copy link
Contributor

@sugmanue sugmanue commented May 9, 2025

Issue #1287

#1287

Description of changes

This change imports the symbol references to add them to the resulting Kotlin file. Without this the codegen for protocol tests with the latest Smithy model complains about missing symbols such as

  • decodeBase64
  • fromEpochMilliseconds

Some of the references were added but not imported. Some others needed being added and imported.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sugmanue sugmanue requested a review from a team as a code owner May 9, 2025 18:37
} else {
"$instant.fromEpochSeconds(${node.value}, 0)"
builder.addReferences(RuntimeTypes.Core.Instant)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this needed here? It's already added on top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let me remove it.

return if (node.isFloatingPointNumber) {
val fromEpochMilliseconds = RuntimeTypes.Core.fromEpochMilliseconds
builder.addReferences(RuntimeTypes.Core.fromEpochMilliseconds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Can you avoid adding this reference and just use Instant? How you do for fromEpochSeconds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how, can you please add a suggestion instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this:

  private fun getDefaultValueForTimestamp(builder: Symbol.Builder, node: NumberNode): String {
      builder.addReferences(RuntimeTypes.Core.Instant)
      return if (node.isFloatingPointNumber) {
          val value = node.value as Double
          val ms = round(value * 1e3).toLong()
          "Instant.fromEpochMilliseconds($ms)"

Basically removing builder.addReferences(RuntimeTypes.Core.fromEpochMilliseconds)

@aws-sdk-kotlin-ci aws-sdk-kotlin-ci merged commit bcad3b4 into smithy-lang:main May 22, 2025
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants