Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Type inference for a record/class behaves differently when module is open or not #580

@ant0nsc

Description

@ant0nsc

In a module that defines a record R and a discriminated union type where one case is called R, type inference is able to distinguish between the 2 types when the module is open, but not when I qualify the type name with the module name. Is that a bug or by design?

Tested in Microsoft (R) F# Interactive version 14.0.23413.0

Repro steps

module Module =
    type R = { a: int } with static member New = { a = 1 }
    type Choice = | R of R
open Module
// This is accepted, R is inferred to be the record type.
let record1 = R.New
let choice1 v =
    match v with
    | R r -> r
    | _ -> failwith "Nope."
// R is inferred to be of type Choice.R, hence R.New not recognized.
let record2 = Module.R.New
let choice2 v =
    match v with
    | Module.R r -> r
    | _ -> failwith "Nope."

Expected behavior

In record2, I would have expected that Module.R is inferred to be the record type.

Actual behavior

Module.R is inferred to be of type Choice.R

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions