Dynamically type-casted variables cannot be used to build streams with map()
Closed this issue · 6 comments
In this code, I define a small interface to represent a HTML element that has text, then attempt to build a stream of it.
interface HasText {
shared formal variable String textContent;
}
dynamic {
{HasText*} textItems;
dynamic doc = window.parent.document;
dynamic nodes = doc.getElementsByTagName("A");
Integer nodesLength = nodes.length;
textItems = (0..nodesLength-1).map((Integer i) {
HasText elem = nodes.item(i);
String oldText = elem.textContent;
print(oldText);
return elem;
});
...
}
This, when run with the Beta Web IDE, throws a type error:
Runtime error:
--- TypeError: Expected web_ide_script::run.HasText (new1.ceylon 20:23-20:35)
This should work, because If I change the type of the Stream to {String*}
and build a stream by calling textContent
on each element, then it does work... so it seems it's a bug in not recognizing a custom type.
I don’t think that’s a bug. It works if you make HasText
a dynamic interface: http://trybeta.ceylon-lang.org/?gist=03d6a0375eb1af63442a
Right, this is exactly what dynamic
is for, isn't it.
But does that mean it work for String
because it's treated as a dynamic type?
Well strings and numbers are special, because there is a built-in mapping between JS and Ceylon types.
Indeed, you need to make HasText
a dynamic interface.
Sounds like not a bug, closing.