dao
dao copied to clipboard
Weird typing rules for empty containers
(dao) l: list<int> = {}
= { }
(dao) l2 = (list<io::Stream>)l
= { }
That won't work for a non-empty list, so the behavior here seems exceedingly awkward.
The casting on lists (and maps) is done in element-wise, so you can cast empty list to any other type of list.
That's so confusing that it arguably brings more harm then help:
(dao) routine cast(x: list<io::Stream>){
..... io.writeln((list<int>)x)
..... }
= none
(dao) cast({})
{ }
= none
(dao) cast({io::stdio})
{ 0 }
= none
(dao) (int)io::stdio
[[Error::Type]] --- Invalid type:
casting from 'Stream' to 'int'.
In code snippet:
0 : GETCL : 0 , 0 , 0 ; 1; io
>> 1 : CAST_I : 0 , 1 , 1 ; 1; (int)io::stdio
2 : RETURN : 1 , 1 , 0 ; 1; (int)io::stdio
Raised by: __main__(), at instruction 1 in line 1 in file "interactive codes";
list<io::Stream> can be cast to list<int>, while io::Stream to int -- cannot? The logic here is puzzling.
That's not all.
(dao) class A {}
= none
(dao) interface I{}
= none
(dao) a = A()
= A[02544460]
(dao) (I)a
= A[02544460]
(dao) l = {a}
= { A[02544460] }
(dao) (list<I>)l
[[Error::Type]] --- Invalid type:
casting from 'list<A>' to 'list<I>'.
In code snippet:
0 : GETVG : 0 , 3 , 0 ; 1; l
>> 1 : CAST : 0 , 0 , 1 ; 1; (list<I>)l
2 : RETURN : 1 , 1 , 0 ; 1; (list<I>)l
Raised by: __main__(), at instruction 1 in line 1 in file "interactive codes";
Now it's immensely confusing for me.
OK, now there are bugs.