Add a few new unit tests for TypeCheck
These cover some previously untested checks on ASSIGN nodes whose lhs is a GETPROP.
@@ -3990,7 +3990,7 @@ public final class TypeCheckTest extends TypeCheckTestCase {
"/** @enum */ var b = a;");
}
- public void testEnum13() {
+ public void testEnum13a() {
testTypes(
"/** @enum {number} */ var a = {};" +
"/** @enum {string} */ var b = a;",
@@ -3999,6 +3999,18 @@ public final class TypeCheckTest extends TypeCheckTestCase {
"required: string");
}
+ public void testEnum13b() {
+ testTypes(
+ lines(
+ "/** @enum {number} */ var a = {};",
+ "/** @const */ var ns = {};",
+ "/** @enum {string} */ ns.b = a;"),
+ lines(
+ "incompatible enum element types", // preserve newlines
+ "found : number",
+ "required: string"));
+ }
+
public void testEnum14() {
testTypes(
"/** @enum {number} */ var a = {FOO:5};" +
@@ -7269,6 +7281,24 @@ public final class TypeCheckTest extends TypeCheckTestCase {
"SubFoo.prototype.bar = 3;");
}
+ public void testOverriddenPropertyWithUnknown() {
+ // When overriding a declared property with a declared unknown property, we warn for a missing
+ // override but not a type mismatch.
+ testTypes(
+ lines(
+ "/** @constructor */ function Foo() {}",
+ "/** @type {?number} */ Foo.prototype.bar = null;",
+ "",
+ "/**",
+ " * @constructor",
+ " * @extends {Foo}",
+ " */",
+ "function SubFoo() {}",
+ "/** @type {?} */",
+ "SubFoo.prototype.bar = 'not a number';"),
+ "property bar already defined on superclass Foo; use @override to override it");
+ }
+
public void testThis2() {
testTypes("var goog = {};" +
"/** @constructor */goog.A = function(){" +
