Flow: Potentially unsafe get/set usage warning

Created on 16 Nov 2016  路  18Comments  路  Source: facebook/flow

I've got this strange warning:

[flow] [flow] Potentially unsafe get/set usage (Getters and setters with side effects are potentially >unsafe and disabled by default. You may opt-in to using them anyway by putting >unsafe.enable_getters_and_setters=true into the [options] section of your .flowconfig.)

Can you clarify what kind of side-effects my plain setter/getter cause?

// @flow
class Git {

  constructor(path: string) {
    this.gitBinary = 'git';
    this._path = path;
  }

  get path(): string {
    return this._path;
  }

  set path(path: string) {
    throw new Error('Path is readonly.');
  }

  get gitBinary(): string {
    return this._gitBinary;
  }

  set gitBinary(value: string) {
    this._gitBinary = value;
  }

}

Most helpful comment

So Flow considers all setters/getters as an error regardless of their implementation? That's pretty frustrating.

All 18 comments

Well, your example is entirely invalid, because you try to set this.path, but don't have a setter, and in getter you cause infinite recursion.

@vkurchatkin yeah right. So I back my properties with some private variable, still get the same warning.

It does not really matter how I define properties, even simple getter that returns constant still emits warning.

class Git {

  static get master() {
    return 'master';
  }

}

I'm not 100% sure, but I think Flow always warns about this, because getter or setter with side effects can potentially invalidate type refinements, but Flow doesn't actually check if your getter/setter has side effects

So Flow considers all setters/getters as an error regardless of their implementation? That's pretty frustrating.

If you prefer to use them without the warnings, you can opt to enable the feature using the configuration option listed in the warning message: unsafe.enable_getters_and_setters=true

It would be nice to disable the warning on a per getter/setter basis. That way, a human could evaluate whether or not a particular getter/setter had side-effects as opposed to blanket acceptance.

This seems like a pretty clear bug in Flow... Any plans on getting getters/setters working in Flow without having to pass in unsafe flags? It seems that is a bad idea since flow could actually catch issues rather than just completely ignoring getters/setters...

@jdalegonzalez I think you can use // $FlowFixMe right above the getter to suppress the error

Unfortunately // $FlowFixMe disables all checks vs. enabling only unsafe.enable_getters_and_setters for that line as an interim workaround until Flow can understand side effects.

Is there any movement on this? From my perspective, this is a pretty big bug in that Flow essentially doesn't work for setters and getters.

Waw! Looks like it fixed in the latest version of flow, see working example

@agrcrobles seem to not complain n any selected version in this example

@agrcrobles Still having the issue on 0.63.1. Edit: Never mind. I forgot Nuclide uses the globally installed flow binary.

@Adam0000 What's an issue? And show your flowconfig

As mentioned by @fsarron-nexway flow.org/try doesn't complain about this error in any of versions of Flow

Sounds like this no longer happens -- also upgraded flow and don't see the issue anymore. Feel free to close.

Closing since v0.64 seems to address this for me.

Also unsafe.enable_getters_and_setters is now removed from Flow config.

Was this page helpful?
0 / 5 - 0 ratings