@@ -748,55 +748,37 @@ bool TypeChecker::visit(Conditional const& _conditional)
748
748
{
749
749
expectType (_conditional.condition (), BoolType ());
750
750
751
- if (_conditional.annotation ().lValueRequested )
752
- {
753
- requireLValue (_conditional.trueExpression ());
754
- requireLValue (_conditional.falseExpression ());
755
-
756
- TypePointer const & trueType = type (_conditional.trueExpression ());
757
- TypePointer const & falseType = type (_conditional.falseExpression ());
751
+ _conditional.trueExpression ().accept (*this );
752
+ _conditional.falseExpression ().accept (*this );
758
753
759
- // as a left value, we require exact match to prevent subtle conversion issues.
760
- if (*trueType != *falseType)
761
- typeError (
762
- _conditional.location (),
763
- " True expression's type " +
764
- trueType->toString () +
765
- " doesn't match false expression's type " +
766
- falseType->toString () +
767
- " ."
768
- );
754
+ TypePointer const & trueType = type (_conditional.trueExpression ());
755
+ TypePointer const & falseType = type (_conditional.falseExpression ());
769
756
770
- _conditional.annotation ().type = trueType;
771
- _conditional.annotation ().isLValue = true ;
772
- }
773
- else
757
+ // we fake it as an equal operator, but any other comparison operator can work.
758
+ TypePointer commonType = trueType->binaryOperatorResult (Token::Equal, falseType);
759
+ if (!commonType)
774
760
{
775
- _conditional.trueExpression ().accept (*this );
776
- _conditional.falseExpression ().accept (*this );
761
+ typeError (
762
+ _conditional.location (),
763
+ " True expression's type " +
764
+ trueType->toString () +
765
+ " doesn't match false expression's type " +
766
+ falseType->toString () +
767
+ " ."
768
+ );
769
+ // even we can't find a common type, we have to set a type here,
770
+ // otherwise the upper statement will not be able to check the type.
771
+ commonType = trueType;
772
+ }
777
773
778
- TypePointer const & trueType = type (_conditional.trueExpression ());
779
- TypePointer const & falseType = type (_conditional.falseExpression ());
774
+ _conditional.annotation ().type = commonType;
780
775
781
- // we fake it as an equal operator, but any other comparison operator can work.
782
- TypePointer commonType = trueType->binaryOperatorResult (Token::Equal, falseType);
783
- if (!commonType)
784
- {
785
- typeError (
786
- _conditional.location (),
787
- " True expression's type " +
788
- trueType->toString () +
789
- " doesn't match false expression's type " +
790
- falseType->toString () +
791
- " ."
792
- );
793
- // even we can't find a common type, we have to set a type here,
794
- // otherwise the upper statement will not be able to check the type.
795
- commonType = trueType;
796
- }
776
+ if (_conditional.annotation ().lValueRequested )
777
+ typeError (
778
+ _conditional.location (),
779
+ " Conditional expression as left value is not supported yet."
780
+ );
797
781
798
- _conditional.annotation ().type = commonType;
799
- }
800
782
return false ;
801
783
}
802
784
0 commit comments