Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions src/Fable.Transforms/OverloadSuffix.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ let rec private getTypeFastFullName (genParams: IDictionary<_, _>) (t: Fable.Typ
[ argType; returnType ]
|> List.map (getTypeFastFullName genParams)
|> String.concat " -> "
// TODO: Use Func` instead?
| Fable.DelegateType(argTypes, returnType) ->
argTypes @ [ returnType ]
|> List.map (getTypeFastFullName genParams)
|> String.concat " -> "
let types =
argTypes @ [ returnType ]
|> List.map (fun t ->
let name: string = getTypeFastFullName genParams t
$"%d{name.Length}:%s{name}"
)
|> String.concat ""

"delegate(" + types + ")"
| Fable.AnonymousRecordType(fieldNames, genArgs, isStruct) ->
let fields =
Seq.zip fieldNames genArgs
Expand Down
8 changes: 5 additions & 3 deletions src/fable-library-rust/src/System.Collections.Generic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type Comparer<'T>(comparison: 'T -> 'T -> int) =
static member get_Default<'V when 'V: comparison>() =
Comparer<'V>(LanguagePrimitives.GenericComparison)

static member Create(comparison) = Comparer<'T>(comparison)
// Same overload suffix as System.Comparison<'T>, which is what callers of Comparer.Create pass
static member Create(comparison: System.Func<'T, 'T, int>) =
Comparer<'T>(fun x y -> comparison.Invoke(x, y))

member _.Compare(x, y) = comparison x y

Expand All @@ -23,8 +25,8 @@ type EqualityComparer<'T>(equals: 'T -> 'T -> bool, getHashCode: 'T -> int) =
static member get_Default<'V when 'V: equality>() =
EqualityComparer<'V>(LanguagePrimitives.GenericEquality, LanguagePrimitives.GenericHash)

static member Create(equals, getHashCode) =
EqualityComparer<'T>(equals, getHashCode)
static member Create(equals: System.Func<'T, 'T, bool>, getHashCode: System.Func<'T, int>) =
EqualityComparer<'T>((fun x y -> equals.Invoke(x, y)), (fun x -> getHashCode.Invoke x))

member _.Equals(x, y) = equals x y
member _.GetHashCode(x) = getHashCode x
Expand Down
13 changes: 11 additions & 2 deletions src/fable-library-ts/System.Collections.Generic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ type Comparer<'T when 'T: comparison and 'T: null>(comparison: 'T -> 'T -> int)

static member Default = Comparer<'T>(LanguagePrimitives.GenericComparison)

static member Create(comparison) = Comparer<'T>(comparison)
// Same overload suffix as System.Comparison<'T>, which is what callers of Comparer.Create pass
static member Create(comparison: System.Func<'T, 'T, int>) =
Comparer<'T>(fun x y -> comparison.Invoke(x, y))

// Exported for Python output compiled by older Fable versions
static member Create(comparison: 'T -> 'T -> int) = Comparer<'T>(comparison)

member _.Compare(x, y) = comparison x y

Expand All @@ -25,7 +30,11 @@ type EqualityComparer<'T when 'T: equality and 'T: null>(equals: 'T -> 'T -> boo
static member Default =
EqualityComparer<'T>(LanguagePrimitives.GenericEquality, LanguagePrimitives.GenericHash)

static member Create(equals, getHashCode) =
static member Create(equals: System.Func<'T, 'T, bool>, getHashCode: System.Func<'T, int>) =
EqualityComparer<'T>((fun x y -> equals.Invoke(x, y)), (fun x -> getHashCode.Invoke x))

// Exported for Python output compiled by older Fable versions
static member Create(equals: 'T -> 'T -> bool, getHashCode: 'T -> int) =
EqualityComparer<'T>(equals, getHashCode)

member _.Equals(x, y) = equals x y
Expand Down
48 changes: 48 additions & 0 deletions tests/Beam/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ type Type5Test(greeting: string) =
member _.Overload(x: int) = x + x
member _.Overload(x: int, y: int) = x + y

type DelegateOverloads =
static member Apply(f: int -> int, x: int) = f x
static member Apply(f: System.Func<int, int>, x: int) = f.Invoke x + 100
static member Apply(f: int -> int -> int, x: int) = f x x
static member Apply(f: System.Func<int, int, int>, x: int) = f.Invoke(x, x) + 100
static member Apply(f: System.Action<int>, x: int) =
f.Invoke x
x + 200

type NestedDelegateOverloads =
static member C(f: System.Func<int, int> -> int) = "fn:" + string (f (System.Func<int, int>(fun x -> x + 1)))
static member C(f: System.Func<int, int, int>) = "del:" + string (f.Invoke(1, 2))

type GenericNestedDelegateOverloads<'T> =
static member C(f: System.Func<'T, 'T> -> 'T, x: 'T) = f (System.Func<'T, 'T>(id))
static member C(f: System.Func<'T, 'T, 'T>, x: 'T) = f.Invoke(x, x)

type ConstrainedDelegateOverloads =
static member N<'U when 'U: comparison and 'U: null>(f: System.Func<'U, int>) = "one"
static member N<'A, 'B when 'A: comparison and 'B: null>(f: System.Func<'A, 'B, int>) = "two"

let inline applyDelegateOverload< ^T, ^F when ^T: (static member Apply: ^F * int -> int)> (f: ^F) (x: int) =
(^T: (static member Apply: ^F * int -> int) (f, x))

type Type6Test(x: int) =
let mutable i = x
member _.Value2 = i + i
Expand Down Expand Up @@ -150,6 +174,30 @@ let ``test class constructor and property getter work`` () =
let t = Type5Test("hello")
equal "hello" t.Value

[<Fact>]
let ``test overloads distinguished by function or delegate work`` () =
let inc: int -> int = fun x -> x + 1
let add: int -> int -> int = fun x y -> x + y
applyDelegateOverload<DelegateOverloads, int -> int> inc 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int>(fun x -> x + 1), 1) |> equal 102
applyDelegateOverload<DelegateOverloads, int -> int -> int> add 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int, int>(fun x y -> x + y), 1) |> equal 102
DelegateOverloads.Apply(System.Action<int>(ignore), 1) |> equal 201

