google / google/closure-compiler

Broken code (with null deref) is being rewritten to unbroken code

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

Description

``` javascript
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// ==/ClosureCompiler==

/** @struct @constructor */
var A = function A() {
this.t = 1;
};

/** @struct @constructor */
var B = function B() {
/** @type {?A} */
this.a = null;
};

/** @return {!number} */
B.prototype.f1 = function() {
return this.a.t; // <== OK, but expected WARNING
};

var b = new B();
alert(b.f1());
```

Compiled code is:

``` javascript
alert((new function(){this.a=null}).a.t);
```

For some reason in statement `return this.a.t` compiler assumes `B.a` to be `{!A}` and doesn't show a "type mismatch" warning.

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.