Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSC_INEXISTENT_PROPERTY_WITH_SUGGESTION is hidden if the inexistent property is set in unrelated code. #4164

Closed
bamtang-dev opened this issue May 10, 2024 · 2 comments
Assignees
Labels
internal-issue-created An internal Google issue has been created to track this GitHub issue triage-done Has been reviewed by someone on triage rotation.

Comments

@bamtang-dev
Copy link

Hello, not sure if this is expected behavior.
Below code is minimal sample tested in ADVANCED mode on: https://closure-compiler.appspot.com/

/**
 * @constructor
 * @struct
 */
function SGlobal() {
	this.className = "SGlobal";
}
/** @type {number}*/
SGlobal.scale = 1;

/**
 * @constructor
 * @struct
 * @param {number} x
 */
function ZoomManager(x) {
	this.m_x = x * SGlobal.scale;
}

/**
 * @param {number} time
 * @param {number} x
 */
ZoomManager.prototype.onDisplace = function(time, x) {
	this.m_x = x + time * SGlobal.scaleT; // <--- THIS IS A TYPO, property was 'scale'
};

ZoomManager.prototype.neverCalled = function() {
	//SGlobal.scaleT = 4;
};

var obj = new ZoomManager(10);
obj.onDisplace(0.5, 1);
var dist = obj.m_x;
console.log(dist);

This code has a typo and the compiler correctly points the error:

JSC_INEXISTENT_PROPERTY_WITH_SUGGESTION: Property scaleT never defined on SGlobal. Did you mean scale? at line 25 character 31

But if you are unlucky like me and have a second typo in other unrelated part of your code the warning goes away and no warning or error is printed. Here I put the second typo in a method of the class that is never called

ZoomManager.prototype.neverCalled = function() {
	SGlobal.scaleT = 4;  // <--- SECOND TYPO, replace this code in above example
};

What is interesting is that the compiler somehow knows that the output is undefined because is producing compiled code with NaN:

'use strict';
var a = new function() {
  this.g = 10;
}();
a.g = NaN;
console.log(a.g);

I was under the impression that the compiler warned me whenever an undeclared property of a @struct was tried to use.

@rishipal
Copy link
Contributor

rishipal commented May 14, 2024

I suspect this is happening because by doing SGlobal.scaleT = 4; inside ZoomManager.prototype.neverCalled you have created a property named scaleT. Hence it's no longer an inexistent property, i.e. the compiler sees that a property with that name exists somewhere in the code. Hence the inexistent property error is not reported by closure compiler and this seems WAI to me.

Furthermore, if you change the neverCalled method to have a "use" of the inexistent property, then the compiler correctly complains at both use-sites of the inexistent property.

ZoomManager.prototype.neverCalled = function() {
	this.m_x = SGlobal.scaleT;
};

See - http://shortn/_J3xapGS5bl

Will discuss this in the internal bug triage meeting and update again.

@rishipal rishipal added triage-done Has been reviewed by someone on triage rotation. internal-issue-created An internal Google issue has been created to track this GitHub issue labels May 14, 2024
@rishipal rishipal self-assigned this May 14, 2024
@rishipal
Copy link
Contributor

Closing as WAI per my comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal-issue-created An internal Google issue has been created to track this GitHub issue triage-done Has been reviewed by someone on triage rotation.
Projects
None yet
Development

No branches or pull requests

2 participants