{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5458","repository_url":"https://api.github.com/repos/Microsoft/visualfsharp","labels_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5458/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5458/comments","events_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5458/events","html_url":"https://github.com/Microsoft/visualfsharp/issues/5458","id":347562206,"node_id":"MDU6SXNzdWUzNDc1NjIyMDY=","number":5458,"title":"Construction of specific IsByRefLike records and unions give errors","user":{"login":"TIHan","id":1278959,"node_id":"MDQ6VXNlcjEyNzg5NTk=","avatar_url":"https://avatars3.githubusercontent.com/u/1278959?v=4","gravatar_id":"","url":"https://api.github.com/users/TIHan","html_url":"https://github.com/TIHan","followers_url":"https://api.github.com/users/TIHan/followers","following_url":"https://api.github.com/users/TIHan/following{/other_user}","gists_url":"https://api.github.com/users/TIHan/gists{/gist_id}","starred_url":"https://api.github.com/users/TIHan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TIHan/subscriptions","organizations_url":"https://api.github.com/users/TIHan/orgs","repos_url":"https://api.github.com/users/TIHan/repos","events_url":"https://api.github.com/users/TIHan/events{/privacy}","received_events_url":"https://api.github.com/users/TIHan/received_events","type":"User","site_admin":false},"labels":[{"id":295281377,"node_id":"MDU6TGFiZWwyOTUyODEzNzc=","url":"https://api.github.com/repos/Microsoft/visualfsharp/labels/Area-Compiler","name":"Area-Compiler","color":"5319e7","default":false},{"id":164789606,"node_id":"MDU6TGFiZWwxNjQ3ODk2MDY=","url":"https://api.github.com/repos/Microsoft/visualfsharp/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":{"login":"TIHan","id":1278959,"node_id":"MDQ6VXNlcjEyNzg5NTk=","avatar_url":"https://avatars3.githubusercontent.com/u/1278959?v=4","gravatar_id":"","url":"https://api.github.com/users/TIHan","html_url":"https://github.com/TIHan","followers_url":"https://api.github.com/users/TIHan/followers","following_url":"https://api.github.com/users/TIHan/following{/other_user}","gists_url":"https://api.github.com/users/TIHan/gists{/gist_id}","starred_url":"https://api.github.com/users/TIHan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TIHan/subscriptions","organizations_url":"https://api.github.com/users/TIHan/orgs","repos_url":"https://api.github.com/users/TIHan/repos","events_url":"https://api.github.com/users/TIHan/events{/privacy}","received_events_url":"https://api.github.com/users/TIHan/received_events","type":"User","site_admin":false},"assignees":[{"login":"TIHan","id":1278959,"node_id":"MDQ6VXNlcjEyNzg5NTk=","avatar_url":"https://avatars3.githubusercontent.com/u/1278959?v=4","gravatar_id":"","url":"https://api.github.com/users/TIHan","html_url":"https://github.com/TIHan","followers_url":"https://api.github.com/users/TIHan/followers","following_url":"https://api.github.com/users/TIHan/following{/other_user}","gists_url":"https://api.github.com/users/TIHan/gists{/gist_id}","starred_url":"https://api.github.com/users/TIHan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TIHan/subscriptions","organizations_url":"https://api.github.com/users/TIHan/orgs","repos_url":"https://api.github.com/users/TIHan/repos","events_url":"https://api.github.com/users/TIHan/events{/privacy}","received_events_url":"https://api.github.com/users/TIHan/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/milestones/24","html_url":"https://github.com/Microsoft/visualfsharp/milestone/24","labels_url":"https://api.github.com/repos/Microsoft/visualfsharp/milestones/24/labels","id":3510326,"node_id":"MDk6TWlsZXN0b25lMzUxMDMyNg==","number":24,"title":"15.9","description":"","creator":{"login":"cartermp","id":6309070,"node_id":"MDQ6VXNlcjYzMDkwNzA=","avatar_url":"https://avatars0.githubusercontent.com/u/6309070?v=4","gravatar_id":"","url":"https://api.github.com/users/cartermp","html_url":"https://github.com/cartermp","followers_url":"https://api.github.com/users/cartermp/followers","following_url":"https://api.github.com/users/cartermp/following{/other_user}","gists_url":"https://api.github.com/users/cartermp/gists{/gist_id}","starred_url":"https://api.github.com/users/cartermp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cartermp/subscriptions","organizations_url":"https://api.github.com/users/cartermp/orgs","repos_url":"https://api.github.com/users/cartermp/repos","events_url":"https://api.github.com/users/cartermp/events{/privacy}","received_events_url":"https://api.github.com/users/cartermp/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":0,"state":"open","created_at":"2018-07-19T23:25:05Z","updated_at":"2018-08-06T15:00:19Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2018-08-03T23:26:52Z","updated_at":"2018-08-06T20:42:10Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Consider this example:\r\n```fsharp\r\nopen System\r\nopen System.Runtime.CompilerServices\r\n\r\n[<Struct;IsByRefLike>]\r\ntype SpanOption<'T> =\r\n    | SpanNone\r\n    | SpanSome of Span<'T>\r\n\r\n[<Struct;IsByRefLike>]\r\ntype SpanRecord<'T> =\r\n    {\r\n        x: int\r\n        [<DefaultValue>] s: Span<'T>\r\n    }\r\n\r\nlet f () =\r\n    let s = Span<int>.Empty\r\n    let sOpt = SpanSome(s) // error on 's' - The byref typed value 's' cannot be used at this point\r\n    let z = SpanNone // error on 'z' - The type of a first-class function cannot contain byrefs\r\n    let w = { x = 1 } // error on 'w' - The type of a first-class function cannot contain byrefs\r\n    ()\r\n```\r\n\r\n---\r\n\r\nThe expression `SpanSome(s)` fails because we missed a `TOp.UnionCase` addition in `PostInferenceChecks.fs`, it's easy enough to add and fix this part.\r\n\r\n---\r\n\r\nThe `SpanNone` and `{ x = 1 }` fail for a different reason; it's tricky. The compiler will wrap the expressions in a `Expr.TyLambda`. Then later in `PostInferenceChecks.fs`, it will throw an error saying that these `Expr.TyLambda` expressions cannot contain byref-like types as return or parameters. I think part of the reason why it wraps it is because it doesn't know what the type argument, `T, is when doing a let binding. A workaround to it is being explicit:\r\n```fsharp\r\n    let z : SpanOption<int> = SpanNone\r\n    let w : SpanRecord<int> = { x = 1 }\r\n```\r\nBut then this compiles:\r\n```fsharp\r\n[<Struct;IsByRefLike>]\r\ntype SpanRecord<'T> =\r\n    {\r\n        x: int\r\n        s: Span<'T>\r\n    }\r\n\r\nlet f (s) =\r\n    let w = { x = 1; s = s }\r\n    ()\r\n```\r\n`s` is `Span<'a>`, which means we still don't know the type arg is. So I'm missing something fundamental here.\r\n\r\nIn `TypeChecker.fs`, this is the line where the logic occurs:\r\n```fsharp\r\n        // Now bind the r.h.s. to the l.h.s. \r\n        let rhsExpr = mkTypeLambda m generalizedTypars (rhsExpr, tauTy)\r\n```\r\n`mkTypeLambda` should be a `tryMkTypeLambda` because it won't wrap the `rhsExpr` in a `Expr.TyLambda` if the `generalizedTypars` is empty.\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/comments/410846494","html_url":"https://github.com/Microsoft/visualfsharp/issues/5458#issuecomment-410846494","issue_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5458","id":410846494,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDg0NjQ5NA==","user":{"login":"TIHan","id":1278959,"node_id":"MDQ6VXNlcjEyNzg5NTk=","avatar_url":"https://avatars3.githubusercontent.com/u/1278959?v=4","gravatar_id":"","url":"https://api.github.com/users/TIHan","html_url":"https://github.com/TIHan","followers_url":"https://api.github.com/users/TIHan/followers","following_url":"https://api.github.com/users/TIHan/following{/other_user}","gists_url":"https://api.github.com/users/TIHan/gists{/gist_id}","starred_url":"https://api.github.com/users/TIHan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TIHan/subscriptions","organizations_url":"https://api.github.com/users/TIHan/orgs","repos_url":"https://api.github.com/users/TIHan/repos","events_url":"https://api.github.com/users/TIHan/events{/privacy}","received_events_url":"https://api.github.com/users/TIHan/received_events","type":"User","site_admin":false},"created_at":"2018-08-06T20:42:10Z","updated_at":"2018-08-06T20:42:10Z","author_association":"CONTRIBUTOR","body":"I quickly looked at this. It seems\r\n```fsharp\r\n    let z = SpanNone // error on 'z' - The type of a first-class function cannot contain byrefs\r\n    let w = { x = 1 } // error on 'w' - The type of a first-class function cannot contain byrefs\r\n```\r\nWould fail regardless if it was a IsByRefLike or not. If I opt out of the error we get a inference error of out of scope; so it looks like this is fine. Perhaps we could improve error messages regarding this case instead of saying the byref-likes are not allowed."}}
{"actor":{"display_login":"TIHan"}}