Skip to content

SkipLocalsInit is an unsafe operation, but does not give warning FS0009 #17116

@abelbraaksma

Description

@abelbraaksma

Applying the attribute SkipLocalsInitAttribute is an unsafe operation, but does not raise the FS0009 warning.

Repro steps

type Rain() =
    [<SkipLocalsInit>]
    member _.ItPours(?msg: string) =
        let message= defaultArg mname "absent"
        $"Message: {message}"

Expected behavior

According to the docs, this is an unsafe operation.

F# issues the FS0009 warning for unsafe operations (like fixed and using nativeptr and the like). This warning should be thrown when using SkipLocalsInit as well.

This is akin to using the unsafe keyword in C#, which is indeed required for this attribute.

Actual behavior

The warning is not thrown.

Related information

The suggestion does not mention the term unsafe, but @dsyme mentioned

It's also in the realm of a "allow generation of unverifiable code for performance reasons" feature

which further cements that this is unsafe and that FS0009 should be shown here.

Since this is just a warning, I hope this can be added to F# still, without being considered a backward compatibility issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions