{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6965","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6965/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6965/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/6965/events","html_url":"https://github.com/Microsoft/TypeScript/issues/6965","id":132234984,"number":6965,"title":"Language services debug assertion when switching compiler options","user":{"login":"martine","id":3847,"avatar_url":"https://avatars.githubusercontent.com/u/3847?v=3","gravatar_id":"","url":"https://api.github.com/users/martine","html_url":"https://github.com/martine","followers_url":"https://api.github.com/users/martine/followers","following_url":"https://api.github.com/users/martine/following{/other_user}","gists_url":"https://api.github.com/users/martine/gists{/gist_id}","starred_url":"https://api.github.com/users/martine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martine/subscriptions","organizations_url":"https://api.github.com/users/martine/orgs","repos_url":"https://api.github.com/users/martine/repos","events_url":"https://api.github.com/users/martine/events{/privacy}","received_events_url":"https://api.github.com/users/martine/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-08T19:26:09Z","updated_at":"2016-02-08T19:26:09Z","closed_at":null,"body":"Suppose you are writing a client of the LanguageService that provides a LanguageServiceHost that implements getCompilationSettings to return CompilerOptions that target ScriptTarget.ES5.\r\n\r\nIf you compile once, then change getCompilationSettings to instead target ScriptTarget.ES6 -- that is, if you dynamically switch the targeted language -- you'll eventually fall into this code path and hit the debug assertion below.\r\n\r\nHowever, it appears the below code after the debug assertion is attempting to correctly handle the case where the settings have changed.  So I think that the debug assertion is unnecessary and should be removed.\r\n\r\nThis issue can also be worked around by recreating the whole stack of LanguageServiceHost from scratch when the compilation target changes, but that seems like it might be slow.  It's potentially the case that clients should expect to recreate this object in that scenario, but then it's not clear why the below code handles the missing entry.\r\n\r\nFeel free to tell me I'm using the API wrong, or whether a reproduction test case would be useful (I pulled this out of a much larger program so reducing it will be a bit painful).\r\n\r\n```javascript\r\n        function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) {\r\n            var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true);\r\n            var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);\r\n            var entry = bucket.get(path);\r\n            if (!entry) {\r\n                ts.Debug.assert(acquiring, \"How could we be trying to update a document that the registry doesn't have?\");\r\n                // Have never seen this file with these settings.  Create a new source file for it.\r\n                var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, /*setNodeParents*/ false);\r\n                entry = {\r\n                    sourceFile: sourceFile,\r\n                    languageServiceRefCount: 0,\r\n                    owners: []\r\n                };\r\n                bucket.set(path, entry);\r\n            }\r\n ```"}}