[<Fact>]
let ``test overloads distinguished by nested delegate work`` () =
let fn: System.Func<int, int> -> int = fun g -> g.Invoke 1
NestedDelegateOverloads.C(fn) |> equal "fn:2"
NestedDelegateOverloads.C(System.Func<int, int, int>(fun x y -> x + y)) |> equal "del:3"
let fnG: System.Func<int, int> -> int = fun g -> g.Invoke 5
GenericNestedDelegateOverloads<int>.C(fnG, 1) |> equal 5
GenericNestedDelegateOverloads<int>.C(System.Func<int, int, int>(fun x y -> x + y), 4) |> equal 8

[<Fact>]
let ``test overloads distinguished by constrained delegate generics work`` () =
ConstrainedDelegateOverloads.N(System.Func<string, int>(fun _ -> 1)) |> equal "one"
ConstrainedDelegateOverloads.N(System.Func<int, string, int>(fun x _ -> x)) |> equal "two"

[<Fact>]
let ``test class method overload with one arg works`` () =
let t = Type5Test("")
Expand Down
45 changes: 45 additions & 0 deletions tests/Dart/src/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,53 @@ type IdHolder(id: Id) =
member _.Id = id
member _.GetId() = id

type DelegateOverloads =
static member Apply(f: int -> int, x: int) = f x
static member Apply(f: System.Func<int, int>, x: int) = f.Invoke x + 100
static member Apply(f: int -> int -> int, x: int) = f x x
static member Apply(f: System.Func<int, int, int>, x: int) = f.Invoke(x, x) + 100
static member Apply(f: System.Action<int>, x: int) =
f.Invoke x
x + 200

type NestedDelegateOverloads =
static member C(f: System.Func<int, int> -> int) = "fn:" + string (f (System.Func<int, int>(fun x -> x + 1)))
static member C(f: System.Func<int, int, int>) = "del:" + string (f.Invoke(1, 2))

