The fact that the semantics of ?: is very ad-hoc is a kind of accident of the history, we may want to fix it but i do not see why we have to fix it at the same time that we introduce the expression switch, we can fix the semantics of ?: later or never.
Rémi ----- Mail original ----- > De: "daniel smith" <daniel.sm...@oracle.com> > À: "Remi Forax" <fo...@univ-mlv.fr> > Cc: "amber-spec-experts" <amber-spec-experts@openjdk.java.net> > Envoyé: Samedi 31 Mars 2018 03:44:49 > Objet: Re: Feedback wanted: switch expression typing >> On Mar 30, 2018, at 10:54 AM, Remi Forax <fo...@univ-mlv.fr> wrote: >> >> I do not see (B) as sacrifying the consistency because the premise is that an >> expression switch should be consistent with ?: >> >> But an expression switch can also be modeled as a classical switch that >> returns >> it's value to a local variable. >> >> int a = switch(foo) { >> case 'a' -> 2; >> case 'b' -> 3; >> } >> can be see as >> int a = $switch(foo); >> with >> int $switch(char foo) { >> case 'a': return 2; >> case 'b': return 3; >> } > > I mean, sure, this is another way to assert "switches in assignment contexts > should always be poly expressions". > > But it's just as easy to assert "conditional expressions in assignment > contexts > should always be poly expressions". > > int a = test ? 2 : 3; > can be seen as > int a = $conditional(test); > with > int $conditional(boolean test) { > if (test) return 2; > else return 3; > } > > Those are probably good principles. But if we embrace them, we're doing (C). > > —Dan