{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/532","labels_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/532/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/532/comments","events_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/532/events","html_url":"https://github.com/Microsoft/visualfsharp/issues/532","id":95106358,"number":532,"title":"Compiler Bug: Cross module inlining when it shouldn't","user":{"login":"manofstick","id":2093966,"avatar_url":"https://avatars.githubusercontent.com/u/2093966?v=3","gravatar_id":"","url":"https://api.github.com/users/manofstick","html_url":"https://github.com/manofstick","followers_url":"https://api.github.com/users/manofstick/followers","following_url":"https://api.github.com/users/manofstick/following{/other_user}","gists_url":"https://api.github.com/users/manofstick/gists{/gist_id}","starred_url":"https://api.github.com/users/manofstick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manofstick/subscriptions","organizations_url":"https://api.github.com/users/manofstick/orgs","repos_url":"https://api.github.com/users/manofstick/repos","events_url":"https://api.github.com/users/manofstick/events{/privacy}","received_events_url":"https://api.github.com/users/manofstick/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/visualfsharp/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-15T04:57:39Z","updated_at":"2015-07-15T21:47:05Z","closed_at":null,"body":"NB. Now I'm at work so haven't tested this on the 4.0 compiler, so I may end up closing this bug before anyone reads it; but anyway...\r\n\r\nIf you have an assembly with two files which have the same namespace, and one has a record type with private constructor and the second has a factory method for the constructor, and then you have a second assembly that accesses the factory method, the f# compiler inlines the call to the internal type and throws an exception at runtime.\r\n\r\nAssembly 1 - File 1\r\n\r\n    namespace ThisNamespaceHasToBeTheSame\r\n    type Hidden = private { x : int } with member this.X = this.x\r\n\r\nAssembly 1 - File 2\r\n\r\n    namespace ThisNamespaceHasToBeTheSame\r\n    module Factory = let New () = { x = 0 } \r\n\r\nAssembly 2 - File 3\r\n\r\n    [<EntryPoint>]\r\n    let main argv = \r\n        let boom = ThisNamespaceHasToBeTheSame.Factory.New ()\r\n        boom.X\r\n\r\nThe runtime exception:\r\n\r\n    Unhandled Exception: System.MethodAccessException: Attempt by method 'Program.main(System.String[])' to access method 'ThisNamespaceHasToBeTheSame.Hidden..ctor(Int32)' failed.\r\n       at Program.main(String[] argv) in ...\\Program.fs:line 4\r\n\r\nThe IL\r\n\r\n\tIL_0000: nop\r\n\tIL_0001: ldc.i4.0\r\n\tIL_0002: newobj instance void [Library1]ThisNamespaceHasToBeTheSame.Hidden::.ctor(int32) // Shouldn't be accessing this!\r\n\tIL_0007: tail.\r\n\tIL_0009: callvirt instance int32 [Library1]ThisNamespaceHasToBeTheSame.Hidden::get_X()\r\n\tIL_000e: ret\r\n\r\nSo this error only occurs if the two files share the same namespace, as otherwise you wouldn't be able to construct the record type in the second file. If file1 and file2 are merged then the compiles does not inline the call."},"comment":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/comments/121759679","html_url":"https://github.com/Microsoft/visualfsharp/issues/532#issuecomment-121759679","issue_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/532","id":121759679,"user":{"login":"dsyme","id":7204669,"avatar_url":"https://avatars.githubusercontent.com/u/7204669?v=3","gravatar_id":"","url":"https://api.github.com/users/dsyme","html_url":"https://github.com/dsyme","followers_url":"https://api.github.com/users/dsyme/followers","following_url":"https://api.github.com/users/dsyme/following{/other_user}","gists_url":"https://api.github.com/users/dsyme/gists{/gist_id}","starred_url":"https://api.github.com/users/dsyme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsyme/subscriptions","organizations_url":"https://api.github.com/users/dsyme/orgs","repos_url":"https://api.github.com/users/dsyme/repos","events_url":"https://api.github.com/users/dsyme/events{/privacy}","received_events_url":"https://api.github.com/users/dsyme/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T21:47:05Z","updated_at":"2015-07-15T21:47:05Z","body":"Yes, this should be fixed (I can help with the fix, I know the code that prevents this sort of thing well enough).  "}}