Skip to content

Commit b24f5df

Browse files
authored
Merge pull request #17350 from dotnet/merges/main-to-release/dev17.11
Merge main to release/dev17.11
2 parents 556819c + 281a2b0 commit b24f5df

File tree

6 files changed

+44
-36
lines changed

6 files changed

+44
-36
lines changed

docs/release-notes/.FSharp.Core/8.0.400.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66

77
* Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
88
* Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
9+
10+
### Breaking Changes
11+
12+
* Fixed argument exception throwing inconsistency - accessing an out-of-bounds collection index will now throw `ArgumentOutOfRangeException` instead of `ArgumentException` ([#17328](https://github.com/dotnet/fsharp/pull/17328))

src/FSharp.Core/local.fs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ module internal DetailedExceptions =
1414
let msg = String.Format (format, paramArray)
1515
raise (new ArgumentException (msg, arg))
1616

17+
/// takes an argument, a formatting string, a param array to splice into the formatting string
18+
let inline invalidArgOutOfRangeFmt (arg:string) (format:string) paramArray =
19+
let msg = String.Format (format, paramArray)
20+
raise (new ArgumentOutOfRangeException (arg, msg))
21+
1722
/// takes a formatting string and a param array to splice into the formatting string
1823
let inline invalidOpFmt (format:string) paramArray =
1924
let msg = String.Format (format, paramArray)
@@ -38,7 +43,6 @@ module internal DetailedExceptions =
3843
"{0}\nThe list was {1} {2} shorter than the index"
3944
[|SR.GetString SR.notEnoughElements; index; (if index=1 then "element" else "elements")|]
4045

41-
4246
/// eg. tried to {skip} {2} {elements} past the end of the seq. Seq.Length = {10}
4347
let invalidOpExceededSeqLength (fnName:string) (diff:int) (len:int) =
4448
invalidOpFmt "{0}\ntried to {1} {2} {3} past the end of the seq\nSeq.Length = {4}"
@@ -52,11 +56,11 @@ module internal DetailedExceptions =
5256
let inline invalidArgInputMustBePositive (arg:string) (count:int) =
5357
invalidArgFmt arg "{0}\n{1} = {2}" [|SR.GetString SR.inputMustBePositive; arg; count|]
5458

55-
/// throws an invalid argument exception and returns the out of range index,
59+
/// throws an invalid argument out of range exception and returns the out of range index,
5660
/// a text description of the range, and the bound of the range
5761
/// e.g. sourceIndex = -4, source axis-0 lower bound = 0"
5862
let invalidArgOutOfRange (arg:string) (index:int) (text:string) (bound:int) =
59-
invalidArgFmt arg
63+
invalidArgOutOfRangeFmt arg
6064
"{0}\n{1} = {2}, {3} = {4}"
6165
[|SR.GetString SR.outOfRange; arg; index; text; bound|]
6266

tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ printfn "Hello from F#"
10131013
checkFile "As 01" expectTwoWarnings
10141014
}
10151015

1016-
[<Fact>]
1016+
[<Fact(Skip="Flaky. See https://github.com/dotnet/fsharp/issues/16766")>]
10171017
let ``Transparent Compiler ScriptClosure cache is populated after GetProjectOptionsFromScript`` () =
10181018
async {
10191019
let transparentChecker = FSharpChecker.Create(useTransparentCompiler = true)

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ type ArrayModule() =
372372
CheckThrowsArgumentNullException (fun () -> Array.blit nullArr 1 strDes 2 3 |> ignore)
373373

374374
// bounds check
375-
CheckThrowsArgumentException (fun () -> Array.blit intSrc -1 intDes 1 3 |> ignore)
376-
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes -1 3 |> ignore)
377-
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 1 -3 |> ignore)
375+
CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc -1 intDes 1 3 |> ignore)
376+
CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc 1 intDes -1 3 |> ignore)
377+
CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc 1 intDes 1 -3 |> ignore)
378378
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 1 300 |> ignore)
379379
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 5 8 |> ignore)
380380

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type SeqModule() =
141141
Assert.AreEqual(null, Seq.head <| Seq.replicate 1 null)
142142
Assert.AreEqual(["1";"1"],Seq.replicate 2 "1" |> Seq.toList)
143143

144-
CheckThrowsArgumentException (fun () -> Seq.replicate -1 null |> ignore)
144+
CheckThrowsArgumentOutOfRangeException (fun () -> Seq.replicate -1 null |> ignore)
145145

146146

147147
[<Fact>]

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ type FSharpValueTests() =
221221

