diff --git a/src/com/google/javascript/jscomp/NTIScope.java b/src/com/google/javascript/jscomp/NTIScope.java index f199d59f3e0..5efdbe45366 100644 --- a/src/com/google/javascript/jscomp/NTIScope.java +++ b/src/com/google/javascript/jscomp/NTIScope.java @@ -35,7 +35,6 @@ import com.google.javascript.jscomp.newtypes.Typedef; import com.google.javascript.rhino.JSDocInfo; import com.google.javascript.rhino.Node; - import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -592,8 +591,15 @@ private Declaration getLocalDeclaration(String name, boolean includeTypes) { } else if (externs.containsKey(name)) { type = externs.get(name); } + Namespace ns = null; + if (localNamespaces.containsKey(name)) { + ns = localNamespaces.get(name); + } else if (preservedNamespaces != null) { + ns = preservedNamespaces.get(name); + } + return new Declaration(type, localTypedefs.get(name), - localNamespaces.get(name), localFunDefs.get(name), isTypeVar, + ns, localFunDefs.get(name), isTypeVar, constVars.contains(name)); } diff --git a/src/com/google/javascript/jscomp/newtypes/Declaration.java b/src/com/google/javascript/jscomp/newtypes/Declaration.java index 9889f4bfe2f..f3b58c53519 100644 --- a/src/com/google/javascript/jscomp/newtypes/Declaration.java +++ b/src/com/google/javascript/jscomp/newtypes/Declaration.java @@ -47,7 +47,7 @@ public Declaration(JSType simpleType, Typedef typedef, Namespace ns, private void checkValid() { if (this.simpleType != null) { - Preconditions.checkState(this.typedef == null && this.ns == null); + Preconditions.checkState(this.typedef == null); } if (this.typedef != null) { Preconditions.checkState( @@ -56,7 +56,7 @@ private void checkValid() { if (this.ns != null) { // Note: Non-null nominal with null function is allowed, // e.g., /** @constructor */ var Bar = Foo; - Preconditions.checkState(this.simpleType == null && this.typedef == null); + Preconditions.checkState(this.typedef == null); } if (this.funScope != null) { Preconditions.checkState(this.typedef == null); diff --git a/test/com/google/javascript/jscomp/CheckConformanceTest.java b/test/com/google/javascript/jscomp/CheckConformanceTest.java index 0c1b4f7e1dc..7911b0bbd1d 100644 --- a/test/com/google/javascript/jscomp/CheckConformanceTest.java +++ b/test/com/google/javascript/jscomp/CheckConformanceTest.java @@ -867,9 +867,6 @@ public void testRestrictedMethodCallThisType() { + "var maybeB = cond ? new Base() : null;\n" + "var maybeS = cond ? new Sub() : null;\n"; - // TODO(aravindpg): Fix in NTI. Make "function(this:Sub)" parse to `function(this:Sub)` - // instead of `function(this:?)`. - this.mode = TypeInferenceMode.OTI_ONLY; testSame(code + "b.m(1)", CheckConformance.CONFORMANCE_VIOLATION); testSame(code + "maybeB.m(1)", CheckConformance.CONFORMANCE_VIOLATION); testSame(code + "s.m(1)"); @@ -894,8 +891,6 @@ public void testRestrictedMethodCallUsingCallThisType() { + "var maybeB = cond ? new Base() : null;\n" + "var maybeS = cond ? new Sub() : null;"; - // TODO(aravindpg): Fix in NTI. - this.mode = TypeInferenceMode.OTI_ONLY; testSame(code + "b.m.call(b, 1)", CheckConformance.CONFORMANCE_VIOLATION); testSame(code + "b.m.call(maybeB, 1)", CheckConformance.CONFORMANCE_VIOLATION); testSame(code + "b.m.call(s, 1)");