Skip to content

Calling a generic method during object construction incorrectly constrains the generic to a type #18967

@steveisaac

Description

@steveisaac

When calling a generic method directly during object construction I get a warning that my code is causing my method to be less generic than the type annotation.

Repro steps

    type Test() as self =
        do
            self.PrintString 12
        member this.PrintString<'a> (x : 'a) = Console.WriteLine(x.ToString())

Expected behavior

The above compiles without warnings.

Actual behavior

I get the warning FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'a has been constrained to be type 'int'

Related information

.NET 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBug

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions