Skip to content

Commit

Permalink
Add an additional test cases for transitively implemented interface i…
Browse files Browse the repository at this point in the history
…nstance fields and structural matching of interface instance fields.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=246365158
  • Loading branch information
nreid260 authored and brad4d committed May 3, 2019
1 parent f65e40c commit e593e6d
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 18 deletions.
20 changes: 20 additions & 0 deletions test/com/google/javascript/jscomp/TypeCheckNoTranspileTest.java
Expand Up @@ -3073,6 +3073,26 @@ public void testClassMissingInterfaceInstanceProperty() {
"property bar on interface Foo is not implemented by type MyFoo"); "property bar on interface Foo is not implemented by type MyFoo");
} }


@Test
public void testClassMissingTransitiveInterfaceInstanceProperty() {
testTypes(
lines(
"/** @record */", // `@interface` would also trigger this.
"class Foo {",
" constructor() {",
" /** @type {number} */",
" this.bar;",
" }",
"}",
"",
"/** @record */",
"class SubFoo extends Foo { }",
"",
"/** @implements {SubFoo} */",
"class MyFoo { }"),
"property bar on interface Foo is not implemented by type MyFoo");
}

@Test @Test
public void testClassInvalidOverrideOfInterfaceInstanceProperty() { public void testClassInvalidOverrideOfInterfaceInstanceProperty() {
testTypes( testTypes(
Expand Down
108 changes: 90 additions & 18 deletions test/com/google/javascript/jscomp/TypeCheckTest.java
Expand Up @@ -19827,9 +19827,8 @@ public void testStructuralInterfaceMatching37() {
"mismatch: [fun,prop]")); "mismatch: [fun,prop]"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching39() { public void testStructuralInterfaceMatching_forObjectLiterals_39() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */",
Expand All @@ -19845,9 +19844,8 @@ public void testStructuralInterfaceMatching39() {
"required: (I2|null)")); "required: (I2|null)"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching40() { public void testStructuralInterfaceMatching_forObjectLiterals_prototypeProp_matching() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */",
Expand All @@ -19859,26 +19857,103 @@ public void testStructuralInterfaceMatching40() {
"var o1 = {length : 123};")); "var o1 = {length : 123};"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching40_1() { public void testStructuralInterfaceMatching_forObjectLiterals_instanceProp_matching() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */", //
"function I2() {",
" /** @type {number} */",
" this.length;",
"}"),
lines(
"/** @type {!I2} */", //
"var o1 = {length : 123};"));
}

@Test
public void testStructuralInterfaceMatching_forObjectLiterals_prototypeProp_missing() {
testTypesWithExtraExterns(
lines(
"/** @record */", //
"function I2() {}", "function I2() {}",
"/** @type {number} */", "/** @type {number} */",
"I2.prototype.length;"), "I2.prototype.length;"),
lines( lines(
"/** @type {I2} */", "/** @type {!I2} */", //
"var o1 = {length : 123};")); "var o1 = {};"),
lines(
"initializing variable", //
"found : {}",
"required: I2",
"missing : [length]",
"mismatch: []"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching41() { public void testStructuralInterfaceMatching_forObjectLiterals_instanceProp_missing() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */", //
"function I2() {",
" /** @type {number} */",
" this.length;",
"}"),
lines(
"/** @type {!I2} */", //
"var o1 = {};"),
lines(
"initializing variable", //
"found : {}",
"required: I2",
"missing : [length]",
"mismatch: []"));
}

@Test
public void testStructuralInterfaceMatching_forObjectLiterals_prototypeProp_mismatch() {
testTypesWithExtraExterns(
lines(
"/** @record */", //
"function I2() {}",
"/** @type {number} */",
"I2.prototype.length;"),
lines(
"/** @type {!I2} */", //
"var o1 = {length: null};"),
lines(
"initializing variable", //
"found : {length: null}",
"required: I2",
"missing : []",
"mismatch: [length]"));
}

@Test
public void testStructuralInterfaceMatching_forObjectLiterals_instanceProp_mismatch() {
testTypesWithExtraExterns(
lines(
"/** @record */", //
"function I2() {",
" /** @type {number} */",
" this.length;",
"}"),
lines(
"/** @type {!I2} */", //
"var o1 = {length: null};"),
lines(
"initializing variable", //
"found : {length: null}",
"required: I2",
"missing : []",
"mismatch: [length]"));
}

@Test
public void testStructuralInterfaceMatching_forObjectLiterals_41() {
testTypesWithExtraExterns(
lines(
"/** @record */", //
"function I2() {}", "function I2() {}",
"/** @type {number} */", "/** @type {number} */",
"I2.prototype.length;"), "I2.prototype.length;"),
Expand All @@ -19890,9 +19965,8 @@ public void testStructuralInterfaceMatching41() {
"i = o1;")); "i = o1;"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching41_1() { public void testStructuralInterfaceMatching41_forObjectLiterals_41_1() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */",
Expand All @@ -19907,9 +19981,8 @@ public void testStructuralInterfaceMatching41_1() {
"i = o1;")); "i = o1;"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching42() { public void testStructuralInterfaceMatching_forObjectLiterals_42() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */",
Expand All @@ -19924,9 +19997,8 @@ public void testStructuralInterfaceMatching42() {
"i = o1;")); "i = o1;"));
} }


/** test structural interface matching for object literals */
@Test @Test
public void testStructuralInterfaceMatching43() { public void testStructuralInterfaceMatching_forObjectLiterals_43() {
testTypesWithExtraExterns( testTypesWithExtraExterns(
lines( lines(
"/** @record */", "/** @record */",
Expand Down

0 comments on commit e593e6d

Please sign in to comment.