Skip to content

Commit 849df9b

Browse files
author
joeyaiello
committed
RFC0002: remove relaxed splatting for .NET methods
1 parent db1f017 commit 849df9b

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

1-Draft/RFC0002-Generalized-Splatting.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,6 @@ $subStringArgs = @{startIndex = 2}
173173
$str.SubString(3, @$subStringArgs)
174174
```
175175

176-
Using the relaxed splatting operator, the `3` value will override the value in `$subStringArgs`:
177-
178-
```PowerShell
179-
# This will not result in an error,
180-
# and the substring will be of length 3.
181-
$subStringArgs = @{startIndex = 2}
182-
$str.SubString(3, @?$subStringArgs)
183-
```
184-
185176
Multiple splatted arguments are not allowed:
186177

187178
```PowerShell
@@ -196,9 +187,40 @@ The splatted argument must be last.
196187
$str.SubString(@@{length=2}, 2)
197188
```
198189

199-
200190
## Alternate Proposals and Considerations
201191

192+
### Relaxed splatting in method invocations
193+
194+
Initially, we wanted to support relaxed splatting for invocation of .NET methods.
195+
In this case, the `3` value would override the value in `$subStringArgs`:
196+
197+
```PowerShell
198+
# This will not result in an error,
199+
# and the substring will be of length 3.
200+
$subStringArgs = @{startIndex = 2}
201+
$str.SubString(3, @?$subStringArgs)
202+
```
203+
204+
However, some situations may make it ambiguous or unclear as to which overload you're invoking.
205+
206+
While not a good practice for API design, if the third overload below is added at a later date,
207+
the meaning of the PowerShell will change when using relaxed splatting.
208+
209+
```csharp
210+
class foo {
211+
void static bar(int a, string b);
212+
void static bar(int a, string b, int c);
213+
// this third overload may be added at a later date
214+
void static bar(int d, int a, string b, int c);
215+
}
216+
```
217+
218+
```PowerShell
219+
$params = @{a = 1; b = '2'; c = 3}
220+
221+
[foo]::bar(0, @?$params)
222+
```
223+
202224
### Slicing operators
203225

204226
The suggested use of '+' and '-' is perhaps surprising

0 commit comments

Comments
 (0)