Skip to content

Commit

Permalink
[NTI] Remove undefined from the receiver type when registering stray …
Browse files Browse the repository at this point in the history
…properties.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148969041
  • Loading branch information
dimvar authored and brad4d committed Mar 2, 2017
1 parent ecb07fd commit b5298fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/GlobalTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ private void visitOtherPropertyDeclaration(Node getProp) {
if (recvType == null) {
return;
}
recvType = recvType.removeType(commonTypes.NULL);
recvType = recvType.removeType(commonTypes.NULL_OR_UNDEFINED);
NominalType nt = recvType.getNominalTypeIfSingletonObj();
// Don't add stray properties to Object.
if (nt == null || nt.equals(commonTypes.getObjectType())) {
Expand Down
13 changes: 13 additions & 0 deletions test/com/google/javascript/jscomp/NewTypeInferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19453,4 +19453,17 @@ public void testSuppressInvalidCasts() {
" /** @type {number} */ ('asdf');",
"}"));
}

public void testRegisterStrayPropertyOnReceiverWithUndefined() {
typeCheck(LINE_JOINER.join(
"/** @constructor */",
"function Foo() {}",
"function f(/** (!Foo|undefined) */ x) {",
" x.myprop;",
"}",
"function g(/** !Foo */ x) {",
" return x.myprop;",
"}"),
NewTypeInference.NULLABLE_DEREFERENCE);
}
}

0 comments on commit b5298fe

Please sign in to comment.