23
23
import static com.google.javascript.jscomp.TypeCheck.INSTANTIATE_ABSTRACT_CLASS;
24
24
import static com.google.javascript.jscomp.TypeCheck.POSSIBLE_INEXISTENT_PROPERTY_EXPLANATION;
25
25
import static com.google.javascript.jscomp.TypeCheck.STRICT_INEXISTENT_PROPERTY;
26
+ import static com.google.javascript.jscomp.TypeCheck.STRICT_INEXISTENT_UNION_PROPERTY;
26
27
import static com.google.javascript.jscomp.parsing.JsDocInfoParser.BAD_TYPE_WIKI_LINK;
27
28
import static com.google.javascript.jscomp.testing.ScopeSubject.assertScope;
28
29
import static com.google.javascript.rhino.testing.NodeSubject.assertNode;
@@ -2578,7 +2579,8 @@ public void testDontDropPropertiesInUnion1() {
2578
2579
"function f(x) {",
2579
2580
" var /** null */ n = x.b;",
2580
2581
"}")
2581
- .addDiagnostic(STRICT_INEXISTENT_PROPERTY)
2582
+ .addDiagnostic(STRICT_INEXISTENT_UNION_PROPERTY)
2583
+ .addDiagnostic(TypeValidator.TYPE_MISMATCH_WARNING)
2582
2584
.run();
2583
2585
}
2584
2586
@@ -2590,7 +2592,8 @@ public void testDontDropPropertiesInUnion2() {
2590
2592
"function f(x) {",
2591
2593
" var /** null */ n = x.b;",
2592
2594
"}")
2593
- .addDiagnostic(STRICT_INEXISTENT_PROPERTY)
2595
+ .addDiagnostic(STRICT_INEXISTENT_UNION_PROPERTY)
2596
+ .addDiagnostic(TypeValidator.TYPE_MISMATCH_WARNING)
2594
2597
.run();
2595
2598
}
2596
2599
@@ -2602,7 +2605,7 @@ public void testDontDropPropertiesInUnion3() {
2602
2605
"function f(x) {}",
2603
2606
"/** @param {{a: number}} x */",
2604
2607
"function g(x) { return x.b; }")
2605
- .addDiagnostic(STRICT_INEXISTENT_PROPERTY )
2608
+ .addDiagnostic(TypeCheck.INEXISTENT_PROPERTY )
2606
2609
.run();
2607
2610
}
2608
2611
@@ -2639,21 +2642,23 @@ public void testDontDropPropertiesInUnion6() {
2639
2642
.addDiagnostic(
2640
2643
lines(
2641
2644
"initializing variable", //
2642
- "found : {a: number}",
2645
+ "found : ({",
2646
+ " a: number,",
2647
+ " b: string",
2648
+ "}|{a: number})",
2643
2649
"required: null"))
2644
2650
.run();
2645
2651
}
2646
2652
2647
2653
@Test
2648
2654
public void testDontDropPropertiesInUnion7() {
2649
- // Only a strict warning because in the registry we map {a, c} to {b, d}
2650
2655
newTest()
2651
2656
.addSource(
2652
2657
"/** @param {{a: number}|{a:number, b:string}} x */",
2653
2658
"function f(x) {}",
2654
2659
"/** @param {{c: number}|{c:number, d:string}} x */",
2655
2660
"function g(x) { return x.b; }")
2656
- .addDiagnostic(STRICT_INEXISTENT_PROPERTY )
2661
+ .addDiagnostic(TypeCheck.INEXISTENT_PROPERTY )
2657
2662
.run();
2658
2663
}
2659
2664
0 commit comments