Skip to content

Commit cba2ff7

Browse files
eiriktsarpalisbaronfel
authored andcommitted
Add Expr.NewStructTuple constructor and active pattern (#8193)
* add Expr.NewStructTuple constructor and active pattern * update surface areas
1 parent d2b59ed commit cba2ff7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/fsharp/FSharp.Core/quotations.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ module Patterns =
391391
[<CompiledName("NewTuplePattern")>]
392392
let (|NewTuple|_|) input = match input with E(CombTerm(NewTupleOp(_), es)) -> Some es | _ -> None
393393

394+
[<CompiledName("NewStructTuplePattern")>]
395+
let (|NewStructTuple|_|) input = match input with E(CombTerm(NewTupleOp(ty), es)) when ty.IsValueType -> Some es | _ -> None
396+
394397
[<CompiledName("DefaultValuePattern")>]
395398
let (|DefaultValue|_|) input = match input with E(CombTerm(DefaultValueOp ty, [])) -> Some ty | _ -> None
396399

@@ -747,6 +750,10 @@ module Patterns =
747750
let ty = FSharpType.MakeTupleType(Array.map typeOf (Array.ofList args))
748751
mkFEN (NewTupleOp ty) args
749752

753+
let mkNewStructTuple (asm, args) =
754+
let ty = FSharpType.MakeStructTupleType(asm, Array.map typeOf (Array.ofList args))
755+
mkFEN (NewTupleOp ty) args
756+
750757
let mkTupleGet (ty, n, x) =
751758
checkTypesSR ty (typeOf x) "tupleGet" (SR.GetString(SR.QtmmExprNotMatchTuple))
752759
let mems = FSharpType.GetTupleElements ty
@@ -1820,6 +1827,9 @@ type Expr with
18201827
static member NewTuple elements =
18211828
mkNewTuple elements
18221829

1830+
static member NewStructTuple (asm:Assembly, elements) =
1831+
mkNewStructTuple (asm, elements)
1832+
18231833
static member NewRecord (recordType:Type, elements) =
18241834
checkNonNull "recordType" recordType
18251835
mkNewRecord (recordType, elements)

src/fsharp/FSharp.Core/quotations.fsi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ type Expr =
181181
/// <returns>The resulting expression.</returns>
182182
static member NewTuple: elements:Expr list -> Expr
183183

184+
/// <summary>Builds an expression that represents the creation of an F# tuple value</summary>
185+
/// <param name="asm">Runtime assembly containing System.ValueTuple definitions.</param>
186+
/// <param name="elements">The list of elements of the tuple.</param>
187+
/// <returns>The resulting expression.</returns>
188+
static member NewStructTuple: asm:Assembly * elements:Expr list -> Expr
189+
184190
/// <summary>Builds record-construction expressions </summary>
185191
/// <param name="recordType">The type of record.</param>
186192
/// <param name="elements">The list of elements of the record.</param>
@@ -545,6 +551,12 @@ module Patterns =
545551
[<CompiledName("NewTuplePattern")>]
546552
val (|NewTuple|_|) : input:Expr -> (Expr list) option
547553

554+
/// <summary>An active pattern to recognize expressions that represent construction of struct tuple values</summary>
555+
/// <param name="input">The input expression to match against.</param>
556+
/// <returns>(Expr list) option</returns>
557+
[<CompiledName("NewStructTuplePattern")>]
558+
val (|NewStructTuple|_|) : input:Expr -> (Expr list) option
559+
548560
/// <summary>An active pattern to recognize expressions that represent the read of a static or instance property, or a non-function value declared in a module</summary>
549561
/// <param name="input">The input expression to match against.</param>
550562
/// <returns>(Expr option * PropertyInfo * Expr list) option</returns>

src/fsharp/FSharp.Core/reflect.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,13 @@ type FSharpType =
314314
static member MakeTupleType: types:Type[] -> Type
315315

316316
/// <summary>Returns a <c>System.Type</c> representing an F# tuple type with the given element types</summary>
317+
/// <param name="asm">Runtime assembly containing System.Tuple definitions.</param>
317318
/// <param name="types">An array of types for the tuple elements.</param>
318319
/// <returns>The type representing the tuple containing the input elements.</returns>
319320
static member MakeTupleType: asm:Assembly * types:Type[] -> Type
320321

321322
/// <summary>Returns a <c>System.Type</c> representing an F# struct tuple type with the given element types</summary>
323+
/// <param name="asm">Runtime assembly containing System.ValueTuple definitions.</param>
322324
/// <param name="types">An array of types for the tuple elements.</param>
323325
/// <returns>The type representing the struct tuple containing the input elements.</returns>
324326
static member MakeStructTupleType: asm:Assembly * types:Type[] -> Type

0 commit comments

Comments
 (0)