flow icon indicating copy to clipboard operation
flow copied to clipboard

Flow Does Not Recognize Infallible Null Guard

Open aksuska opened this issue 8 years ago • 4 comments

Given:

https://flow.org/try/#0MYGwhgzhAECyCeB5ARgKwKbAC7QN4ChoBIABwCcB7E9MreARgC5oUNsAfAOwFcQQBufESEBbdFgAWFACb0AFAEtpAD2Y8RyGgEo8haPugKAZtDmSFEAHTkqNOvWgBeZ9B58teg-rLjuZToJehiZmEhbWlNS0DJbAFNycOAB8hioeQdBxnBAUIOiWIBQA5nIARAAKkcylANTmVjZR9lqBBgC++B1AA

Flow should know that the property could not possibly be null, unless it is expecting side effects from the getter, but there is no reason to expect that.

aksuska avatar Mar 18 '18 23:03 aksuska

@aksuska Actually flow understands your null guard. The error said you are trying to concatenate string with object.

TrySound avatar Mar 19 '18 05:03 TrySound

This probably can be closed. /cc @vkurchatkin

TrySound avatar Mar 19 '18 05:03 TrySound

Sorry, I missed that it was the wrong error message. This is shows the issue: https://flow.org/try/#0MYGwhgzhAECyCmAXAFgewCYGUCWBzAdmIgK4BO80A3gFDS3T7EC2ARvKQPIBmAgqbs3j5EEABQBKKvWjRyJUvmgAmANz0AvtU3VQkGLACeHFgCt4wRFOgBIAPpMkaLHkLz4ALjiOMOAkTLwAD6MICBq1tTWDigYAIyi2OgAHp6MrOySNNYA9NnQENggQoggBtAuqOTlXNAA7hRgVfioltj42IjYYCDYAF7w6NAADqSoQ+ylkdbYNaIo2BAAdPbezn5u0AC82wzEoeJT1nJk+OER1tOziUnQAHyb0PNLKzFrrgGLaWycvPyCwmJxJlDihRrVoAByNroeA3CEAamu8Ih0FQxEsqBqLDR+HQMAA2gBaWIAGkh8LmyAWy2iTl873In2Y324fAEDgBEmghOgsXEyIAuhCzpoZDJNNogA

aksuska avatar Mar 19 '18 14:03 aksuska

@aksuska This is because of javascript dynamism. Flow does not trust checks of instance fields and variables from parent scopes after more than one statement. First statement may change values, so you should store checked references in const. Also a lot of problem may be fixed with $ReadOnlyArray and $ReadOnly utility types similar to const.

https://flow.org/try/#0MYGwhgzhAECyCmAXAFgewCYGUCWBzAdmIgK4BO80A3gFDS3T7EC2ARvKQPIBmAgqbs3j5EEABQBKKvWjRyJUvmgAmANz0AvtU3VQkGLACeHFgCt4wRFOgBIAPpMkaLHkLz4ALjiOMOAkTLwAD6MICBq1tTWDigYAIyi2OgAHp6MrOySNNYyAPQ50BDYIEKIIAbQLqjkFVzQAO4UYNX4qJbY+NiI2GAg2ABe8OjQAA6kqMPsZdIy0MCo+BCW0U6+rgHQALzQKNgQAHT23s5+btMy2LWiyz4u-tUbDwzEoeJnM3JkiiFh1G8X0AlktAAHxba7HNbkPZpNicXj8QTCMTiTJvGQoMZ1aAAcna6HgSRxAGpEkkidjoKhiJZULUWFT8OgYABtAC0sQANMSrkdVnd4NDmLDuHwBA4kRJoKzoLFxOSALrYtQzGaaFWabRAA

TrySound avatar Mar 19 '18 14:03 TrySound