google / google/closure-compiler

Consider adding @checkReturnValue

Open
#1,749 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Some context: https://github.com/google/closure-compiler/issues/1745 reported that `Object.create()` was not dead code eliminated. My proposed fix in https://github.com/google/closure-compiler/pull/1746 was pointed out by @SLaks to be unsafe because of cases like:

``` js
document.getElementById('foo').innerHTML = 'blah';
```

`document.getElementById` is also marked with `@nosideeffects`, but since it returns a shared mutable object, the assignment cannot be removed.

Another example: https://github.com/google/closure-compiler/pull/1281 removed `@nosideeffects` from `JSON.parse` and `JSON.stringify` because they had both `@throws` and `@nosideeffects`, which is contradictory. After removing `@nosideeffects`, some calls to them will not be removed.

These examples suggest that the definition of `@nosideeffects` is not clear enough. Currently, most of its use cases can be replaced by a `@checkReturnValue` annotation which can adopt similar semantics as the one in [Error Prone](http://errorprone.info/bugpattern/CheckReturnValue). We will need something like a `@returnValueNotShared` annotation for https://github.com/google/closure-compiler/issues/1746. We can also add a `@pure` annotation which can be recognized by `PureFunctionIdentifier`.

IMO we should also allow these new annotations in both externs and code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.