ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

CeylonList, CeylonMap, etc should offer additional constructors for dealing with null

Open gavinking opened this issue 10 years ago • 3 comments

I suppose we need, for example, CeylonList.withNullElements()

gavinking avatar Nov 15 '15 00:11 gavinking

Moving to 1.2.3

quintesse avatar Mar 07 '16 17:03 quintesse

Random thoughts:

I might prefer the opposite: make the programmer assert non-nullness by using a special constructor. But I guess it's too late to consider that.

Conceptually (but not a serious suggestion), it seems that Java T should map to Ceylon T¿, with ¿ indicating that the special interop null rules should apply. Of course, the benefit would be limited unless assigning List<T¿> to List<T> were disallowed, which would be inconvenient.

jvasileff avatar Mar 26 '16 19:03 jvasileff

Currently, the wrappers expose a type hole that looks like the code below (imagine nextItem being in CeylonIterator):

    T nextItem<T>(JIterator<T> it) => it.next();

    value l = JArrayList<String>();
    l.add(null);
    Object s = nextItem(l.iterator());
    print((s of Anything) is Null); // true

It might be nice for the wrappers to perform null checks, since the compiler can't, since the compiler doesn't know whether or not nulls are legal in functions that look like nextItem.

The problem is that this would cost us a reified check to determine if Element is nullable unless we relied on the constructor that was used. But, doing that would result in unwanted null checks for CeylonList<String?>(...).

jvasileff avatar Mar 26 '16 19:03 jvasileff