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(cdk): don't use instanceof in App #1249

Merged
merged 3 commits into from
Nov 30, 2018
Merged

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Nov 27, 2018

Make the Stack instance test no longer use instanceof, which doesn't
work properly in case of multiple installed copies of the library.

This does not resolve but helps with #1245.


Pull Request Checklist

Please check all boxes (including N/A items)

Testing

  • Unit test and/or integration test added
  • Toolkit change?: integration
    tests

    manually executed (paste output to the PR description)
  • Init template change?: coordinated update of integration tests
    (currently maintained in a private repo).

Documentation

  • README: README and/or documentation topic updated
  • jsdocs: All public APIs documented

Title and description

  • Change type: Title is prefixed with change type:
    • fix(module): <title> bug fix (patch)
    • feat(module): <title> feature/capability (minor)
    • chore(module): <title> won't appear in changelog
    • build(module): <title> won't appear in changelog
  • Title format: Title uses lower case and doesn't end with a period
  • Breaking change?: Last paragraph of description is: BREAKING CHANGE: <describe exactly what changed and how to achieve similar behavior + link to documentation/gist/issue if more details are required>
  • References: Indicate issues fixed via: Fixes #xxx or Closes #xxx

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

Make the Stack instance test no longer use instanceof, which doesn't
work properly in case of multiple installed copies of the library.

This does not resolve but helps with #1245.
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 27, 2018

Not a fix but addresses the immediate symptoms

@@ -438,7 +438,7 @@ export abstract class Referenceable extends StackElement {
*
* We do attribute detection since we can't reliably use 'instanceof'.
*/
function isStack(construct: Construct): construct is Stack {
export function isStack(construct: Construct): construct is Stack {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it a static method? Stack.isStack (like Array.isArray)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to do that, but I was worried it will conflict with stack.isStack = true.

I didn't test, though, so I could.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worries unfounded, it does work.

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 27, 2018

Wouldn'tya know it, it's our friend C# again:

@aws-cdk/cdk: Stack.cs(95,28): error CS0102: The type 'Stack' already contains a definition for 'IsStack' [/tmp/jsii-pacmak-code27cpp8/Amazon.CDK/Amazon.CDK.csproj] 

@eladb
Copy link
Contributor

eladb commented Nov 28, 2018

Wouldn'tya know it, it's our friend C# again:

Maybe deprecate the public isStack and make it private (_isStack)? The idiomatic way to check a type should be Stack.isStack(x) and not (x as Stack).isStack, no?

@rix0rrr rix0rrr merged commit a45c3bd into master Nov 30, 2018
@rix0rrr rix0rrr deleted the huijbers/app-no-instanceof branch November 30, 2018 15:54
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
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.

3 participants