[Issue 22514] Invalid duplicate case error when the switched value has errors

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 14 10:34:24 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22514

--- Comment #6 from Dlang Bot <dlang-bot at dlang.rocks> ---
dlang/dmd pull request #13421 "merge stable" was merged into master:

- d14ed1e9c2183a533b6f275be2c6692e9aad4e9e by MoonlightSentinel:
  Fix 22514 - Don't raise invalid duplicate case errors when the switch...

  ... has other errors.

  The duplicate case checks triggered because #11467 made `ErrorExp` into
  a singleton and hence caused `ErrorExp` == `ErrorExp` to yield true even
  if those errors were caused by different expressions.

  This situation can arise from two different user errors:

  1. the case is faulty, e.g. an unknown variable
  2. the switch'ed value is faulty, causing `implicitCastTo` to generate
     an `ErrorExp`.

  This commit fixes (1) by simply skipping the ducplicated case check for
  `ErrorExp` because it doesn't have enough information. (2) requires the
  case expression to not be coerced into the switched type s.t. we can
  at least detect some errors while also keeping the actual case
  expression to offer helpful diagnostics.

https://github.com/dlang/dmd/pull/13421

--


More information about the Digitalmars-d-bugs mailing list