Skip to content

Instantly share code, notes, and snippets.

@mfikes

mfikes/aget.md Secret

Last active July 4, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/ba5e999eeef8295ee9d8d53af94ebc18 to your computer and use it in GitHub Desktop.
Save mfikes/ba5e999eeef8295ee9d8d53af94ebc18 to your computer and use it in GitHub Desktop.

This release includes new optional warnings (:invalid-aget and :invalid-aset) that indicate, when known via type inference, that aget or aset is operating on non-arrays or being supplied non-numeric indices.

These warnings can be enabled in order to highlight instances of a common pattern where these APIs are used for object property access—as in (aget #js {:foo 1} "foo").

While this works, it is only an unintended aspect of the current implementation. Usages of aget or aset on objects should be corrected to instead use the facilities in the goog.object namespace, such as goog.object/get or goog.object/set.

Doing this enables the core implementations of aget and aset to evolve while focusing on array access.

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