{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10665","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10665/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10665/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10665/events","html_url":"https://github.com/Microsoft/TypeScript/issues/10665","id":174515535,"number":10665,"title":"Regression: failure when comparing two values of the same enum type","user":{"login":"DirtyHairy","id":2444224,"avatar_url":"https://avatars.githubusercontent.com/u/2444224?v=3","gravatar_id":"","url":"https://api.github.com/users/DirtyHairy","html_url":"https://github.com/DirtyHairy","followers_url":"https://api.github.com/users/DirtyHairy/followers","following_url":"https://api.github.com/users/DirtyHairy/following{/other_user}","gists_url":"https://api.github.com/users/DirtyHairy/gists{/gist_id}","starred_url":"https://api.github.com/users/DirtyHairy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirtyHairy/subscriptions","organizations_url":"https://api.github.com/users/DirtyHairy/orgs","repos_url":"https://api.github.com/users/DirtyHairy/repos","events_url":"https://api.github.com/users/DirtyHairy/events{/privacy}","received_events_url":"https://api.github.com/users/DirtyHairy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Bug","name":"Bug","color":"e11d21"}],"state":"closed","locked":false,"assignee":{"login":"sandersn","id":293473,"avatar_url":"https://avatars.githubusercontent.com/u/293473?v=3","gravatar_id":"","url":"https://api.github.com/users/sandersn","html_url":"https://github.com/sandersn","followers_url":"https://api.github.com/users/sandersn/followers","following_url":"https://api.github.com/users/sandersn/following{/other_user}","gists_url":"https://api.github.com/users/sandersn/gists{/gist_id}","starred_url":"https://api.github.com/users/sandersn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandersn/subscriptions","organizations_url":"https://api.github.com/users/sandersn/orgs","repos_url":"https://api.github.com/users/sandersn/repos","events_url":"https://api.github.com/users/sandersn/events{/privacy}","received_events_url":"https://api.github.com/users/sandersn/received_events","type":"User","site_admin":false},"assignees":[{"login":"sandersn","id":293473,"avatar_url":"https://avatars.githubusercontent.com/u/293473?v=3","gravatar_id":"","url":"https://api.github.com/users/sandersn","html_url":"https://github.com/sandersn","followers_url":"https://api.github.com/users/sandersn/followers","following_url":"https://api.github.com/users/sandersn/following{/other_user}","gists_url":"https://api.github.com/users/sandersn/gists{/gist_id}","starred_url":"https://api.github.com/users/sandersn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandersn/subscriptions","organizations_url":"https://api.github.com/users/sandersn/orgs","repos_url":"https://api.github.com/users/sandersn/repos","events_url":"https://api.github.com/users/sandersn/events{/privacy}","received_events_url":"https://api.github.com/users/sandersn/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2016-09-01T12:54:15Z","updated_at":"2016-09-14T17:04:36Z","closed_at":"2016-09-14T17:04:33Z","body":"**TypeScript Version:**  2.0.2\r\n\r\n**Code**\r\n\r\nUnfortunately, 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 \r\n\r\nhttps://github.com/DirtyHairy/6502.ts\r\n\r\nand switch to the branch `ts-broken`. Doing `npm install` and `grunt initial` will demonstrate the issue. After that, the failing compile can be retriggered via `grunt ts`.\r\n\r\n**Expected behavior:**\r\n\r\nProject builds.\r\n\r\n**Actual behavior:** \r\n\r\n```\r\nUsing tsc v2.0.2\r\nsrc/machine/stella/Board.ts(139,16): error TS2365: Operator '!==' cannot be applied to types 'ExecutionState.boot' and 'ExecutionState.fetch'\r\n```\r\n\r\nThe code used to compile fine before 2.0.2 . The failing code fragment is this function:\r\n\r\n```\r\n    boot(): Board {\r\n        let cycles = 0,\r\n            cpuCycles = 0;\r\n\r\n        this.reset();\r\n\r\n        if (this._cpu.executionState !== CpuInterface.ExecutionState.boot)\r\n            throw new Error(\"Already booted!\");\r\n\r\n        while (this._cpu.executionState !== CpuInterface.ExecutionState.fetch) {\r\n            this._cycle();\r\n\r\n            cycles++;\r\n            if (this._subClock === 0) {\r\n                cpuCycles++;\r\n            }\r\n        }\r\n\r\n        this.cpuClock.dispatch(cpuCycles);\r\n        this.clock.dispatch(cycles);\r\n        return this;\r\n    }\r\n```\r\n\r\nThe corresponding types are declared in this snippet:\r\n\r\n```\r\ninterface CpuInterface {\r\n\r\n    // [...]\r\n\r\n    executionState: CpuInterface.ExecutionState;\r\n    \r\n    // [...]\r\n\r\n}\r\n\r\nmodule CpuInterface {\r\n    export const enum ExecutionState {\r\n        boot, fetch, execute\r\n    }\r\n\r\n    // [...] \r\n\r\n}\r\n```\r\n\r\nI think the problem was introduced when enum values were split into different types, and I suspect that two issues are at work here:\r\n\r\n 1. The assertion leads the compiler to infer the type of `this._cpu.executionState` to be `CpuInterface.ExecutionState.boot`. However, calling `this.cycle()` will mutate the execution state.\r\n 2. The compiler deems the two sides of `!==` to be of different type and rejects the comparision.\r\n\r\nAfter introducing a manual cast\r\n```\r\nwhile (this._cpu.executionState as CpuInterface.ExecutionState !== CpuInterface.ExecutionState.fetch) {\r\n```\r\nthe code compiles fine\r\n\r\nHowever, 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 :smirk:"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/247083448","html_url":"https://github.com/Microsoft/TypeScript/issues/10665#issuecomment-247083448","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10665","id":247083448,"user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T17:04:36Z","updated_at":"2016-09-14T17:04:36Z","body":"This looks like the same issue as https://github.com/Microsoft/TypeScript/issues/10613. I have a similar explanation in https://github.com/Microsoft/TypeScript/issues/10613#issuecomment-246727374"}}
{"actor":{"display_login":"mhegazy"}}