type GenericNestedDelegateOverloads<'T> =
static member C(f: System.Func<'T, 'T> -> 'T, x: 'T) = f (System.Func<'T, 'T>(id))
static member C(f: System.Func<'T, 'T, 'T>, x: 'T) = f.Invoke(x, x)

type ConstrainedDelegateOverloads =
static member N<'U when 'U: comparison and 'U: null>(f: System.Func<'U, int>) = "one"
static member N<'A, 'B when 'A: comparison and 'B: null>(f: System.Func<'A, 'B, int>) = "two"

let inline applyDelegateOverload< ^T, ^F when ^T: (static member Apply: ^F * int -> int)> (f: ^F) (x: int) =
(^T: (static member Apply: ^F * int -> int) (f, x))

let tests() =

testCase "Overloads distinguished by function or delegate work" <| fun () ->
let inc: int -> int = fun x -> x + 1
let add: int -> int -> int = fun x y -> x + y
applyDelegateOverload<DelegateOverloads, int -> int> inc 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int>(fun x -> x + 1), 1) |> equal 102
applyDelegateOverload<DelegateOverloads, int -> int -> int> add 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int, int>(fun x y -> x + y), 1) |> equal 102
DelegateOverloads.Apply(System.Action<int>(ignore), 1) |> equal 201

testCase "Overloads distinguished by nested delegate work" <| fun () ->
let fn: System.Func<int, int> -> int = fun g -> g.Invoke 1
NestedDelegateOverloads.C(fn) |> equal "fn:2"
NestedDelegateOverloads.C(System.Func<int, int, int>(fun x y -> x + y)) |> equal "del:3"
let fnG: System.Func<int, int> -> int = fun g -> g.Invoke 5
GenericNestedDelegateOverloads<int>.C(fnG, 1) |> equal 5
GenericNestedDelegateOverloads<int>.C(System.Func<int, int, int>(fun x y -> x + y), 4) |> equal 8

testCase "Overloads distinguished by constrained delegate generics work" <| fun () ->
ConstrainedDelegateOverloads.N(System.Func<string, int>(fun _ -> 1)) |> equal "one"
ConstrainedDelegateOverloads.N(System.Func<int, string, int>(fun x _ -> x)) |> equal "two"

testCase "Unit arguments work" <| fun () ->
update () |> equal ((), ())

Expand Down
45 changes: 45 additions & 0 deletions tests/Js/Main/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,30 @@ type Distinct1 =
static member OfList(_elements: list<'K * 'V>) = ()
static member OfList(_elements: list<struct('K * 'V)>) = ()

type DelegateOverloads =
static member Apply(f: int -> int, x: int) = f x
static member Apply(f: System.Func<int, int>, x: int) = f.Invoke x + 100
static member Apply(f: int -> int -> int, x: int) = f x x
static member Apply(f: System.Func<int, int, int>, x: int) = f.Invoke(x, x) + 100
static member Apply(f: System.Action<int>, x: int) =
f.Invoke x
x + 200

type NestedDelegateOverloads =
static member C(f: System.Func<int, int> -> int) = "fn:" + string (f (System.Func<int, int>(fun x -> x + 1)))
static member C(f: System.Func<int, int, int>) = "del:" + string (f.Invoke(1, 2))

type GenericNestedDelegateOverloads<'T> =
static member C(f: System.Func<'T, 'T> -> 'T, x: 'T) = f (System.Func<'T, 'T>(id))
static member C(f: System.Func<'T, 'T, 'T>, x: 'T) = f.Invoke(x, x)

type ConstrainedDelegateOverloads =
static member N<'U when 'U: comparison and 'U: null>(f: System.Func<'U, int>) = "one"
static member N<'A, 'B when 'A: comparison and 'B: null>(f: System.Func<'A, 'B, int>) = "two"

let inline applyDelegateOverload< ^T, ^F when ^T: (static member Apply: ^F * int -> int)> (f: ^F) (x: int) =
(^T: (static member Apply: ^F * int -> int) (f, x))

