Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum exhaustiveness checking with --noImplicitReturns doesn't work for nested switches #27388

Closed
arielshaqed opened this issue Sep 27, 2018 · 2 comments · Fixed by #32695
Closed
Labels
Duplicate An existing issue was already created

Comments

@arielshaqed
Copy link

TypeScript Version: 3.2.0-dev.20180927

Search Terms:

enum nested switch

Code

enum E {
  A = 'A', B = 'B', C = 'C'
};

function one(e: E): number {
  switch (e) {
    case E.A: return 1;
    case E.B: return 2;
    case E.C: return 3;
  }
}

function two(e: E, f: E): number {
  switch (e) {
  case E.A: return 1;
  case E.B: return 2;
  case E.C:
    switch (f!) {
    case E.A: return 31;
    case E.B: return 32;
    case E.C: return 33;
    }
  }
}

Expected behavior:

Successful compilation: if one is OK, then so is two.

Actual behavior:

flutterby:tmp ariels$ tsc --noImplicitReturns x.ts
x.ts:13:27 - error TS7030: Not all code paths return a value.

13 function two(e: E, f: E): number {

Playground Link:
https://www.typescriptlang.org/play/#src=enum%20E%20%7B%0D%0A%20%20A%20%3D%20'A'%2C%20B%20%3D%20'B'%2C%20C%20%3D%20'C'%0D%0A%7D%3B%0D%0A%0D%0Afunction%20one(e%3A%20E)%3A%20number%20%7B%0D%0A%20%20switch%20(e)%20%7B%0D%0A%20%20%20%20case%20E.A%3A%20return%201%3B%0D%0A%20%20%20%20case%20E.B%3A%20return%202%3B%0D%0A%20%20%20%20case%20E.C%3A%20return%203%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Afunction%20two(e%3A%20E%2C%20f%3A%20E)%3A%20number%20%7B%0D%0A%20%20switch%20(e)%20%7B%0D%0A%20%20%20%20case%20E.A%3A%20return%201%3B%0D%0A%20%20%20%20case%20E.B%3A%20return%202%3B%0D%0A%20%20%20%20case%20E.C%3A%0D%0A%20%20%20%20%20%20switch%20(f!)%20%7B%0D%0A%20%20%20%20%20%20%20%20case%20E.A%3A%20return%2031%3B%0D%0A%20%20%20%20%20%20%20%20case%20E.B%3A%20return%2032%3B%0D%0A%20%20%20%20%20%20%20%20case%20E.C%3A%20return%2033%3B%0D%0A%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%7D%0D%0A

Related Issues:

Possibly a simpler case of #23572

@mattmccutchen
Copy link
Contributor

Possible duplicate of #11572.

@ghost ghost added the Duplicate An existing issue was already created label Sep 27, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants