Re: "" : List[String]
Kevin Reid <kpreid-M/[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
On Apr 27, 2010, at 11:03, Thomas Leonard wrote: > This surprised me: > > ? "" : List[String] > # value: "" > > ? "" : List[int] > # value: [] > > I was calling TreeItem.setText(str). When str is the empty string it > coerces to a list of strings and you get "Ambiguous overload on class > org.eclipse.swt.widgets.TableItem: setText(String) vs > setText(String[])". > > Is this intentional? It isn deliberate that String is a subtype of ConstList. I do not care for this choice, because things which want lists usually don't want strings-of-characters, and because it breaks the property we would otherwise have that if a :List and b :List have the same elements, they are ==. The list guard returning "" is evidently because the "cheap success" case in ListGuard passed, because the element guard is a ClassDesc. That this code has this behavior in one optimization-based case and not in another seems to me more evidence that "" being a ConstList is a bad idea. (Having String be a subtype of EList, the mutable-or-immutable-list type, would seem to me to serve the same acknowledge-the-protocol- inheritance purpose and be safer.) But, I wouldn't want to make this kind of significant change without consulting MarkM. -- Kevin Reid <http://switchb.org/kpreid/>