Add tests for two untested warning kinds in the old type checker, and document
a bug in the checking of inherited properties.
Related to github issue
@@ -14300,6 +14300,48 @@ public final class TypeCheckTest extends CompilerTypeTestCase {
"var k;");
}
+ public void testBadSuperclassInheritance1() throws Exception {
+ testTypes(LINE_JOINER.join(
+ "/** @constructor */",
+ "function Foo() {}",
+ "/** @type {number} */",
+ "Foo.prototype.myprop = 2;",
+ "",
+ "/** @constructor @extends {Foo} */",
+ "function Bar() {}",
+ "/** @type {number} */",
+ "Bar.prototype.myprop = 1;"),
+ TypeCheck.HIDDEN_SUPERCLASS_PROPERTY);
+ }
+
+ public void testBadSuperclassInheritance2() throws Exception {
+ testTypes(LINE_JOINER.join(
+ "/** @constructor */",
+ "function Foo() {}",
+ "/** @type {number} */",
+ "Foo.prototype.myprop = 2;",
+ "",
+ "/** @constructor @extends {Foo} */",
+ "function Bar() {}",
+ "/** @override @type {string} */",
+ "Bar.prototype.myprop = 'qwer';"),
+ TypeCheck.HIDDEN_SUPERCLASS_PROPERTY_MISMATCH);
+ }
+
+ // If the property has no initializer, the HIDDEN_SUPERCLASS_PROPERTY_MISMATCH warning is missed.
+ public void testBadSuperclassInheritance3() throws Exception {
+ testTypes(LINE_JOINER.join(
+ "/** @constructor */",
+ "function Foo() {}",
+ "/** @type {number} */",
+ "Foo.prototype.myprop = 2;",
+ "",
+ "/** @constructor @extends {Foo} */",
+ "function Bar() {}",
+ "/** @override @type {string} */",
+ "Bar.prototype.myprop;"));
+ }
+
public void testCheckObjectKeysWithNamedType() throws Exception {
testTypes(
"/** @type {!Object<!PseudoId, number>} */\n" +
