google / google/closure-compiler

Report a small bug, and a small fix: False alarm "could not determine the type of this expression"

Open
#1,685 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Hello,
I encountered this annoying bug many times - the bug can be demonstrated by compiling this code:

``` js
(function(){
/** @constructor */
function MyClass() {}
/** @type {!string} */ MyClass.prototype.myProp;
/** @type {!MyClass} */({}).myProp; <== Error: "could not determine the type of this expression"
})();
```

After long deep effort, it seems that this can be fixed by adding one line to `com.google.javascript.jscomp.TypeInference`:
Add this line:

``` java
objType.resolve(registry.getErrorReporter(), scope);
```

right after this line:

``` java
if (propertyType == null && objType != null) {
```

in the method

``` java
private JSType getPropertyType(JSType objType, String propName, Node n, FlowScope scope) {...}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.