Skip to content

Warning FS3536: "(interface) is normally used as a type constraint in generic code" for extension method on interface in .NET 7 SDK #14480

@emz00

Description

@emz00

When compiling an extension method for an interface using .NET SDK 7 you now get a confusing FS3536 warning about type constraints. With .NET SDK 6 there was no such warning. I don't see anything wrong with the code, so as far as I can tell the warning is a bug.

Repro steps

Try to compile the following console EXE:

type INormalInterface =
    abstract member IntMember: int

module INormalInterfaceExtensions =
    type INormalInterface with
        static member extMethod (a: INormalInterface) =
            ()

printfn "Hello from F#"

Project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
</Project>

Expected behavior

Compiles with no warnings, same as with .NET 6 SDK.

Actual behavior

$ dotnet build
MSBuild version 17.4.0+18d5aef85 for .NET
  Determining projects to restore...
  Restored /home/em/src/FS3536/FS3536.fsproj (in 468 ms).
/home/em/src/FS3536/Program.fs(6,37): warning FS3536: 'INormalInterface' is normally used as a type constraint in generic code, e.g. "'T when ISomeInterface<'T>" or "let f (x: #ISomeInterface<_>)". See https://aka.ms/fsharp-iwsams for guidance. You can disable this warning by using '#nowarn "3536"' or '--nowarn:3536'. [/home/em/src/FS3536/FS3536.fsproj]

Known workarounds

Use .NET 6 SDK by creating a global.json file or suppress that specific warning like the message says.

  • Operating system: Ubuntu 18.04
  • .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET 6.0.12
  • .NET SDK: 7.0.101

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions