{"action":"opened","issue":{"url":"https://api.github.com/repos/lionheart/openradar-mirror/issues/12004","repository_url":"https://api.github.com/repos/lionheart/openradar-mirror","labels_url":"https://api.github.com/repos/lionheart/openradar-mirror/issues/12004/labels{/name}","comments_url":"https://api.github.com/repos/lionheart/openradar-mirror/issues/12004/comments","events_url":"https://api.github.com/repos/lionheart/openradar-mirror/issues/12004/events","html_url":"https://github.com/lionheart/openradar-mirror/issues/12004","id":148629496,"number":12004,"title":"18332184: Swift: Types declared in if block & used via higher-order functions fail to compile/link w/o error (in Xcode)","user":{"login":"openradar-mirror","id":13605213,"avatar_url":"https://avatars.githubusercontent.com/u/13605213?v=3","gravatar_id":"","url":"https://api.github.com/users/openradar-mirror","html_url":"https://github.com/openradar-mirror","followers_url":"https://api.github.com/users/openradar-mirror/followers","following_url":"https://api.github.com/users/openradar-mirror/following{/other_user}","gists_url":"https://api.github.com/users/openradar-mirror/gists{/gist_id}","starred_url":"https://api.github.com/users/openradar-mirror/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openradar-mirror/subscriptions","organizations_url":"https://api.github.com/users/openradar-mirror/orgs","repos_url":"https://api.github.com/users/openradar-mirror/repos","events_url":"https://api.github.com/users/openradar-mirror/events{/privacy}","received_events_url":"https://api.github.com/users/openradar-mirror/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lionheart/openradar-mirror/labels/classification:serious%20bug","name":"classification:serious bug","color":"e11d21"},{"url":"https://api.github.com/repos/lionheart/openradar-mirror/labels/reproducible:always","name":"reproducible:always","color":"5319e7"},{"url":"https://api.github.com/repos/lionheart/openradar-mirror/labels/status:open","name":"status:open","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/lionheart/openradar-mirror/milestones/1","html_url":"https://github.com/lionheart/openradar-mirror/milestones/Developer%20Tools","labels_url":"https://api.github.com/repos/lionheart/openradar-mirror/milestones/1/labels","id":1237415,"number":1,"title":"Developer Tools","description":null,"creator":{"login":"openradar-mirror","id":13605213,"avatar_url":"https://avatars.githubusercontent.com/u/13605213?v=3","gravatar_id":"","url":"https://api.github.com/users/openradar-mirror","html_url":"https://github.com/openradar-mirror","followers_url":"https://api.github.com/users/openradar-mirror/followers","following_url":"https://api.github.com/users/openradar-mirror/following{/other_user}","gists_url":"https://api.github.com/users/openradar-mirror/gists{/gist_id}","starred_url":"https://api.github.com/users/openradar-mirror/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openradar-mirror/subscriptions","organizations_url":"https://api.github.com/users/openradar-mirror/orgs","repos_url":"https://api.github.com/users/openradar-mirror/repos","events_url":"https://api.github.com/users/openradar-mirror/events{/privacy}","received_events_url":"https://api.github.com/users/openradar-mirror/received_events","type":"User","site_admin":false},"open_issues":3362,"closed_issues":20,"state":"open","created_at":"2015-08-03T02:08:29Z","updated_at":"2016-04-15T11:01:51Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2016-04-15T11:01:51Z","updated_at":"2016-04-15T11:01:51Z","closed_at":null,"body":"#### Description\n\nSummary:\nWhen you use a higher-order function like compose to return a function which calls a function which uses a type defined in an if block, Swift refuses to compile the file. In Xcode, no error is shown (which is perhaps a separate bug). From the CLI, you get this message:\n\nResonance:Desktop rob$ ./Failure.swift \ninvalid linkage type for global declaration\n%swift.full_type* @_TMdV7FailureL_1S\nLLVM ERROR: Broken module found, compilation aborted!\n\n\nSteps to Reproduce:\n1. Try to compile this code:\n\nif true {\n\tstruct S {\n\t\tlet v: Int\n\t}\n\tlet g = { S(v: $0) }\n\tlet f = { 0 }\n\tfunc compose<T, U, V>(g: U -> V, f: T -> U)(x: T) -> V { return g(f(x)) }\n\tlet h = compose(g, f)\n}\n\n\nExpected Results:\nI expected it to succeed without issue.\n\n\nActual Results:\nIn Xcode, it failed and wouldn’t tell me the issue. From the CLI, it failed and told me something about the issue, but nothing about the source it was operating on, or why it’s a problem. Further, I don’t think it should be a problem at all.\n\n\nRegression:\nIf you move the definition of struct S outside of the if statement, it succeeds.\nIf you let h = { g(f($0)) } (instead of using compose()), it succeeds.\nstruct, enum, class, all of them fail. There is no escape.\nA variant on this using the venerable class Box had a slightly different error:\n\nGlobal is external, but doesn't have external or weak linkage!\n\nFor my case the best workaround is not to define the type inside the if block.\n\n\nNotes:\nN/A\n\n-\nProduct Version: Xcode-Beta (6A1027)\nCreated: 2014-09-14T19:09:05.575201\nOriginated: 2014-09-14T15:08:00\nOpen Radar Link: http://www.openradar.me/18332184"}}