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

fix(go): unused imports emitted for type unions #3664

Merged
merged 3 commits into from
Jul 21, 2022

Conversation

RomainMuller
Copy link
Contributor

When imported types are solely referenced by type unions, a go import
is emitted, but is never used (type unions end up represented as opaque
interface{} type). This causes compilation failures.

Added a test case for this scenario in particular, and adjusted go code
generation to not emit dependency imports for type unions.

These imports may be re-introduced soon, as we are working to add
dynamic type checking around type unions in go (at which point those
imports would no longer be unused).

Fixes #3399


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

When imported types are solely referenced by type unions, a go import
is emitted, but is never used (type unions end up represented as opaque
`interface{}` type). This causes compilation failures.

Added a test case for this scenario in particular, and adjusted go code
generation to not emit dependency imports for type unions.

These imports may be re-introduced soon, as we are working to add
dynamic type checking around type unions in go (at which point those
imports would no longer be unused).

Fixes #3399
@RomainMuller RomainMuller requested a review from a team July 19, 2022 09:24
@RomainMuller RomainMuller self-assigned this Jul 19, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 19, 2022
@@ -2,4 +2,5 @@ import { overriddenConfig } from '../../jest.config.mjs';

export default overriddenConfig({
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/test'],
watchPathIgnorePatterns: ['.*\\.tsx?$'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note - this makes jest --watch a lot more pleasant to use, as it'd only re-run tests onces tsc --watch updates the .js files instead of possibly re-running when the .ts file changed (which yields unexpected outcome).

I'm contemplating moving this up to the baseline configuration but need to evaluate impact first.

Comment on lines +144 to +146
// for (const t of this.typeMap.value) {
// ret.push(...t.dependencies);
// }
Copy link
Contributor Author

@RomainMuller RomainMuller Jul 19, 2022

Choose a reason for hiding this comment

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

This was left here intentionally as it will likely need to be re-introduced when @MrArnoldPalmer adds runtime type checks for type unions (#3641).

Comment on lines +34 to +36
).resolves.not.toContain(
'github.com/aws/jsii/packages/jsii-pacmak/test/targets/fixtures/base',
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Contemplated putting a .toMatchInlineSnapshot instead here, as it'd show the file has the expected content, but this is more compact and expresses the intent best... I'm slightly worried about false negative tests here, though... but decided this is okay.

@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2022

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Jul 20, 2022
@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2022

Merging (with squash)...

@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2022

Merging (with squash)...

@RomainMuller RomainMuller merged commit 68a80d9 into main Jul 21, 2022
@RomainMuller RomainMuller deleted the rmuller/go-unused-imports branch July 21, 2022 07:54
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when types are imported but seemingly unused in Go
2 participants