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

Flag non-any/number/string operands on either side of comparison as errors #27926

Closed
wants to merge 1 commit into from

Conversation

feloy
Copy link

@feloy feloy commented Oct 16, 2018

Fixes #15506

@msftclas
Copy link

msftclas commented Oct 16, 2018

CLA assistant check
All CLA requirements met.

(t === TypeFlags.Any) ||
(t === TypeFlags.TypeParameter) ||
(t === TypeFlags.Enum) ||
(t === TypeFlags.Object) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

This differs from the PR description and the proposed change in the linked issue. It allows basically any structured type. That means all objects are allowed. That's awesome if you need to compare Date objects but may not be desired in all other cases.

Copy link
Author

@feloy feloy Oct 16, 2018

Choose a reason for hiding this comment

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

I have added some more types than the ones done in the proposed change:

  • Object,
  • Intersection,
  • TypeFlags.EnumLiteral | TypeFlags.Union | TypeFlags.UnionOfPrimitiveType
  • TypeFlags.Union | TypeFlags.UnionOfPrimitiveTypes

for TypeScript to continue compiling.

Without the Object type selection, the compilation of TypeScript will fail because Dates are compared somewhere in the code.

@RyanCavanaugh
Copy link
Member

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 16, 2018

Heya @RyanCavanaugh, I've started to run the extended test suite on this PR at a9939ab. You can monitor the build here. It should now contribute to this PR's status checks.

@feloy
Copy link
Author

feloy commented Oct 18, 2018

I see that the extended tests fail, but I'm not able to reproduce the failure locally, and cannot find specific messages of the errors.
Any advice?

@weswigham
Copy link
Member

It's marked as failing, but the contents of the (small) change look benign - likely just a small diff between what commits from master made it into the last master build's baselines and the build triggered here. I don't think this actually affects RWC at all.

@stefanobaghino
Copy link

Thanks for working on this, it would be great to understand what went wrong with the tests.

@weswigham
Copy link
Member

weswigham commented Nov 9, 2018

Well, at this point it needs to be synced with master and reconciled with bigint (which needs to be allowed in arithmetic operators, but already has restrictions on the types it can operate with). RWC can be run again after that, but I don't think it should have any changes.

@feloy
Copy link
Author

feloy commented Nov 9, 2018

Ok, I'll work on this asap

@weswigham
Copy link
Member

@feloy will you been able to sync this?

@feloy
Copy link
Author

feloy commented Jan 28, 2019

Hi @weswigham I will try to work on this this week. If without news before next monday, you can consider I've dropped

@feloy feloy force-pushed the feloy-15506 branch 3 times, most recently from 2b43e5b to 3559a93 Compare January 30, 2019 19:54
@feloy
Copy link
Author

feloy commented Jan 30, 2019

Hi @weswigham I hope I've made all the necessary changes

@@ -22760,6 +22762,19 @@ namespace ts {
return Debug.fail();
}

function checkTypeComparableWithLessOrGreaterThanOperator(valueType: Type): boolean {
const t = valueType.flags;
return (t === TypeFlags.String) ||
Copy link
Member

@weswigham weswigham Jan 30, 2019

Choose a reason for hiding this comment

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

I'm pretty sure all these comparisons should be using & and not ===. I'm also curious why NumberLiteral (and BigIntLiteral) is missing - I'd assume comparing 0 and 2 (and 0n and 2n) is probably OK.

Copy link
Member

Choose a reason for hiding this comment

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

I'd definitely like to see some tests comparing numeric literal types of all sorts among one another and with their bases (number, bigint).

Copy link
Author

Choose a reason for hiding this comment

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

I have lots of troubles adapting the tests. I prefer to give up on this PR :(

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.

7 participants