This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 8092 - HTMLCollection subclass interfaces are incompatible with static languages
Summary: HTMLCollection subclass interfaces are incompatible with static languages
Status: CLOSED FIXED
Alias: None
Product: HTML WG
Classification: Unclassified
Component: pre-LC1 HTML5 spec (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords: NE
Depends on:
Blocks:
 
Reported: 2009-10-27 22:13 UTC by Maciej Stachowiak
Modified: 2010-10-04 14:47 UTC (History)
5 users (show)

See Also:


Attachments

Description Maciej Stachowiak 2009-10-27 22:13:38 UTC
HTMLCollection has a namedItem method that returns "Element", and the interfaces that inherit from HTMLCollection (such as HTMLAllCollection) override it with a namedItem method that returns "object".

This is a problem because you can't generate interfaces for any statically typed language (e.g. Java or Objective-C) from the WebIDL as written. The base class would return a specific type ("Element) but subclasses would return a more general type (Java "Object" or Objective-C "id"), which is not allowed in those languages. Return types in derived classes have to be covariant, not contravariant. This would be fixed by having namedItem() in the base interface declared to return "object" type, even though in practice a vanilla HTMLCollection will only return Elements.
Comment 1 Maciej Stachowiak 2009-10-27 22:15:11 UTC
As a side note, though contravariant return types are not really a problem in JS, declaring a more specific return type in the WebIDL doesn't particularly help JavaScript either. The exposed JavaScript behavior is not affected.
Comment 2 Ian 'Hixie' Hickson 2009-12-08 15:45:42 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with reporter's comments.

But note that anyone who is using polymorphism with HTMLCollection is going to shoot themselves in the foot really badly.
Comment 3 contributor 2009-12-08 15:46:09 UTC
Checked in as WHATWG revision r4418.
Check-in comment: Change the IDL for HTMLCollection to support statically typed languages.
http://html5.org/tools/web-apps-tracker?from=4417&to=4418
Comment 4 Maciej Stachowiak 2009-12-08 16:06:59 UTC
(In reply to comment #2)
> 
> But note that anyone who is using polymorphism with HTMLCollection is going to
> shoot themselves in the foot really badly.
> 

I think you are probably right. All that's essential to be able to run the IDL compiler on the spec IDL to generate ObjC or Java bindings without failing.