type FlexibleOverloads() =
member _.For(xs: 'a list, f: 'a -> 'b list) : 'b list = xs |> List.collect f
member _.For(xs: #seq<'a>, f: 'a -> unit) : int =
Expand Down Expand Up @@ -1218,6 +1242,27 @@ let tests =
t.For([|1; 2; 3|], fun i -> sum <- sum + i) |> equal 3
sum |> equal 6

testCase "Overloads distinguished by function or delegate work" <| fun () ->
let inc: int -> int = fun x -> x + 1
let add: int -> int -> int = fun x y -> x + y
applyDelegateOverload<DelegateOverloads, int -> int> inc 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int>(fun x -> x + 1), 1) |> equal 102
applyDelegateOverload<DelegateOverloads, int -> int -> int> add 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int, int>(fun x y -> x + y), 1) |> equal 102
DelegateOverloads.Apply(System.Action<int>(ignore), 1) |> equal 201

testCase "Overloads distinguished by nested delegate work" <| fun () ->
let fn: System.Func<int, int> -> int = fun g -> g.Invoke 1
NestedDelegateOverloads.C(fn) |> equal "fn:2"
NestedDelegateOverloads.C(System.Func<int, int, int>(fun x y -> x + y)) |> equal "del:3"
let fnG: System.Func<int, int> -> int = fun g -> g.Invoke 5
GenericNestedDelegateOverloads<int>.C(fnG, 1) |> equal 5
GenericNestedDelegateOverloads<int>.C(System.Func<int, int, int>(fun x y -> x + y), 4) |> equal 8

testCase "Overloads distinguished by constrained delegate generics work" <| fun () ->
ConstrainedDelegateOverloads.N(System.Func<string, int>(fun _ -> 1)) |> equal "one"
ConstrainedDelegateOverloads.N(System.Func<int, string, int>(fun x _ -> x)) |> equal "two"

testCase "Type abbreviation works" <| fun () ->
let t = T4()
t.Value2 |> equal "Bye"
Expand Down
20 changes: 20 additions & 0 deletions tests/Python/TestMisc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,26 @@
[<Global("TimeoutError")>]
type TimeoutError() = inherit Exception()

module private LegacyLibraryExports =
open Fable.Core.PyInterop

let comparerCreate: Func<Func<int, int, int>, System.Collections.Generic.IComparer<int>> =
import "Comparer_1_Create_47C913C" "fable_library.system_collections_generic"

let equalityComparerCreate: Func<Func<int, int, bool>, Func<int, int>, System.Collections.Generic.IEqualityComparer<int>> =
import "EqualityComparer_1_Create_Z6EE254AB" "fable_library.system_collections_generic"

[<Fact>]
let ``test Comparer.Create exports used by older compilers still work`` () =
let comparer = LegacyLibraryExports.comparerCreate.Invoke(Func<int, int, int>(fun x y -> compare y x))
comparer.Compare(1, 2) |> equal 1

let equalityComparer =
LegacyLibraryExports.equalityComparerCreate.Invoke(Func<int, int, bool>(fun x y -> x <> y), Func<int, int>(fun x -> x + 1))

equalityComparer.Equals(1, 1) |> equal false
equalityComparer.GetHashCode(1) |> equal 2

[<Fact>]
let ``test Python ExceptionBase compatibility import preserves class identity`` () =
obj.ReferenceEquals(PythonExceptionBases.exceptionBase, PythonExceptionBases.legacyExceptionBase) |> equal true
Expand Down Expand Up @@ -1336,7 +1356,7 @@
| 2 -> x <- "2"
| 3 | 4 -> x <- "3" // Multiple cases are allowed
// | 5 | 6 as j -> x <- string j // This prevents the optimization
| 4 -> x <- "4" // Unreachable cases are removed

Check warning on line 1359 in tests/Python/TestMisc.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.15)

This rule will never be matched

Check warning on line 1359 in tests/Python/TestMisc.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.15)

This rule will never be matched

Check warning on line 1359 in tests/Python/TestMisc.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.14)

This rule will never be matched

Check warning on line 1359 in tests/Python/TestMisc.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.13)

This rule will never be matched

Check warning on line 1359 in tests/Python/TestMisc.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.13)

This rule will never be matched

Check warning on line 1359 in tests/Python/TestMisc.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.14)