222222
// invalid type
223223
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(1) |> ignore)
224-
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields( () ) |> ignore)
224+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetExceptionFields( () ) |> ignore)
225225

226226
// System Exception
227227
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(new System.Exception("ex message")) |> ignore)
228228

229229
// null
230-
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(null) |> ignore)
230+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetExceptionFields(null) |> ignore)
231231

232232
[<Fact>]
233233
member _.GetRecordField() =
@@ -241,15 +241,15 @@ type FSharpValueTests() =
241241
Assert.AreEqual((FSharpValue.GetRecordField(genericRecordType1, propertyinfo2)), 1)
242242

243243
// null value
244-
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
245-
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)
244+
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
245+
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)
246246

247247
// invalid value
248248
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfo1) |> ignore)
249249

250250
// invalid property info
251-
let propertyinfoint = (typeof<RecordType>).GetProperty("fieldstring")
252-
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore)
251+
let propertyinfoint = (typeof<RecordType>).GetProperty("fieldstring") // null
252+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore)
253253

254254
[<Fact>]
255255
member _.GetStructRecordField() =
@@ -259,15 +259,15 @@ type FSharpValueTests() =
259259
Assert.AreEqual((FSharpValue.GetRecordField(structRecord1, propertyinfo1)), "field1")
260260

261261
// null value
262-
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
263-
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)
262+
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
263+
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)
264264

265265
// invalid value
266266
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfo1) |> ignore)
267267

268268
// invalid property info
269-
let propertyinfoint = (typeof<StructRecordType>).GetProperty("fieldstring")
270-
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore)
269+
let propertyinfoint = (typeof<StructRecordType>).GetProperty("fieldstring") // null
270+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore)
271271

272272
[<Fact>]
273273
member _.GetRecordFields() =
@@ -280,8 +280,8 @@ type FSharpValueTests() =
280280
Assert.AreEqual((FSharpValue.GetRecordFields(genericRecordType1)).[0], "field1")
281281

282282
// null value
283-
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields(null)|> ignore)
284-
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields( () )|> ignore)
283+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordFields(null)|> ignore)
284+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordFields( () )|> ignore)
285285

286286
// invalid value
287287
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields("invalid") |> ignore)
@@ -300,8 +300,8 @@ type FSharpValueTests() =
300300
Assert.AreEqual( FSharpValue.GetTupleField(tuple2, 1), "tuple2")
301301

302302
// null value
303-
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField(null, 3)|> ignore)
304-
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField( () , 3)|> ignore)
303+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleField(null, 3)|> ignore)
304+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleField( () , 3)|> ignore)
305305

306306
// invalid value
307307
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField("Invalid", 3)|> ignore)
@@ -329,8 +329,8 @@ type FSharpValueTests() =
329329
Assert.AreEqual( (FSharpValue.GetTupleFields(tuple2)).[1], "tuple2")
330330

331331
// null value
332-
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields(null)|> ignore)
333-
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields( () )|> ignore)
332+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleFields(null)|> ignore)
333+
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleFields( () )|> ignore)
334334

335335
// invalid value
336336
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields("Invalid")|> ignore)
@@ -393,7 +393,7 @@ type FSharpValueTests() =
393393
Assert.AreEqual(FSharpValue.GetRecordFields(makeRecordGeneric).[0], "field1")
394394

395395
// null value
396-
CheckThrowsArgumentException(fun () ->FSharpValue.MakeRecord(null, null)|> ignore)
396+
CheckThrowsArgumentNullException(fun () ->FSharpValue.MakeRecord(null, null)|> ignore)
397397

398398
// invalid value
399399
CheckThrowsArgumentException(fun () -> FSharpValue.MakeRecord(typeof<GenericRecordType<string, int>>, [| box 1; box("invalid param"); box("invalid param") |])|> ignore)
@@ -471,7 +471,7 @@ type FSharpValueTests() =
471471
Assert.AreEqual( (unbox<GenericRecordType<string, int>>(resultGenericRecordType)).field1, genericRecordType1.field1)
472472

473473
// null value
474-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordConstructor(null)|> ignore)
474+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordConstructor(null)|> ignore)
475475

476476
// invalid value
477477
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordConstructor(typeof<DiscUnionType<string>>) |> ignore)
@@ -495,7 +495,7 @@ type FSharpValueTests() =
495495
Assert.AreEqual(genericrecordCtorInfo.ReflectedType, typeof<GenericRecordType<string, int>>)
496496

