blickly / closure-compiler-issues

0 stars 0 forks source link

incorrect 'undefined has no properties' error caused by reverse abstract interpretation #109

Closed blickly closed 9 years ago

blickly commented 9 years ago
What steps will reproduce the problem?

With externs:
function alert(a) {}
/** @return {String} */
function String() {}
String.prototype.toString = function() {};
var undefined;

and code:
/** @constructor */ function Foo() {}

/** @type {String|undefined} */
Foo.prototype.someProp;

Foo.prototype.foo = function() {
  this.someProp = undefined;
  this.reassign();
  alert(this.someProp.toString());
};
Foo.prototype.reassign = function() {
   this.someProp = new String('ha a string object!');
};

What is the expected output? What do you see instead?

I expect to see no error. However, the assignment to undefined makes the 
type system think that the someProp field is undefined, despite the fact 
that it in fact gets reset in the other function.

The error I get is:
input:9: WARNING - undefined has no properties
found : undefined
required: Object
alert(this.someProp.toString()); 
^

What version of the product are you using? On what operating system?
This is using a build from Feb 1.

Original issue reported on code.google.com by amoeding on 2010-02-15 20:11:26

blickly commented 9 years ago
Sadly, this is a fundamental flaw in how we designed type inference. We really need
to 
do something so that the method call cancels the type inference on the qualified name.

I'll think about this a bit more. I've toyed with a few ideas, but have no good ones

yet.

Original issue reported on code.google.com by Nicholas.J.Santos on 2010-02-16 15:24:28

blickly commented 9 years ago
Is this something that will change in the new type inference?

Original issue reported on code.google.com by concavelenz on 2014-03-13 20:30:24

blickly commented 9 years ago
We want to include some of the side effects of a function in its summary, so we can
catch things like this, but we haven't implemented it yet. (Assigning to me is fine
though. I'll update it when we have more progress.)

Original issue reported on code.google.com by dimvar@google.com on 2014-03-13 20:39:03

blickly commented 9 years ago
Issue tracking has been migrated to github. Please make any further comments on this
issue through https://github.com/google/closure-compiler/issues

Original issue reported on code.google.com by blickly@google.com on 2014-05-01 18:31:49

blickly commented 9 years ago
(No text was entered with this change)

Original issue reported on code.google.com by blickly@google.com on 2014-05-01 18:34:11