-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Regression: failure when comparing two values of the same enum type #10665
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
Comments
It looks like control flow is tripping you up, although I'm not sure yet whether if it's working as intended. Basically, after the line I know that If that's the case, then perhaps control flow analysis should know when it is narrowing a property of |
Yes, I'm pretty sure that this feature is working as designed for now. I observed that adding an obvious narrowing inside the body of the loop also gets rid of the error, like this: while (this._cpu.executionState !== CpuInterface.ExecutionState.fetch) {
if (this._cycle()) {
this._cpu.executionState = CpuInterface.ExecutionState.fetch;
}
cycles++;
if (this._subClock === 0) {
cpuCycles++;
}
} Since For a real workaround, I'd recommend not breaking the |
This looks like the same issue as #10613. I have a similar explanation in #10613 (comment) |
Hi @sandersn ! Thanks for the feedback! As this is a performance critical part of the emulator (the very inner loop, executed at ~3-4 MHz), I prefer checking the state via direct comparision over a function call at the price of loosening the abstraction. However, I am fine with either of the two other workarounds ;) Is this part of control flow analysis going to be refined in a future release? The way JS and TS are designed, any function call might have side effects that mutate this._cpu, so the assumptions made by the compiler in this situation seem rather brittle to me ;) Cheers |
Yes, control flow is still being improved as we observe the ways it fails. Lots of tweaks and fixes are going into 2.1 already, for example. |
TypeScript Version: 2.0.2
Code
Unfortunately, I have not been able to construct a reduced testcase, so I prepared a branch in the failing project to demonstrate the issue. Please checkout
https://github.com/DirtyHairy/6502.ts
and switch to the branch
ts-broken
. Doingnpm install
andgrunt initial
will demonstrate the issue. After that, the failing compile can be retriggered viagrunt ts
.Expected behavior:
Project builds.
Actual behavior:
The code used to compile fine before 2.0.2 . The failing code fragment is this function:
The corresponding types are declared in this snippet:
I think the problem was introduced when enum values were split into different types, and I suspect that two issues are at work here:
this._cpu.executionState
to beCpuInterface.ExecutionState.boot
. However, callingthis.cycle()
will mutate the execution state.!==
to be of different type and rejects the comparision.After introducing a manual cast
the code compiles fine
However, as I said, I have not been able to construct a reduced test case, so some other aspect of my code seems to contribute to the compiler's confusion 😏
The text was updated successfully, but these errors were encountered: