google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.41k stars 1.15k forks source link

Unknown type MapEntry in ES6 polyfills #1942

Open supersteves opened 8 years ago

supersteves commented 8 years ago

After compiling our very large codebase, we see these warnings:

 [synthetic:es6/map] :81: WARNING - Bad type annotation. Unknown type MapEntry

 [synthetic:es6/map] :85: WARNING - Bad type annotation. Unknown type MapEntry

 [synthetic:es6/map] :116: WARNING - Bad type annotation. Unknown type MapEntry

We'll have to code in some exceptions, since we fail the build on warning. Presumably this is a bug, rather than something we're doing? Can't see how to put together a test case in the debugger here; this doesn't work.

dimvar commented 8 years ago

Can you provide steps to repro from the command line? Some small input program and what compiler options you're using.

supersteves commented 8 years ago

It'll be difficult, any ideas that might help me narrow it down?

dimvar commented 8 years ago

Not sure, which is why I was hoping for a small repro :) The teammate who implemented this is on leave, so it'll take a bit of effort to dig into this and figure out what's going on.

supersteves commented 8 years ago

I've already added an exception to our build, so there's no rush (speaking for myself). But I'll see if I can narrow it down.

supersteves commented 8 years ago

I've narrowed it down somewhat. But can't find a testcase.

These 3 errors occur when I compile the largest monolithic part of our codebase. This includes a common script which registers a couple of old polyfills.

The same script is included by other builds which DON'T produce these warnings. So I have been unable to narrow it down in that way.

However I have whittled down the included common script to the bare minimum such that the 3 warnings still occur (when compiling the large monolithic code):

goog.provide("X");
(function (view) {
  var objCtr = Object;
})(self);
supersteves commented 8 years ago

My guess is some interplay between some other unknown part of my code and the above pattern is causing the issue. I can easily inspect in the Eclipse debugger when the warning is raised, if you can guide me to what you might need.

MatrixFrog commented 8 years ago

MapEntry is defined at https://github.com/google/closure-compiler/blob/f3aa05d1cba9da45467505183d1270ea90b1a67b/src/com/google/javascript/jscomp/js/es6/map.js#L75 and is not referenced in any other file. So I can't see why this would happen. If you're mixing the compiler's polyfills with polyfills from elsewhere that could cause some weirdness.

supersteves commented 8 years ago

My Polyfill is a red herring; it's just the first provide, and I've commented out everything other than the 4 lines quoted above.

Somewhere in my ~5000 files is causing this. When the error is raised the NamedType ("MapEntry") arises from InstanceObjectType.properties, which contains just these entries: {data_=Property { name: data_, type:Object<?,Array<MapEntry>>, inferred: false}, head_=Property { name: head_, type:MapEntry, inferred: false}, size=Property { name: size, type:number, inferred: false}}

These come from: https://github.com/google/closure-compiler/blob/f3aa05d1cba9da45467505183d1270ea90b1a67b/src/com/google/javascript/jscomp/js/es6/map.js#L109

The global scope's vars LinkedHashMap at the error raise has Map present (from externs?) but not MapEntry and not PolyfillMap.

I'm only checking types and have all optimisations disabled. But the same occurs with SIMPLE_OPTIMIZATIONS.

Any pointers to further debug?

rubenlg commented 8 years ago

I have the same problem, it is actually quite easy to reproduce. As the error itself suggests, you just need to use ES6 maps:

let x = new Map();

And then compile with: --warning_level VERBOSE --jscomp_warning=reportUnknownTypes

For others landing on this page,here is a workaround that shuts up the compiler for errors generated by its own polyfills:

--hide_warnings_for=synthetic

MatrixFrog commented 8 years ago

It's worth noting that reportUnknownTypes is not well-supported.