google / google/closure-compiler
Failed `@record` declarations aren't reported correctly
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
See [this example](https://closure-compiler-debugger.appspot.com/#input0%3Dsink%28function%28%29%2520%257B%250A%2520%2520%252F**%2520%2540record%2520*%252F%2520var%2520Foo%2520%253D%2520function%28%29%2520%257B%257D%253B%250A%2520%2520%252F**%2520%2540type%2520%257Bstring%257D%2520*%252F%2520Foo.prototype.bar%253B%250A%250A%2520%2520%252F**%2520%2540return%2520%257B!Foo%257D%2520*%252F%250A%2520%2520var%2520handle%2520%253D%2520function%28%29%2520%257B%2520return%2520%252F**%2520%2540type%2520%257B!Foo%257D%2520*%252F%2520%28%257B%257D%29%253B%2520%257D%253B%250A%250A%2520%2520sink%28handle%28%29.bar%29%253B%250A%257D%29%253B%26input1%26conformanceConfig%26externs%3D%252F**%2520%2540record%2520*%252F%2520var%2520Foo%2520%253D%2520function%28%29%2520%257B%257D%253B%250A%252F**%2520%2540type%2520%257Bnumber%257D%2520*%252F%2520Foo.prototype.foo%253B%250A%250Afunction%2520sink%28arg%29%2520%257B%257D%26refasterjs-template%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26MISSING_PROPERTIES%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1) in which we define a `@record` type inside an IIFE that should shadow an extern type `Foo`:
Externs:
``` js
/** @record */ var Foo = function() {};
/** @type {number} */ Foo.prototype.foo;
function sink(arg) {}
```
Main:
``` js
sink(function() {
/** @record */ var Foo = function() {};
/** @type {string} */ Foo.prototype.bar;
/** @return {!Foo} */
var handle = function() { return /** @type {!Foo} */ ({}); };
sink(handle().bar);
});
```
Per #1729, the compiler can't handle shadowing the extern, and if the main code defined a `@constructor` instead of a `@record`, we would get an explicit error message saying so. But for `@record`s, we instead get a very cryptic message:
```
input0:8: WARNING - Property bar never defined on Foo
sink(handle().bar);
^
```
which is complete nonsense because as you can clearly see, I _did_ define `bar`. Hopefully fixing #1729 will take care of this, but there's also another bug somewhere where we're not reporting that a `@record` declaration didn't actually stick.
Contributor guide
Assessment
This issue has not been assessed yet.