Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes Issue 9398 - Print colon instead of question mark for mismatch …

…of ternary operator types.
  • Loading branch information...
commit bba09e60fa4cbb59c84fc125d4ca58a4eb231578 1 parent f1738a0
@drey08 drey08 authored
Showing with 16 additions and 2 deletions.
  1. +4 −2 src/expression.c
  2. +12 −0 test/fail_compilation/diag9398.d
View
6 src/expression.c
@@ -6369,15 +6369,17 @@ Expression *BinExp::incompatibleTypes()
e2->type->toBasetype() != Type::terror
)
{
+ // CondExp uses 'a ? b : c' but we're comparing 'b : c'
+ TOK thisOp = (op == TOKquestion) ? TOKcolon : op;
if (e1->op == TOKtype || e2->op == TOKtype)
{
error("incompatible types for ((%s) %s (%s)): cannot use '%s' with types",
- e1->toChars(), Token::toChars(op), e2->toChars(), Token::toChars(op));
+ e1->toChars(), Token::toChars(thisOp), e2->toChars(), Token::toChars(op));
}
else
{
error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
- e1->toChars(), Token::toChars(op), e2->toChars(),
+ e1->toChars(), Token::toChars(thisOp), e2->toChars(),
e1->type->toChars(), e2->type->toChars());
}
return new ErrorExp();
View
12 test/fail_compilation/diag9398.d
@@ -0,0 +1,12 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/diag9398.d(11): Error: incompatible types for ((f) : (s)): 'float' and 'string'
+---
+*/
+void main()
+{
+ float f;
+ string s;
+ auto a = (true ? f : s);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.