HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

HTMLElement can't be casted to HTMLTableSectionElement #1309

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

/**
 * @return {HTMLElement}
 */
var y = function() {
  document.createElement('tbody');
};
var x = /** @type {HTMLTableSectionElement} */ y();
/** @type {HTMLTableSectionElement} */
var z = x;

What is the expected output? What do you see instead?

Nothing, this typechecks correctly. But instead I get this error:

found   : (HTMLElement|null)
required: (HTMLTableSectionElement|null)
var z = x;
        ^

What version of the product are you using? On what operating system?

Closure Compiler (http://code.google.com/closure/compiler)
Version: v20140407
Built on: 2014/04/07 14:04

Please provide any additional information below.

It seems like a cast to an interface isn't taken into account when the original 
type is a supertype of the interface.

Original issue reported on code.google.com by lgand...@gmail.com on 16 Apr 2014 at 9:35

GoogleCodeExporter commented 9 years ago
A workaround I'm using right now is

/**
 * @return {HTMLElement}
 */
var y = function() {
  document.createElement('tbody');
};
var x = (/** @type {HTMLTableSectionElement} */ ((/** @type {Object} */ 
(y()))));
/** @type {HTMLTableSectionElement} */
var z = x;

Original comment by lgand...@gmail.com on 16 Apr 2014 at 9:38

GoogleCodeExporter commented 9 years ago
The parenthesis after the closing comment are part of the cast syntax:
https://code.google.com/p/closure-compiler/wiki/AnnotatingTypes#Type_Casts

Original comment by blic...@google.com on 16 Apr 2014 at 9:41

GoogleCodeExporter commented 9 years ago
Excuse me very much. This bug issue is wrong again. I think i'll stop 
submitting false positives for today.

Original comment by lgand...@gmail.com on 16 Apr 2014 at 9:42