Skip to content

Commit 107814e

Browse files
authored
[Python/Beam] Add tests for #4160 generic parameter resolution (#4391)
1 parent a5437df commit 107814e

2 files changed

Lines changed: 160 additions & 0 deletions

File tree

tests/Beam/TypeTests.fs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,83 @@ let ``test Type abbreviation works`` () =
731731
// t1.X |> equal 10
732732
// let mutable t2 = ValueType3()
733733
// t2.X |> equal 0
734+
735+
// Test types for generic parameter static member resolution
736+
type TestTypeA =
737+
static member GetValue() = "A"
738+
static member Combine(x: int, y: int) = x + y + 100
739+
740+
type TestTypeB =
741+
static member GetValue() = "B"
742+
static member Combine(x: int, y: int) = x + y + 200
743+
744+
type TestTypeC =
745+
static member GetValue() = "C"
746+
static member Combine(x: int, y: int) = x + y + 300
747+
748+
// Inline functions for testing multiple generic parameters with static member constraints
749+
let inline getTwoValues<'a, 'b when 'a: (static member GetValue: unit -> string)
750+
and 'b: (static member GetValue: unit -> string)> () =
751+
'a.GetValue(), 'b.GetValue()
752+
753+
let inline getThreeValues<'a, 'b, 'c when 'a: (static member GetValue: unit -> string)
754+
and 'b: (static member GetValue: unit -> string)
755+
and 'c: (static member GetValue: unit -> string)> () =
756+
'a.GetValue(), 'b.GetValue(), 'c.GetValue()
757+
758+
let inline getValuesAndCombine<'a, 'b when 'a: (static member GetValue: unit -> string)
759+
and 'a: (static member Combine: int * int -> int)
760+
and 'b: (static member GetValue: unit -> string)
761+
and 'b: (static member Combine: int * int -> int)> x y =
762+
let aVal = 'a.GetValue()
763+
let bVal = 'b.GetValue()
764+
let aCombined = 'a.Combine(x, y)
765+
let bCombined = 'b.Combine(x, y)
766+
(aVal, aCombined), (bVal, bCombined)
767+
768+
let inline getReversed<'x, 'y when 'x: (static member GetValue: unit -> string)
769+
and 'y: (static member GetValue: unit -> string)> () =
770+
'y.GetValue(), 'x.GetValue()
771+
772+
let inline innerGet<'t when 't: (static member GetValue: unit -> string)> () =
773+
't.GetValue()
774+
775+
let inline outerGet<'a, 'b when 'a: (static member GetValue: unit -> string)
776+
and 'b: (static member GetValue: unit -> string)> () =
777+
innerGet<'a>(), innerGet<'b>()
778+
779+
[<Fact>]
780+
let ``test Inline function with two generic parameters resolves static members correctly`` () =
781+
let result = getTwoValues<TestTypeA, TestTypeB>()
782+
result |> equal ("A", "B")
783+
784+
[<Fact>]
785+
let ``test Inline function with three generic parameters resolves static members correctly`` () =
786+
let result = getThreeValues<TestTypeA, TestTypeB, TestTypeC>()
787+
result |> equal ("A", "B", "C")
788+
789+
[<Fact>]
790+
let ``test Inline function with multiple constraints per type parameter works`` () =
791+
let result = getValuesAndCombine<TestTypeA, TestTypeB> 10 20
792+
result |> equal (("A", 130), ("B", 230))
793+
794+
[<Fact>]
795+
let ``test Inline function with reversed type parameter order works`` () =
796+
let result = getReversed<TestTypeA, TestTypeB>()
797+
result |> equal ("B", "A")
798+
799+
[<Fact>]
800+
let ``test Nested inline functions resolve generic parameters correctly`` () =
801+
let result = outerGet<TestTypeA, TestTypeB>()
802+
result |> equal ("A", "B")
803+
804+
[<Fact>]
805+
let ``test Different type parameter combinations work correctly`` () =
806+
let result1 = getTwoValues<TestTypeB, TestTypeA>()
807+
result1 |> equal ("B", "A")
808+
809+
let result2 = getTwoValues<TestTypeC, TestTypeA>()
810+
result2 |> equal ("C", "A")
811+
812+
let result3 = getTwoValues<TestTypeB, TestTypeC>()
813+
result3 |> equal ("B", "C")

tests/Python/TestType.fs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,3 +1677,83 @@ let ``test Type test decimal`` () =
16771677

16781678
box 5M |> isDecimal |> equal true
16791679
box 5 |> isDecimal |> equal false
1680+
1681+
// Test types for generic parameter static member resolution
1682+
type TestTypeA =
1683+
static member GetValue() = "A"
1684+
static member Combine(x: int, y: int) = x + y + 100
1685+
1686+
type TestTypeB =
1687+
static member GetValue() = "B"
1688+
static member Combine(x: int, y: int) = x + y + 200
1689+
1690+
type TestTypeC =
1691+
static member GetValue() = "C"
1692+
static member Combine(x: int, y: int) = x + y + 300
1693+
1694+
// Inline functions for testing multiple generic parameters with static member constraints
1695+
let inline getTwoValues<'a, 'b when 'a: (static member GetValue: unit -> string)
1696+
and 'b: (static member GetValue: unit -> string)> () =
1697+
'a.GetValue(), 'b.GetValue()
1698+
1699+
let inline getThreeValues<'a, 'b, 'c when 'a: (static member GetValue: unit -> string)
1700+
and 'b: (static member GetValue: unit -> string)
1701+
and 'c: (static member GetValue: unit -> string)> () =
1702+
'a.GetValue(), 'b.GetValue(), 'c.GetValue()
1703+
1704+
let inline getValuesAndCombine<'a, 'b when 'a: (static member GetValue: unit -> string)
1705+
and 'a: (static member Combine: int * int -> int)
1706+
and 'b: (static member GetValue: unit -> string)
1707+
and 'b: (static member Combine: int * int -> int)> x y =
1708+
let aVal = 'a.GetValue()
1709+
let bVal = 'b.GetValue()
1710+
let aCombined = 'a.Combine(x, y)
1711+
let bCombined = 'b.Combine(x, y)
1712+
(aVal, aCombined), (bVal, bCombined)
1713+
1714+
let inline getReversed<'x, 'y when 'x: (static member GetValue: unit -> string)
1715+
and 'y: (static member GetValue: unit -> string)> () =
1716+
'y.GetValue(), 'x.GetValue()
1717+
1718+
let inline innerGet<'t when 't: (static member GetValue: unit -> string)> () =
1719+
't.GetValue()
1720+
1721+
let inline outerGet<'a, 'b when 'a: (static member GetValue: unit -> string)
1722+
and 'b: (static member GetValue: unit -> string)> () =
1723+
innerGet<'a>(), innerGet<'b>()
1724+
1725+
[<Fact>]
1726+
let ``test Inline function with two generic parameters resolves static members correctly`` () =
1727+
let result = getTwoValues<TestTypeA, TestTypeB>()
1728+
result |> equal ("A", "B")
1729+
1730+
[<Fact>]
1731+
let ``test Inline function with three generic parameters resolves static members correctly`` () =
1732+
let result = getThreeValues<TestTypeA, TestTypeB, TestTypeC>()
1733+
result |> equal ("A", "B", "C")
1734+
1735+
[<Fact>]
1736+
let ``test Inline function with multiple constraints per type parameter works`` () =
1737+
let result = getValuesAndCombine<TestTypeA, TestTypeB> 10 20
1738+
result |> equal (("A", 130), ("B", 230))
1739+
1740+
[<Fact>]
1741+
let ``test Inline function with reversed type parameter order works`` () =
1742+
let result = getReversed<TestTypeA, TestTypeB>()
1743+
result |> equal ("B", "A")
1744+
1745+
[<Fact>]
1746+
let ``test Nested inline functions resolve generic parameters correctly`` () =
1747+
let result = outerGet<TestTypeA, TestTypeB>()
1748+
result |> equal ("A", "B")
1749+
1750+
[<Fact>]
1751+
let ``test Different type parameter combinations work correctly`` () =
1752+
let result1 = getTwoValues<TestTypeB, TestTypeA>()
1753+
result1 |> equal ("B", "A")
1754+
1755+
let result2 = getTwoValues<TestTypeC, TestTypeA>()
1756+
result2 |> equal ("C", "A")
1757+
1758+
let result3 = getTwoValues<TestTypeB, TestTypeC>()
1759+
result3 |> equal ("B", "C")

0 commit comments

Comments
 (0)