google / google/closure-compiler

HIDDEN_INTERFACE_PROPERTY_MISMATCH error message points to wrong line

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

Description

See [this example](https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540interface%2520*%252F%250Aclass%2520BaseInterface%2520%257B%250A%2520%2520%252F**%2520%2540return%2520%257B!BaseInterface%257D%2520*%252F%2520foo()%2520%257B%257D%250A%257D%250A%250A%252F**%2520%2540interface%2520%2540extends%2520%257BBaseInterface%257D%2520*%252F%250Aclass%2520SubInterface%2520%257B%250A%2520%2520%252F**%2520%2540override%2520%2540return%2520%257B!SubInterface%257D%2520*%252F%2520foo()%2520%257B%257D%250A%257D%250A%250A%252F**%2520%2540implements%2520%257BBaseInterface%257D%2520*%252F%250Aclass%2520Abstract%2520%257B%250A%2520%2520%252F**%2520%2540override%2520*%252F%2520foo()%2520%257B%2520return%2520new%2520Abstract()%253B%2520%257D%250A%257D%250A%250A%252F**%2520%2540extends%2520%257BAbstract%257D%250A%2520%2520%2520%2520%2540implements%2520%257BSubInterface%257D%2520*%252F%250Aclass%2520SubAbstract%2520extends%2520Abstract%2520%257B%250A%2520%2520%252F**%2520%2540override%250A%2520%2520%2520%2520%2520%2520%2540this%2520%257B!Abstract%257D%250A%2520%2520%2520%2520%2520%2520%2540return%2520%257B!SubInterface%257D%2520*%252F%250A%2520%2520foo()%2520%257B%2520return%2520new%2520SubAbstract()%253B%2520%257D%250A%257D%250A%250A%252F**%2520%2540extends%2520%257BAbstract%257D%2520*%252F%250Aclass%2520Other%2520extends%2520Abstract%2520%257B%257D%250A%250A%252F**%2520%2540extends%2520%257BOther%257D%250A%2520%2520%2520%2520%2540implements%2520%257BSubInterface%257D%2520*%252F%250Aclass%2520SubOther%2520extends%2520Other%2520%257B%257D%250A%250A%252F**%2520%2540override%2520*%252F%250ASubOther.prototype.foo%2520%253D%2520SubAbstract.prototype.foo%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26MISSING_PROPERTIES%3D1%26TRANSPILE%3D1%26CHECK_TYPES%3D1%26CLOSURE_PASS%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1).

This is a somewhat complicated scenario - I'm not convinced that all of this is required, but the basic idea is that the final direct prototype assignment needs to specialize the `@return` since `Other`'s `foo` doesn't satisfy `SubInterface`.

```js
/** @interface */
class BaseInterface {
/** @return {!BaseInterface} */ foo() {}
}

/** @interface @extends {BaseInterface} */
class SubInterface {
/** @override @return {!SubInterface} */ foo() {}
}

/** @implements {BaseInterface} */
class Abstract {
/** @override */ foo() { return new Abstract(); }
}

/** @extends {Abstract}
@implements {SubInterface} */
class SubAbstract extends Abstract {
/** @override
@this {!Abstract}
@return {!SubInterface} */
foo() { return new SubAbstract(); }
}

/** @extends {Abstract} */
class Other extends Abstract {}

/** @extends {Other}
@implements {SubInterface} */
class SubOther extends Other {}

/** @override */ // NOTE: error is fixed if we add @return {!SubInterface}
SubOther.prototype.foo = SubAbstract.prototype.foo;
```

OTI error:
```
input0:13: WARNING - mismatch of the foo property type and the type of the property it overrides from interface BaseInterface
original: function (this:SubInterface): SubInterface
override: function (this:Abstract): BaseInterface
/** @override */ foo() { return new Abstract(); }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

NTI error - note that it gets the line correct:
```
input0:33: WARNING - Invalid redeclaration of property foo.
inherited type : function(this:SubInterface):SubInterface
overriding type : function(this:Abstract):BaseInterface

SubOther.prototype.foo = SubAbstract.prototype.foo;
^^^^^^^^^^^^^^^^^^^^^^
```

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.