public override object VisitTernaryExpression([NotNull] PigeonParser.TernaryExpressionContext context) { var condition = Visit(context.expr(0)); var whenTrue = Visit(context.expr(1)); var whenFalse = Visit(context.expr(2)); return((bool)condition ? whenTrue : whenFalse); }
public override void ExitTernaryExpression([NotNull] PigeonParser.TernaryExpressionContext context) { CheckExprType(context.expr(0), PigeonType.Bool); var whenTrue = Types.Get(context.expr(1)); var whenFalse = Types.Get(context.expr(2)); if (!TernaryOperator.TryGetResType(whenTrue, whenFalse, out var type)) { errorBag.ReportInvalidTypeTernaryOperator(context.GetTextSpan(), whenTrue, whenFalse); } Types.Put(context, type); }