This rule will never be matched
| _ -> x <- "?"
equal "3" x

Expand Down
48 changes: 48 additions & 0 deletions tests/Python/TestType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,30 @@
static member OfList(_elements: list<'K * 'V>) = ()
static member OfList(_elements: list<struct ('K * 'V)>) = ()

type DelegateOverloads =
static member Apply(f: int -> int, x: int) = f x
static member Apply(f: System.Func<int, int>, x: int) = f.Invoke x + 100
static member Apply(f: int -> int -> int, x: int) = f x x
static member Apply(f: System.Func<int, int, int>, x: int) = f.Invoke(x, x) + 100
static member Apply(f: System.Action<int>, x: int) =
f.Invoke x
x + 200

type NestedDelegateOverloads =
static member C(f: System.Func<int, int> -> int) = "fn:" + string (f (System.Func<int, int>(fun x -> x + 1)))
static member C(f: System.Func<int, int, int>) = "del:" + string (f.Invoke(1, 2))

type GenericNestedDelegateOverloads<'T> =
static member C(f: System.Func<'T, 'T> -> 'T, x: 'T) = f (System.Func<'T, 'T>(id))
static member C(f: System.Func<'T, 'T, 'T>, x: 'T) = f.Invoke(x, x)

type ConstrainedDelegateOverloads =
static member N<'U when 'U: comparison and 'U: null>(f: System.Func<'U, int>) = "one"
static member N<'A, 'B when 'A: comparison and 'B: null>(f: System.Func<'A, 'B, int>) = "two"

let inline applyDelegateOverload< ^T, ^F when ^T: (static member Apply: ^F * int -> int)> (f: ^F) (x: int) =
(^T: (static member Apply: ^F * int -> int) (f, x))

type InfoA = { Foo: string }

type InfoB = { InfoA: InfoA; Bar: string }
Expand Down Expand Up @@ -662,7 +686,7 @@

type IndexedProps(v: int) =
let mutable v = v
member _.Item with get (v2: int) = v + v2 and set v2 (s: string) = v <- v2 + int s

Check warning on line 689 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.15)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 689 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.15)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 689 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.14)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 689 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.13)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 689 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.13)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 689 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.14)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.
member _.Item with get (v2: float) = float v + v2 / 2.

[<Interface>]
Expand Down Expand Up @@ -1017,6 +1041,30 @@
t.Overload(2) |> equal 4
t.Overload(2, 3) |> equal 5

[<Fact>]
let ``test Overloads distinguished by function or delegate work`` () =
let inc: int -> int = fun x -> x + 1
let add: int -> int -> int = fun x y -> x + y
applyDelegateOverload<DelegateOverloads, int -> int> inc 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int>(fun x -> x + 1), 1) |> equal 102
applyDelegateOverload<DelegateOverloads, int -> int -> int> add 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int, int>(fun x y -> x + y), 1) |> equal 102
DelegateOverloads.Apply(System.Action<int>(ignore), 1) |> equal 201

[<Fact>]
let ``test Overloads distinguished by nested delegate work`` () =
let fn: System.Func<int, int> -> int = fun g -> g.Invoke 1
NestedDelegateOverloads.C(fn) |> equal "fn:2"
NestedDelegateOverloads.C(System.Func<int, int, int>(fun x y -> x + y)) |> equal "del:3"
let fnG: System.Func<int, int> -> int = fun g -> g.Invoke 5
GenericNestedDelegateOverloads<int>.C(fnG, 1) |> equal 5
GenericNestedDelegateOverloads<int>.C(System.Func<int, int, int>(fun x y -> x + y), 4) |> equal 8

[<Fact>]
let ``test Overloads distinguished by constrained delegate generics work`` () =
ConstrainedDelegateOverloads.N(System.Func<string, int>(fun _ -> 1)) |> equal "one"
ConstrainedDelegateOverloads.N(System.Func<int, string, int>(fun x _ -> x)) |> equal "two"

[<Fact>]
let ``test Type abbreviation works`` () =
let t = T4()
Expand Down
48 changes: 48 additions & 0 deletions tests/Rust/tests/src/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@
member _.Overload(x) = x + x
member _.Overload(x, y) = x + y

