google / google/closure-compiler
Overriding implicit visibility
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
In Closure, a child class cannot override visibility of a property with different visibility.
But if the parent visibility is not declared in the jsdoc explicitly (that is treated as @public implicitly if no @fileoverview), the child can change the visibility now.
Is this intentional or bug?
For example:
```js
/**
* @constructor
*/
app.Foo = function() {};
/**
* @return {string}
* @public
*/
app.Foo.prototype.explicitPublic = function() {
return 'explicitPublic!';
};
/**
* @return {string}
*/
app.Foo.prototype.implicitPublic = function() {
return 'implicitPublic!';
};
/**
* @constructor
* @extends {app.Foo}
*/
app.Bar = function() {};
/**
* Correct: `WARNING - Overriding PUBLIC property of app.Foo.prototype with PRIVATE property.`
*
* @override
* @private
*/
app.Bar.prototype.explicitPublic = function() {
return 'explicitPublic!';
};
/**
* No warnings! Intentional?
*
* @override
* @private
*/
app.Bar.prototype.implicitPublic = function() {
return 'implicitPublic!';
};
```
Repro:
- [playground](https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F**%250A%2520*%2520%2540constructor%250A%2520*%252F%250Aapp.Foo%2520%253D%2520function()%2520%257B%257D%253B%250A%250A%252F**%250A%2520*%2520%2540return%2520%257Bstring%257D%250A%2520*%2520%2540public%250A%2520*%252F%250Aapp.Foo.prototype.explicitPublic%2520%253D%2520function()%2520%257B%250A%2520%2520return%2520'explicitPublic!'%253B%250A%257D%253B%250A%250A%252F**%250A%2520*%2520%2540return%2520%257Bstring%257D%250A%2520*%252F%250Aapp.Foo.prototype.implicitPublic%2520%253D%2520function()%2520%257B%250A%2520%2520return%2520'implicitPublic!'%253B%250A%257D%253B%250A%250A%252F**%250A%2520*%2520%2540constructor%250A%2520*%2520%2540extends%2520%257Bapp.Foo%257D%250A%2520*%252F%250Aapp.Bar%2520%253D%2520function()%2520%257B%257D%253B%250A%250A%252F**%250A%2520*%2520%2560WARNING%2520-%2520Overriding%2520PUBLIC%2520property%2520of%2520app.Foo.prototype%2520with%2520PRIVATE%2520property.%2560%250A%2520*%250A%2520*%2520%2540override%250A%2520*%2520%2540private%250A%2520*%252F%250Aapp.Bar.prototype.explicitPublic%2520%253D%2520function()%2520%257B%250A%2520%2520return%2520'explicitPublic!'%253B%250A%257D%253B%250A%250A%252F**%250A%2520*%2520No%2520warnings%250A%2520*%250A%2520*%2520%2540override%250A%2520*%2520%2540private%250A%2520*%252F%250Aapp.Bar.prototype.implicitPublic%2520%253D%2520function()%2520%257B%250A%2520%2520return%2520'implicitPublic!'%253B%250A%257D%253B)
- https://github.com/teppeis-sandbox/closure-compiler-sandbox/tree/override-visibility
Also I found such cases in Closure Library, but it does not appear to be intentional.
Contributor guide
Assessment
This issue has not been assessed yet.