Skip to content

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

Closed

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.

Activity

  1. added this to the Backlog milestone on Nov 2, 2022
  2. added
    Area-Compiler-Checking
    Area-Compiler-StateMachines
    Impact-Medium
    on Nov 2, 2022
  3. removed
    Area-Compiler-StateMachines
    on Nov 28, 2022
  4. self-assigned this
    on Sep 21, 2023
  5. modified the milestones: Backlog, September-2023 on Sep 22, 2023
  6. abonie commented on Sep 22, 2023

    @abonie
    Member

    I am starting to look into this, it still repros. Simpler example:

    type A = { X: int }
    type B = { X: int }
    
    let l: A list = [
        if true then { X = 1 }
    ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingBugImpact-Medium

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions