Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Only update typar name when TyparStaticReq matches.
  • Loading branch information
nojaf committed Aug 23, 2023
commit 62ea216e1f6b9a6a5aa301952895395507013718
23 changes: 23 additions & 0 deletions member-contrains-type-extension.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Extensions

type DataItem<'data> =
{ Identifier: string
Label: string
Data: 'data }

static member Create<'data>(identifier: string, label: string, data: 'data) =
{ DataItem.Identifier = identifier
DataItem.Label = label
DataItem.Data = data }

#nowarn "957"

type DataItem< ^input> with

static member inline Create(item: ^input) =
let stringValue: string = (^input: (member get_StringValue: unit -> string) (item))

let friendlyStringValue: string =
(^input: (member get_FriendlyStringValue: unit -> string) (item))

DataItem.Create< ^input>(stringValue, friendlyStringValue, item)
6 changes: 4 additions & 2 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4049,8 +4049,10 @@ module TcDeclarations =
if tcref.TyparsNoRange.Length = synTypars.Length then
(tcref.TyparsNoRange, synTypars)
||> List.zip
|> List.iter (fun (typar, SynTyparDecl.SynTyparDecl (typar = SynTypar (ident = untypedIdent))) ->
typar.SetIdent(untypedIdent)
|> List.iter (fun (typar, SynTyparDecl.SynTyparDecl (typar = tp)) ->
let (SynTypar(ident = untypedIdent; staticReq = sr)) = tp
if typar.StaticReq = sr then
typar.SetIdent(untypedIdent)
)

res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,31 @@ else ()
|> run
|> shouldSucceed
|> withExitCode 0

[<Fact>]
let ``Respect nowarn 957 for extension method`` () =
FSharp """
module Foo

type DataItem<'data> =
{ Identifier: string
Label: string
Data: 'data }

static member Create<'data>(identifier: string, label: string, data: 'data) =
{ DataItem.Identifier = identifier
DataItem.Label = label
DataItem.Data = data }

#nowarn "957"

type DataItem< ^input> with

static member inline Create(item: ^input) =
let stringValue: string = (^input: (member get_StringValue: unit -> string) (item))
let friendlyStringValue: string = (^input: (member get_FriendlyStringValue: unit -> string) (item))

DataItem.Create< ^input>(stringValue, friendlyStringValue, item)
"""
|> compile
|> shouldSucceed
43 changes: 43 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,49 @@ type System.Collections.Concurrent.ConcurrentDictionary<'key,'value> with

member TryFind: key: 'key -> 'value option"""

[<Fact>]
let ``Don't update typar name in type extension when TyparStaticReq doesn't match`` () =
FSharp """
module Extensions

type DataItem<'data> =
{ Identifier: string
Label: string
Data: 'data }

static member Create<'data>(identifier: string, label: string, data: 'data) =
{ DataItem.Identifier = identifier
DataItem.Label = label
DataItem.Data = data }

#nowarn "957"

type DataItem< ^input> with

static member inline Create(item: ^input) =
let stringValue: string = (^input: (member get_StringValue: unit -> string) (item))

let friendlyStringValue: string =
(^input: (member get_FriendlyStringValue: unit -> string) (item))

DataItem.Create< ^input>(stringValue, friendlyStringValue, item)
"""
|> printSignatures
|> should equal
"""
module Extensions

type DataItem<'data> =
{
Identifier: string
Label: string
Data: 'data
}

static member inline Create: item: ^input -> DataItem<^input> when ^input: (member get_StringValue: unit -> string) and ^input: (member get_FriendlyStringValue: unit -> string)

static member Create<'data> : identifier: string * label: string * data: 'data -> DataItem<'data>"""

[<Fact>]
let ``ValText for C# abstract member override`` () =
let csharp = CSharp """
Expand Down