Skip to content

Commit

Permalink
[NTI] Some CheckConformance bugfixes, including making isUnresolved a…
Browse files Browse the repository at this point in the history
… stub that always returns false in NTI.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130540732
  • Loading branch information
aravind-pg authored and dimvar committed Aug 18, 2016
1 parent 2b74136 commit e02980d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/com/google/javascript/jscomp/ConformanceRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ protected boolean isUnknown(Node n) {
return (type == null || type.isUnknownType());
}

protected boolean isSomeUnknownType(Node n) {
TypeI type = n.getTypeI();
return (type == null || type.isSomeUnknownType());
}

protected boolean isTypeVariable(Node n) {
TypeI type = n.getTypeI().restrictByNotNullOrUndefined();
return type.isTypeVariable();
Expand Down Expand Up @@ -1232,7 +1237,7 @@ protected ConformanceResult checkConformance(NodeTraversal t, Node n) {
}

if (n.isGetProp()
&& n.getTypeI().isSomeUnknownType()
&& isSomeUnknownType(n)
&& isUsed(n) // skip most assignments, etc
&& !isTypeImmediatelyTightened(n)
&& isCheckablePropertySource(n.getFirstChild()) // not a cascading unknown
Expand Down
6 changes: 5 additions & 1 deletion src/com/google/javascript/jscomp/newtypes/JSType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,11 @@ public boolean isSomeUnknownType() {

@Override
public boolean isUnresolved() {
return isUnknown();
// TODO(aravindpg): This is purely a stub to ensure we never get into a codepath that
// depends on us being an unresolved type. We currently do not mark unresolved types as such
// in NTI since the main use-case (warning for unfulfilled forward declares) can be
// handled differently (by warning after GTI), so we don't want to change the type system.
return false;
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions test/com/google/javascript/jscomp/CheckConformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,15 @@ public void testCustomBanUnresolvedType() {
+ "/** @param {Foo} a */ function f(a) {a.foo()};",
CheckConformance.CONFORMANCE_VIOLATION,
"Violation: BanUnresolvedType Message");

this.mode = TypeInferenceMode.BOTH;
testSame(LINE_JOINER.join(
"/** @suppress {newCheckTypes}",
" * @param {!Object<string, ?>} data",
" */",
"function foo(data) {",
" data['bar'].baz();",
"}"));
}

public void testMergeRequirements() {
Expand Down

0 comments on commit e02980d

Please sign in to comment.