Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Issue 9398 - Print colon for mismatch of ternary operator types #1555

Merged
merged 1 commit into from over 1 year ago

2 participants

Andrej Mitrovic Andrei Alexandrescu
Andrei Alexandrescu andralex merged commit 57a0ea9 into from
Andrei Alexandrescu
Owner

thanks

Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 26, 2013
Andrej Mitrovic AndrejMitrovic Fixes Issue 9398 - Print colon instead of question mark for mismatch …
…of ternary operator types.
bba09e6
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 16 additions and 2 deletions. Show diff stats Hide diff stats

  1. +4 2 src/expression.c
  2. +12 0 test/fail_compilation/diag9398.d
6 src/expression.c
@@ -6369,15 +6369,17 @@ Expression *BinExp::incompatibleTypes()
6369 6369 e2->type->toBasetype() != Type::terror
6370 6370 )
6371 6371 {
  6372 + // CondExp uses 'a ? b : c' but we're comparing 'b : c'
  6373 + TOK thisOp = (op == TOKquestion) ? TOKcolon : op;
6372 6374 if (e1->op == TOKtype || e2->op == TOKtype)
6373 6375 {
6374 6376 error("incompatible types for ((%s) %s (%s)): cannot use '%s' with types",
6375   - e1->toChars(), Token::toChars(op), e2->toChars(), Token::toChars(op));
  6377 + e1->toChars(), Token::toChars(thisOp), e2->toChars(), Token::toChars(op));
6376 6378 }
6377 6379 else
6378 6380 {
6379 6381 error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
6380   - e1->toChars(), Token::toChars(op), e2->toChars(),
  6382 + e1->toChars(), Token::toChars(thisOp), e2->toChars(),
6381 6383 e1->type->toChars(), e2->type->toChars());
6382 6384 }
6383 6385 return new ErrorExp();
12 test/fail_compilation/diag9398.d
... ... @@ -0,0 +1,12 @@
  1 +/*
  2 +TEST_OUTPUT:
  3 +---
  4 +fail_compilation/diag9398.d(11): Error: incompatible types for ((f) : (s)): 'float' and 'string'
  5 +---
  6 +*/
  7 +void main()
  8 +{
  9 + float f;
  10 + string s;
  11 + auto a = (true ? f : s);
  12 +}

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.