type DelegateOverloads =
static member Apply(f: int -> int, x: int) = f x
static member Apply(f: System.Func<int, int>, x: int) = f.Invoke x + 100
static member Apply(f: int -> int -> int, x: int) = f x x
static member Apply(f: System.Func<int, int, int>, x: int) = f.Invoke(x, x) + 100
static member Apply(f: System.Action<int>, x: int) =
f.Invoke x
x + 200

type NestedDelegateOverloads =
static member C(f: System.Func<int, int> -> int) = "fn:" + string (f (System.Func<int, int>(fun x -> x + 1)))
static member C(f: System.Func<int, int, int>) = "del:" + string (f.Invoke(1, 2))

type GenericNestedDelegateOverloads<'T> =
static member C(f: System.Func<'T, 'T> -> 'T, x: 'T) = f (System.Func<'T, 'T>(id))
static member C(f: System.Func<'T, 'T, 'T>, x: 'T) = f.Invoke(x, x)

type ConstrainedDelegateOverloads =
static member N<'U when 'U: comparison and 'U: null>(f: System.Func<'U, int>) = "one"
static member N<'A, 'B when 'A: comparison and 'B: null>(f: System.Func<'A, 'B, int>) = "two"

let inline applyDelegateOverload< ^T, ^F when ^T: (static member Apply: ^F * int -> int)> (f: ^F) (x: int) =
(^T: (static member Apply: ^F * int -> int) (f, x))

type TestType8(?greeting) =
member _.Value = defaultArg greeting "Hi"

Expand Down Expand Up @@ -694,7 +718,7 @@

type IndexedProps(v: int) =
let mutable v = v
member _.Item with get (v2: int) = v + v2 and set v2 (s: string) = v <- v2 + int s

Check warning on line 721 in tests/Rust/tests/src/TypeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (,)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 721 in tests/Rust/tests/src/TypeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (threaded)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 721 in tests/Rust/tests/src/TypeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (reflection)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 721 in tests/Rust/tests/src/TypeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (no_std)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 721 in tests/Rust/tests/src/TypeTests.fs

View workflow job for this annotation

GitHub Actions / build-rust (lrc_ptr)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.
member _.Item with get (v2: float) = float v + v2 / 2.

[<Interface>]
Expand Down Expand Up @@ -1086,6 +1110,30 @@
}
gameState.Players.ContainsKey(1) |> equal false

[<Fact>]
let ``Overloads distinguished by function or delegate work`` () =
let inc: int -> int = fun x -> x + 1
let add: int -> int -> int = fun x y -> x + y
applyDelegateOverload<DelegateOverloads, int -> int> inc 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int>(fun x -> x + 1), 1) |> equal 102
applyDelegateOverload<DelegateOverloads, int -> int -> int> add 1 |> equal 2
DelegateOverloads.Apply(System.Func<int, int, int>(fun x y -> x + y), 1) |> equal 102
DelegateOverloads.Apply(System.Action<int>(ignore), 1) |> equal 201

[<Fact>]
let ``Overloads distinguished by nested delegate work`` () =
let fn: System.Func<int, int> -> int = fun g -> g.Invoke 1
NestedDelegateOverloads.C(fn) |> equal "fn:2"
NestedDelegateOverloads.C(System.Func<int, int, int>(fun x y -> x + y)) |> equal "del:3"
let fnG: System.Func<int, int> -> int = fun g -> g.Invoke 5
GenericNestedDelegateOverloads<int>.C(fnG, 1) |> equal 5
GenericNestedDelegateOverloads<int>.C(System.Func<int, int, int>(fun x y -> x + y), 4) |> equal 8

[<Fact>]
let ``Overloads distinguished by constrained delegate generics work`` () =
ConstrainedDelegateOverloads.N(System.Func<string, int>(fun _ -> 1)) |> equal "one"
ConstrainedDelegateOverloads.N(System.Func<int, string, int>(fun x _ -> x)) |> equal "two"

[<Fact>]
let ``Overloads work`` () =
let t = TestType5("")
Expand Down
Loading