On Thu, Nov 25, 2010 at 6:54 PM, Graydon Hoare <[email protected]> wrote:

> On 10-11-25 08:50 AM, Igor Bukanov wrote:
> > My preference is the option 1.
>
> Aw man! We were almost drifting towards a consensus. Nuts!
>

More dissenting opinions then!

How about 2, but with a tweak to the type checker so it only unifies the
types of the two arms if it *really* needs to?

So, if the type of the whole if-expression is (), then the type of each arm
can be different (implicitly ignoring any non-() value, perhaps by just
inserting a "()" at the end of each arm), but if the type is anything else,
then it needs to match with both arms.

I.e.

if (b) { getInt() } else { getFloat() } // fine, implicitly ignores the
values/types
auto x = if (b) { getInt() } else { getFloat()  // Error, the arms of the if
have different types

The trailing semi-colon would be an aesthetic optional that wouldn't impact
semantics.

As far as I can tell, this would seem to avoid subtle problems due to
missing a semi-colon and trivial mistakes like that, while also matching
intuition about what should be legal. The downside is that the type-checking
becomes a bit unorthodox.

-- 
Sebastian Sylvan
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to