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

Number literal object keys typechecking #7593

Closed
wants to merge 10 commits into from

Conversation

goodmind
Copy link
Contributor

@goodmind goodmind commented Mar 26, 2019

Fixes #380

Doesn't allow in interfaces
Doesn't allow in class declarations

@goodmind
Copy link
Contributor Author

@goodmind goodmind changed the title Number literal keys Number literal object keys Mar 26, 2019
@nmote
Copy link
Contributor

nmote commented Mar 27, 2019

Not sure who should review this. @dsainati1, @jbrown215, or @mvitousek, any of you have some time to spare for this?

@dsainati1
Copy link
Contributor

Given that @mroch had raised concerns on #380 I'd like to get his opinion on this, but at the very least I think we'd want to see more tests here. It would be good to test number keys with different variance, as well as cases where objects are declared with number/string keys that are in conflict. I.e., what should happen here?

let a = {1 : "A", "1" : 3};
(a[1] : number)

@goodmind
Copy link
Contributor Author

@dsainati1 it does the same as {'1': 'A', '1': 3} i.e. uses latter definition, added tests

@goodmind
Copy link
Contributor Author

Parser test for contravariant number keys fails, probably it parses it as negative number

@goodmind
Copy link
Contributor Author

goodmind commented Mar 28, 2019

Fixed contravariant properties parsing.

@goodmind
Copy link
Contributor Author

image
This probably should display numbers too

@goodmind
Copy link
Contributor Author

goodmind commented Mar 28, 2019

@dsainati1 do you think tuples should be affected by this?

//@flow

declare var e: { 0: number, 1: number, length: 2 };
declare var b: [number, number];

(e[0]: number);
(e[1]: number);

(b[0]: number);
(b[1]: number);

const m: { 0: number, 1: number, length: 2 } = b; // error currently
const m2: [number, number] = e; // error currently

Related PR: #5048

| DefT (reason_x, _, NumT (Literal (_, (x, _)))) ->
let x = Dtoa.ecma_string_of_float x in
let reason_prop = replace_reason_const (RProperty (Some x)) reason_x in
(* Probably should be different type constructor *)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this broke {[key: number]: any} reads,

declare var e: { [key: number]: any };

e[0]; // string `0` [1] is incompatible with  number [2].Flow(InferError)

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 think this #2293 (comment) applies to this also, so probably I fixed it wrong

@goodmind
Copy link
Contributor Author

goodmind commented Apr 6, 2019

This PR probably shouldn't mix number keys with string keys

@goodmind
Copy link
Contributor Author

goodmind commented May 8, 2019

@mroch can you look at this?

@goodmind
Copy link
Contributor Author

goodmind commented Jun 7, 2019

😃I forgot about this PR completely. I think to split parsing from typechecking in two PRs
@mroch do you have anything to say about number keys?

@goodmind goodmind force-pushed the number-literal-keys branch 2 times, most recently from 89a15ca to 9b70048 Compare June 7, 2019 06:01
@goodmind
Copy link
Contributor Author

goodmind commented Jun 7, 2019

Moved parsing here #7798

@goodmind goodmind changed the title Number literal object keys Number literal object keys typechecking Jun 7, 2019
@goodmind goodmind force-pushed the number-literal-keys branch from 9b70048 to 5b9960c Compare July 19, 2019 02:59
@goodmind goodmind force-pushed the number-literal-keys branch from 5b9960c to 575d803 Compare July 19, 2019 03:02
@nnmrts
Copy link
Contributor

nnmrts commented Sep 3, 2019

@goodmind Wow, thanks for your work on this! Do you have any updates for us?

EDIT: Oh. I guess we have to wait for @mroch to say something about this.

@goodmind
Copy link
Contributor Author

goodmind commented Sep 3, 2019

@nnmrts I don't think this would get in as-is, I hope at least parsing would get reviewed

@nnmrts
Copy link
Contributor

nnmrts commented Oct 11, 2019

@goodmind So it seems you're just getting ignored here. Nice! 👍👍👍

@goodmind
Copy link
Contributor Author

goodmind commented Oct 12, 2019

@nnmrts not really, I have tons of PR merged already
https://github.com/facebook/flow/pulls?q=is%3Apr+author%3Agoodmind+label%3AMerged+is%3Aclosed

@nnmrts
Copy link
Contributor

nnmrts commented Dec 1, 2019

Any update on this? 😆

@nnmrts
Copy link
Contributor

nnmrts commented Dec 12, 2019

Really? It's almost 9 months now!? This is ridiculous. Maintainers, then open up flowlib (and js types) for developers at least, if you don't want to fix major bugs like this one.

Flow is officially an unusable typechecker for 2014 javascript now. Numerical keys are standard since JUNE 2015!???

How is this even a typechecker when half of the types aren't following any standard?

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 80ca16f.

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

Successfully merging this pull request may close these issues.

"non-string literal property keys not supported"
5 participants