Skip to content

Commit

Permalink
Merge pull request #17350 from dotnet/merges/main-to-release/dev17.11
Browse files Browse the repository at this point in the history
Merge main to release/dev17.11
  • Loading branch information
psfinaki authored Jun 27, 2024
2 parents 556819c + 281a2b0 commit b24f5df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/.FSharp.Core/8.0.400.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

* Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
* Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))

### Breaking Changes

* 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))
10 changes: 7 additions & 3 deletions src/FSharp.Core/local.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ module internal DetailedExceptions =
let msg = String.Format (format, paramArray)
raise (new ArgumentException (msg, arg))

/// takes an argument, a formatting string, a param array to splice into the formatting string
let inline invalidArgOutOfRangeFmt (arg:string) (format:string) paramArray =
let msg = String.Format (format, paramArray)
raise (new ArgumentOutOfRangeException (arg, msg))

/// takes a formatting string and a param array to splice into the formatting string
let inline invalidOpFmt (format:string) paramArray =
let msg = String.Format (format, paramArray)
Expand All @@ -38,7 +43,6 @@ module internal DetailedExceptions =
"{0}\nThe list was {1} {2} shorter than the index"
[|SR.GetString SR.notEnoughElements; index; (if index=1 then "element" else "elements")|]


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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ printfn "Hello from F#"
checkFile "As 01" expectTwoWarnings
}

[<Fact>]
[<Fact(Skip="Flaky. See https://github.com/dotnet/fsharp/issues/16766")>]
let ``Transparent Compiler ScriptClosure cache is populated after GetProjectOptionsFromScript`` () =
async {
let transparentChecker = FSharpChecker.Create(useTransparentCompiler = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ type ArrayModule() =
CheckThrowsArgumentNullException (fun () -> Array.blit nullArr 1 strDes 2 3 |> ignore)

// bounds check
CheckThrowsArgumentException (fun () -> Array.blit intSrc -1 intDes 1 3 |> ignore)
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes -1 3 |> ignore)
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 1 -3 |> ignore)
CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc -1 intDes 1 3 |> ignore)
CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc 1 intDes -1 3 |> ignore)
CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc 1 intDes 1 -3 |> ignore)
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 1 300 |> ignore)
CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 5 8 |> ignore)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type SeqModule() =
Assert.AreEqual(null, Seq.head <| Seq.replicate 1 null)
Assert.AreEqual(["1";"1"],Seq.replicate 2 "1" |> Seq.toList)

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


[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ type FSharpValueTests() =

// invalid type
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(1) |> ignore)
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields( () ) |> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetExceptionFields( () ) |> ignore)

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

// null
CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(null) |> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetExceptionFields(null) |> ignore)

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)

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

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

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore)

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

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

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

// null value
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields(null)|> ignore)
CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields( () )|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordFields(null)|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordFields( () )|> ignore)

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

// null value
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField(null, 3)|> ignore)
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField( () , 3)|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleField(null, 3)|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleField( () , 3)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields(null)|> ignore)
CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields( () )|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleFields(null)|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleFields( () )|> ignore)

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

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

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordConstructor(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordConstructor(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordConstructorInfo(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordConstructorInfo(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordFieldReader(null)|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.PreComputeRecordFieldReader(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordReader(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordReader(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructor(null)|> ignore)
CheckThrowsArgumentNullException(fun () -> FSharpValue.PreComputeTupleConstructor(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTupleConstructorInfo(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTupleConstructorInfo(null)|> ignore)

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

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

// invalid value
CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTuplePropertyInfo(typeof<RecordType>, 0) |> ignore)
Expand Down Expand Up @@ -670,7 +670,7 @@ type FSharpValueTests() =
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) |])

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTupleReader(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTupleReader(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeUnionTagMemberInfo(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeUnionTagMemberInfo(null)|> ignore)

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

// null value
CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeUnionTagReader(null)|> ignore)
CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeUnionTagReader(null)|> ignore)

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

// invalid cases
CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( [|null;null|]) |> ignore )
CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( null) |> ignore )
CheckThrowsArgumentNullException(fun () ->FSharpType.MakeStructTupleType( null) |> ignore )
CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( [| |]) |> ignore )

type UnionCaseInfoTests() =
Expand Down

0 comments on commit b24f5df

Please sign in to comment.