Skip to content

Implicit yield and if-then when using records with similarly-named fields causes type inference error #14213

@cmeeren

Description

@cmeeren

Consider this:

type A = { X: int }
type B = { X: int }

let _x: (A -> int) list = [
    fun a -> a.X
    if true then fun a -> a.X
]

This fails with a type inference error:

image

Adding yield works:

let _x: (A -> int) list = [
    yield fun a -> a.X
    if true then yield fun a -> a.X
]

As does type annotations to both a parameters:

let _x: (A -> int) list = [
    fun (a: A) -> a.X
    if true then fun (a: A) -> a.X
]

As does removing the if:

let _x: (A -> int) list = [
    fun a -> a.X
    fun a -> a.X
]

As a developer with no knowledge of the compiler, I can't see a compelling reason why I get the error. I would expect it to work.

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions