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

TypeCheck.INEXISTENT_PROPERTY being reported incorrectly #2165

Open supersteves opened 7 years ago

supersteves commented 7 years ago

Since updating (I was previously using a mid-summer build), I'm getting JSC_INEXISTENT_PROPERTY for subsequent access to properties defined in a class constructor.

It only occurs in NTI when options.setReportOTIErrorsUnderNTI(true). An obscure option, I know, also one I added myself, and admittedly I'm probably the only one using it.

Without NTI, the error does not occur. With NTI and options.setReportOTIErrorsUnderNTI(false) the error does not occur. Only with NTI and options.setReportOTIErrorsUnderNTI(true) does the error occur.

Externs:

/**
 * @constructor
 */
var RC = function() {};

Class:

export default class S extends RC {
    constructor() {
        super();
        this.e = "eee";
    }
    m() {
        console.log(this.e);
    }
}

Warning:

S.js:7: WARNING - Property e never defined on S
   5|     }
   6|     m() {
   7|         console.log(this.e);
   8|     }
   9| }

Is TypeCheck.INEXISTENT_PROPERTY an OTI-specific error? Is TypeCheck itself OTI specific? I didn't think it was. If it is, I just need to filter out the warning. If not, it's possibly a bug.

dimvar commented 7 years ago

Is TypeCheck.INEXISTENT_PROPERTY an OTI-specific error? Is TypeCheck itself OTI specific?

Yes and yes.

The NTI-equivalent warning is here.

supersteves commented 7 years ago

Great. Thanks for clarifying so quickly. I can now disregard all TypeCheck diag groups as OTI when compiling NTI-ready parts of my code.

supersteves commented 7 years ago

I think there's a bug here. When NTI runs, some OTI logic is being disabled, which should not be the case when setReportOTIErrorsUnderNTI(true). I'm getting this OTI error only when NTI is also enabled, when only OTI passes are done, I don't get the error.