google / google/closure-compiler
Array type check not performed
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
IIt seems that type chekcing is not catching type mismatch when inserting in a typed array. I have the example run in web service. I thought the compiler should complain that I am trying to insert property into the myArray_ that is not part of the enumeration, but it does not complain. Is think this might be a bug.
``` js
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @formatting pretty_print
// @use_closure_library true
// @warning_level VERBOSE
// ==/ClosureCompiler==
goog.provide('myns.A');
goog.require('goog.array');
/**
* @constructor
*/
myns.A = function() {
/**
* @type {Array.}
* @private
*/
this.myArray_ = [];
};
myns.A.prototype.mymethod=function() {
goog.array.insert(this.myArray_, 17);
};
/**
* @enum {number}
*/
myns.A.Type = {
A: 1,
B: 2
}
var a = new myns.A();
a.mymethod();
```
I had similar problem in real code and the compiler did not catch it (so I have lost half a day trying to figure out what is going on).
Contributor guide
Assessment
This issue has not been assessed yet.