Skip to content

Commit

Permalink
Create a unit test describing an issue with DisambiguateProperties
Browse files Browse the repository at this point in the history
…and templatized types.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=234669621
  • Loading branch information
nreid260 authored and lauraharker committed Feb 21, 2019
1 parent 48df493 commit cdc0915
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2017,24 +2017,50 @@ public void testStructuralTypingWithDisambiguatePropertyRenaming5() {
"",
"function f(/** Bar */ i) { return i.x; }");

String output = lines(
"/** @record */",
"function I(){}",
"/** @type {number} */",
"I.prototype.Foo_prototype$x;",
"/** @constructor @implements {I} */",
"function Foo(){}",
"/** @type {number} */",
"Foo.prototype.Foo_prototype$x;",
"/** @constructor */",
"function Bar(){}",
"/** @type {number} */",
"Bar.prototype.Bar_prototype$x;",
"function f(/** Bar */ i){return i.Bar_prototype$x}");
String output =
lines(
"/** @record */",
"function I(){}",
"/** @type {number} */",
"I.prototype.Foo_prototype$x;",
"/** @constructor @implements {I} */",
"function Foo(){}",
"/** @type {number} */",
"Foo.prototype.Foo_prototype$x;",
"/** @constructor */",
"function Bar(){}",
"/** @type {number} */",
"Bar.prototype.Bar_prototype$x;",
"function f(/** Bar */ i){return i.Bar_prototype$x}");

testSets(js, output, "{x=[[Bar.prototype], [Foo.prototype, I.prototype]]}");
}

@Test
public void testStructuralTyping_typeConflationIsRecordedThroughTemplateTypes() {
testSets(
lines(
"/** @record */",
"class Record {",
" /** @return {string} */",
" bar() {}",
"}",
"",
"class Concrete {",
" /** @return {string} */",
" bar() { return ''; }",
"}",
"",
"/**",
" * @param {!Array<!Concrete>} concretes",
" * @return {!Array<!Record>}",
" */",
"function conflate(concretes) { return concretes; }"),
// TODO(b/124766232): The correct disambiguation sets would be:
// "{bar=[[Concrete.prototype, Record.prototype]]}"
"{bar=[[Concrete.prototype], [Record.prototype]]}");
}

/**
* Tests that the type based version skips renaming on types that have a mismatch, and the type
* tightened version continues to work as normal.
Expand Down

0 comments on commit cdc0915

Please sign in to comment.