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

Spreading object breaks optional enum #4682

Closed
leoselig opened this issue Aug 22, 2017 · 6 comments
Closed

Spreading object breaks optional enum #4682

leoselig opened this issue Aug 22, 2017 · 6 comments

Comments

@leoselig
Copy link

leoselig commented Aug 22, 2017

The following very simple snippet shows an error which, I am very certain, is wrong.
When fiddling with it a bit, it seems to be related to 2 conditions:

  • the type of field allowing null, hence being an optional
  • the state (that should have a valid field) being spread into the return value

https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AZRQIYpYAqmOAvKAN6KiiQCWW0AJgFygDkAogHIBVALIB9AGoBBADICeXUAB9QAOwCu0aIgC+AbmRYAHhlgAnFKFZZIBdecirlAYxSNYyhrFgAKOqADOhMSc+ESk5IgAlDS+JlgoqibutPT0TCwcKurQADS+9AB0hQGhoCCgsQC2sABuOCgAFox+oATKrP5YOMqwoFgmJqZ+vrraiEA

I ran into this when writing a new redux reducer (though I did not understand yet why this never happened before).

Tested on Flow Try on master, 0.53.1, 0.53.0, 0.52.0, 0.51.1, 0.51.0

@leoselig leoselig changed the title Spreading object break optional enum Spreading object breaks optional enum Aug 22, 2017
@asolove
Copy link
Contributor

asolove commented Aug 22, 2017

I tend to agree I would expect this to work. If you need a workaround right away, this small change is ugly but makes everything work as expected.

I'm also curious why you would set a value for a field in the same object where you then spread in an object that will definitely override the value for that field. I'm sure there is some larger context to the real code, so if you share that maybe we can find a solution.

@leoselig
Copy link
Author

leoselig commented Aug 22, 2017

@asolove
Your curiosity...

why you would set a value for a field in the same object where you then spread in an object that will definitely override the value for that field

actually answered mine...

though I did not understand yet why this never happened before

I indeed did not mean to spread this way and fixing the order fixes the issue for me

Anyway, I strongly believe there is a defect and this is ONE bug it might trigger

@asolove
Copy link
Contributor

asolove commented Aug 22, 2017

Yeah, could be: if you find another case let us know!

@leoselig
Copy link
Author

@asolove Long time no... read
So I hit another use case – this time my workaround does not make sense for me

See this example: https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AWSwM4ECGA5lgCqY4C8oA3oqKALaEnkBcoBKATgEsAdqQA0THgGNY2bgH5egkYgC+AbmRYAHhlh8UoSAFchklANhDQkvlmIos+ImSwAxYgOgEAFPVAA6QNgANyw+QQATHBVuABIAZQALYmwAHicOSmoAPgBKbgyXKmwGCVsUIz4rRmZmNmcuUAAiSGIAaxx6zKbxWqkZLG4hI2hoXtrA-xCwyKwJdVVNHT0DY1NzS2tbe0d2FwB1PTafP0np8IEo0BjQBOS0wvJirDyCvafqUuZyyuqJOveg2arQ6rEBPX+-VkoGGo3mGhUiCAA

As you can see, as opposed to my initial example, I now really want to spread last, not first, since I am overriding the values

@villesau
Copy link
Contributor

I think this fixes the issue: #7298

@nmote
Copy link
Contributor

nmote commented Oct 25, 2019

This no longer errors in master

@nmote nmote closed this as completed Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants