#2653 Elvis shortcut operator in ctor

SlimerDude Tue 10 Oct 2017

Somewhat related to this topic It would be nice to be able to use the Elvis convenience operator in a ctor like this:

class Example {
    Str val
	
    new make(|This| f) {
        f(this)

        // --> Cannot use '?:' operator on non-nullable type 'sys::Str'
        val = val ?: "--wotever--"
    }
}

But it gives a compilation error as shown. Thus forcing you to write it long hand:

if (val == null) val = "--wotever--"

brian Mon 16 Oct 2017

I agree it might be nice, but that code is already fairly tricky (just fixed a bug related to it), so not sure its worth the trade-off

Login or Signup to reply.