Skip to content

Type inference behaves slightly differently in JDK 8 #438

@omarkilani

Description

@omarkilani

Not sure if this belongs in closure-library or closure-compiler.

When compiling closure-library with --jscomp_error=checkTypes using JDK 8, the compiler errors on this code:

closure/goog/dom/abstractrange.js:79: ERROR - Property item never defined on range
        } else if (!range.length || range.item(0).document != doc) {
                                    ^    

Modifying the code to:

diff --git a/closure/goog/dom/abstractrange.js b/closure/goog/dom/abstractrange.js
--- a/closure/goog/dom/abstractrange.js
+++ b/closure/goog/dom/abstractrange.js
@@ -76,7 +76,7 @@ goog.dom.AbstractRange.getBrowserSelectionForWindow = function(win) {
           if (range.parentElement().document != doc) {
             return null;
           }
-        } else if (!range.length || range.item(0).document != doc) {
+        } else if (!range.length || /** @type {ControlRange} */ (range).item(0).document != doc) {
           // For ControlRanges, check that the range has items, and that
           // the first item in the range is in the correct document.
           return null;

Solves the problem.

I have no idea why type inference works with JDK < 8 in this case.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions