|
| 1 | +module FSharp.Compiler.ComponentTests.ErrorMessages.IndexedSetterNamedArgTests |
| 2 | + |
| 3 | +open Xunit |
| 4 | +open FSharp.Test.Compiler |
| 5 | + |
| 6 | +[<Fact>] |
| 7 | +let ``Indexed property setter with named argument does not ICE - intrinsic``() = |
| 8 | + FSharp """ |
| 9 | +module Test |
| 10 | +type T() = |
| 11 | + member x.Item |
| 12 | + with get (a1: obj) = 1 |
| 13 | + and set (a1: obj) (value: int) = () |
| 14 | +
|
| 15 | +let t = T() |
| 16 | +t.Item(a1 = "x") <- 1 |
| 17 | + """ |
| 18 | + |> compile |
| 19 | + |> shouldSucceed |
| 20 | + |
| 21 | +[<Fact>] |
| 22 | +let ``Indexed property setter with named argument does not ICE - named property``() = |
| 23 | + FSharp """ |
| 24 | +module Test |
| 25 | +type T() = |
| 26 | + member x.indexed1 |
| 27 | + with get (a1: obj) = 1 |
| 28 | + and set (a1: obj) (value: int) = () |
| 29 | +
|
| 30 | +let t = T() |
| 31 | +t.indexed1(a1 = "x") <- 1 |
| 32 | + """ |
| 33 | + |> compile |
| 34 | + |> shouldSucceed |
| 35 | + |
| 36 | +[<Fact>] |
| 37 | +let ``Indexed property setter with named argument does not ICE - extension``() = |
| 38 | + FSharp """ |
| 39 | +module Test |
| 40 | +type T() = |
| 41 | + member x.indexed1 |
| 42 | + with get (a1: obj) = 1 |
| 43 | + and set (a1: obj) (value: int) = () |
| 44 | +
|
| 45 | +module Extensions = |
| 46 | + type T with |
| 47 | + member x.indexed1 |
| 48 | + with get (aa1: obj) = 1 |
| 49 | + and set (aa1: obj) (value: int) = () |
| 50 | +
|
| 51 | +open Extensions |
| 52 | +let t = T() |
| 53 | +t.indexed1(aa1 = "x") <- 1 |
| 54 | + """ |
| 55 | + |> compile |
| 56 | + |> shouldSucceed |
| 57 | + |
| 58 | +[<Fact>] |
| 59 | +let ``Indexed property getter with named argument still works``() = |
| 60 | + FSharp """ |
| 61 | +module Test |
| 62 | +type T() = |
| 63 | + member x.indexed1 |
| 64 | + with get (a1: obj) = 1 |
| 65 | + and set (a1: obj) (value: int) = () |
| 66 | +
|
| 67 | +let t = T() |
| 68 | +let _ = t.indexed1(a1 = "x") |
| 69 | + """ |
| 70 | + |> compile |
| 71 | + |> shouldSucceed |
| 72 | + |
| 73 | +[<Theory>] |
| 74 | +[<InlineData("t.indexed1(a1 = \"x\") <- 1")>] |
| 75 | +[<InlineData("t.indexed1(\"x\") <- 1")>] |
| 76 | +[<InlineData("t.set_indexed1(\"x\", 1)")>] |
| 77 | +let ``Indexed setter call shapes compile`` (call: string) = |
| 78 | + FSharp $""" |
| 79 | +module Test |
| 80 | +type T() = |
| 81 | + member x.indexed1 |
| 82 | + with get (a1: obj) = 1 |
| 83 | + and set (a1: obj) (value: int) = () |
| 84 | +
|
| 85 | +let t = T() |
| 86 | +{call} |
| 87 | + """ |
| 88 | + |> compile |
| 89 | + |> shouldSucceed |
| 90 | + |
| 91 | +[<Fact>] |
| 92 | +let ``Multi-arg indexer setter with named args compiles``() = |
| 93 | + FSharp """ |
| 94 | +module Test |
| 95 | +type M() = |
| 96 | + member x.Item |
| 97 | + with get (a: int, b: string) = 1 |
| 98 | + and set (a: int, b: string) (v: int) = () |
| 99 | +
|
| 100 | +let m = M() |
| 101 | +m.[a = 1, b = "x"] <- 5 |
| 102 | +m.[b = "x", a = 1] <- 5 |
| 103 | +m.[1, b = "x"] <- 5 |
| 104 | + """ |
| 105 | + |> compile |
| 106 | + |> shouldSucceed |
| 107 | + |
| 108 | +[<Fact>] |
| 109 | +let ``Default Item indexer setter with named arg compiles``() = |
| 110 | + FSharp """ |
| 111 | +module Test |
| 112 | +type D() = |
| 113 | + member x.Item |
| 114 | + with get (k: string) = 1 |
| 115 | + and set (k: string) (v: int) = () |
| 116 | +
|
| 117 | +let d = D() |
| 118 | +d.[k = "x"] <- 1 |
| 119 | + """ |
| 120 | + |> compile |
| 121 | + |> shouldSucceed |
0 commit comments