497497
// null value
498-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordConstructorInfo(null)|> ignore)
498+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordConstructorInfo(null)|> ignore)
499499

500500
// invalid value
501501
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordConstructorInfo(typeof<DiscUnionType<string>>) |> ignore)
@@ -517,7 +517,7 @@ type FSharpValueTests() =
517517
Assert.AreEqual(recordFieldReader(genericRecordType1), box("field1"))
518518

519519
// null value
520-
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordFieldReader(null)|> ignore)
520+
CheckThrowsArgumentNullException(fun () -> FSharpValue.PreComputeRecordFieldReader(null)|> ignore)
521521

522522
[<Fact>]
523523
member _.PreComputeStructRecordFieldReader() =
@@ -536,7 +536,7 @@ type FSharpValueTests() =
536536
Assert.AreEqual( (genericrecordReader(genericRecordType1)).[0], "field1")
537537

538538
// null value
539-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordReader(null)|> ignore)
539+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordReader(null)|> ignore)
540540

541541
// invalid value
542542
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordReader(typeof<DiscUnionType<string>>) |> ignore)
@@ -566,7 +566,7 @@ type FSharpValueTests() =
566566
Assert.AreEqual( tupleNestedCtor([| box 1; box(2, "tuple") |] ), box(tuple3))
567567

568568
// null value
569-
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructor(null)|> ignore)
569+
CheckThrowsArgumentNullException(fun () -> FSharpValue.PreComputeTupleConstructor(null)|> ignore)
570570

571571
// invalid value
572572
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructor(typeof<DiscUnionType<string>>) |> ignore)
@@ -604,7 +604,7 @@ type FSharpValueTests() =
604604
Assert.AreEqual(nestedTupleCtorInfo.ReflectedType, typeof<Tuple<int, Tuple<int, string>>>)
605605

606606
// null value
607-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTupleConstructorInfo(null)|> ignore)
607+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTupleConstructorInfo(null)|> ignore)
608608

609609
// invalid value
610610
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructorInfo(typeof<RecordType>) |> ignore)
@@ -634,7 +634,7 @@ type FSharpValueTests() =
634634
Assert.AreEqual(tupleNestedPropInfo.PropertyType, typeof<Tuple<int, string>>)
635635

636636
// null value
637-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTuplePropertyInfo(null, 0)|> ignore)
637+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTuplePropertyInfo(null, 0)|> ignore)
638638

639639
// invalid value
640640
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTuplePropertyInfo(typeof<RecordType>, 0) |> ignore)
@@ -670,7 +670,7 @@ type FSharpValueTests() =
670670
Assert.AreEqual (longTupleReader longTuple, [| box ("yup", 1s); box 2; box 3; box 4; box 5; box 6; box 7; box 8; box 9; box 10; box 11; box (Some 12); box 13; box "nope"; box (struct (15, 16)); box 17; box 18; box (ValueSome 19) |])
671671

672672
// null value
673-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTupleReader(null)|> ignore)
673+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTupleReader(null)|> ignore)
674674

675675
// invalid value
676676
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleReader(typeof<RecordType>) |> ignore)
@@ -813,7 +813,7 @@ type FSharpValueTests() =
813813
Assert.AreEqual(discUnionMemberInfo.ReflectedType, typeof<DiscUnionType<int>>)
814814

815815
// null value
816-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeUnionTagMemberInfo(null)|> ignore)
816+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeUnionTagMemberInfo(null)|> ignore)
817817

818818
// invalid value
819819
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeUnionTagMemberInfo(typeof<RecordType>) |> ignore)
@@ -851,7 +851,7 @@ type FSharpValueTests() =
851851
Assert.AreEqual(voptionTagReader(box(voptionNone)), 0)
852852

853853
// null value
854-
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeUnionTagReader(null)|> ignore)
854+
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeUnionTagReader(null)|> ignore)
855855

856856
// invalid value
857857
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeUnionTagReader(typeof<RecordType>) |> ignore)
@@ -1179,7 +1179,7 @@ type FSharpTypeTests() =
11791179

11801180
// invalid cases
11811181
CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( [|null;null|]) |> ignore )
1182-
CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( null) |> ignore )
1182+
CheckThrowsArgumentNullException(fun () ->FSharpType.MakeStructTupleType( null) |> ignore )
11831183
CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( [| |]) |> ignore )
11841184

11851185
type UnionCaseInfoTests() =

0 commit comments

Comments
 (0)