Visitar URL original
Codegen issue w.r.t. `DefaultAugmentation(false)` · Issue #16565 · dotnet/fsharp · GitHub
Skip to content

Codegen issue w.r.t. DefaultAugmentation(false) #16565

Closed

Description

@vzarytovskii

Given the following code:

open System
[<DefaultAugmentation(false)>]
type Option<'T> =
    | Some of Value: 'T
    | None
 
    member x.Value =
        match x with
        | Some x -> x
        | None -> raise (new InvalidOperationException("Option.Value"))
 
    static member None : Option<'T> = None
and 'T option = Option<'T>

When compiling or pasted to FSI, produces the following issue:

Error in pass2 for type ..., error: duplicate entry 'get_None' in method table

Removing DefaultAugmentation attribute and static member None resolves the issue.

Interestingly enough, this is roughly how FSharpOption is defined in fslib, it also fails to compile in fsi, but not in product compiler apparently.

If it's a regression, then it's a fairly old one, SharpLab shows it and they use F# 6

Activity

  1. added this to the Backlog milestone on Jan 22, 2024
  2. vzarytovskii commented on Jan 22, 2024

    @vzarytovskii
    MemberAuthor

    Additionally, there are multiple issues with both method and properties, which are related to this one:

    open System
    [<DefaultAugmentation(false)>]
    [<StructuralEquality; StructuralComparison>]
    [<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
    [<CompiledName("FSharpOption`1")>]
    type Option<'T> =
        | Some of Value: 'T
        | None
    
        [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
        member x.Value =
            match x with
            | Some x -> x
            | None -> raise (new InvalidOperationException("Option.Value"))
    
        [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
        member x.IsNone =
            match x with
            | None -> true
            | _ -> false
    
        [<CompilationRepresentation(CompilationRepresentationFlags.Instance)>]
        member x.IsSome =
            match x with
            | Some _ -> true
            | _ -> false

    will yield

    error FS0192: internal error: Error in pass2 for type FSI_0019, error: Error in pass2 for type FSharpOption`1, error: duplicate entry 'get_Value' in method table

    open System
    [<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
    type Option<'T> =
        | Some of Value: 'T
        | None
    
        member x.Value =
            match x with
            | Some x -> x
            | None -> failwith "None"

    will yield

    error FS0192: internal error: Error in pass2 for type FSI_0013, error: Error in pass2 for type Option`1, error: duplicate entry 'Value' in property table

    When either of the following is changed, it compiles correctly (valid for both cases):

    • member x.Value is completely removed
    • member x.Value is rewritten as member x.Value = () (this fixes is probably due to return type change)
    • Some of Value: 'T is rewritten as Some of ValueZ: 'T or Some of 'T (will generate two separate properties in ilxgen)
    • [<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>] is removed (not sure how and why does it affect this specific codegen path).
  3. added
    Area-Diagnosticsmistakes and possible improvements to diagnostics
    Impact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
    and removed on Jan 22, 2024
  4. added 6 commits that reference this issue on Feb 20, 2026
    4939af0
    7175341
    5744d1d
    63e792d
    3b64857
    56491f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendArea-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions