d80fab4a8a
If the switch's expression has type 'dynamic' and all the case expressions have the same type, we compare them using '=='. This requires a cast to ensure all the types match for the dispatch to the '==' function. However, we don't check that the type of the switch expression matches the type of the case expressions. So the cast fails if they don't match. This adds a guard to ensure the types match before running through the case expressions. If the guard fails, we either jump to the default case or if there isn't one, we skip the switch entirely. Fixes: https://github.com/dart-lang/sdk/issues/59782 Change-Id: I12e81f98d1c2046ee47e8ca4371642fd40620636 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402460 Commit-Queue: Nate Biggs <natebiggs@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>