hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

[Typechecker | Regression] Intersection with enum types disables switch exhaustion check

Open lexidor opened this issue 5 years ago • 3 comments

HHVM Version

HipHop VM 4.23.0-dev (rel)
Compiler: 1568605624_509374463
Repo schema: d3aeac4022c6a43fc3660e7d8141465a7fbb14c2
hackc-9f58f3799749c8d2680054e2c26f95325770390d-4.23.0-dev

Operating System and Version

Ubuntu 18.04

Standalone code, or other way to reproduce the problem

enum NUMBERS: string {
    ONE = 'ONE';
    TWO = 'TWO';
}

<<__EntryPoint>>
function snippet(): void {
    $one = 'ONE';
    $one as NUMBERS;
    switch ($one) {
        case NUMBERS::ONE:
            ;
    }

    $two = 'TWO';
    $two = NUMBERS::assert($two);
    switch ($two) {
        case NUMBERS::ONE:
            ;
    }
}

Actual result

hh_client 
Typing[4019] Switch statement nonexhaustive; the following cases are missing: TWO
   --> src/file.hack
  6 | enum NUMBERS: string {
    |      ^^^^^^^ Enum declared here
 22 |     switch ($two) {
    |             ^^^^

1 error found.

Expected result

Check about $one too.

lexidor avatar Sep 16 '19 16:09 lexidor

Edited repro, because empty switch{} statements are a parse error in newer hhvm versions.

lexidor avatar Jun 02 '20 17:06 lexidor

@vsiles @CatherineGasnier https://github.com/facebook/hhvm/commit/53a12e25ee56d140ddf57a9dc475f834f1d8f890 from @sarahhenkens is a suggested fix for this which appears to work, but looks like it's essentially a revert 7824d828cff1c9fcf2f9c2fc6f320a7d99afd73b - do you have context to share on that or an alternative approach?

fredemmott avatar May 27 '21 15:05 fredemmott

I've commented on 53a12e2

CatherineGasnier avatar May 27 '21 16:05 CatherineGasnier