Skip to content

Bug in byref-return checking: passing local struct address should not be permitted #1401

Closed
@dsyme

Description

@dsyme

This is a bug in ref-return safety checking, a missing error for negative test case https://github.com/Microsoft/visualfsharp/pull/1367/files#diff-59ae1d2137d6b7479475f5d1287557d9L13

For most cases of returning byrefs we correctly report an error, e,g

let negTest5() = 
    let mutable x = 0
    let addr = &x
    &addr

But not for this case:

Repro steps

Compile this code:

module Test

[<Struct>]
type Struct(initial:int) = 
    let mutable x = initial
    member __.AddrX = &x
    member __.IncrX() = x <- x + 1

let negTest7() = 
    let mutable iterator = Struct(0)
    iterator.AddrX

Expected behavior

We expect an error to be reported

Actual behavior

No error is reported

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions