Skip to content

Commit 6e86a6b

Browse files
committed
Merge pull request #463 from Jand42/master
Exposing slot signature of members in object expressions
2 parents 839bab6 + 6144b47 commit 6e86a6b

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/fsharp/vs/Exprs.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ type E =
108108
| ILAsm of string * FSharpType list * FSharpExpr list
109109

110110
/// Used to represent the information at an object expression member
111-
and [<Sealed>] FSharpObjectExprOverride(gps: FSharpGenericParameter list, args:FSharpMemberFunctionOrValue list list, body: FSharpExpr) =
111+
and [<Sealed>] FSharpObjectExprOverride(sgn: FSharpAbstractSignature, gps: FSharpGenericParameter list, args:FSharpMemberFunctionOrValue list list, body: FSharpExpr) =
112+
member __.Signature = sgn
112113
member __.GenericParameters = gps
113114
member __.CurriedParameterGroups = args
114115
member __.Body = body
@@ -444,13 +445,14 @@ module FSharpExprConvert =
444445
| Expr.Obj (_lambdaId,typ,_basev,basecall,overrides, iimpls,_m) ->
445446
let basecallR = ConvExpr cenv env basecall
446447
let ConvertMethods methods =
447-
[ for (TObjExprMethod(_slotsig,_,tps,tmvs,body,_)) in methods ->
448+
[ for (TObjExprMethod(slotsig,_,tps,tmvs,body,_)) in methods ->
448449
let vslR = List.map (List.map (ConvVal cenv)) tmvs
450+
let sgn = FSharpAbstractSignature(cenv, slotsig)
449451
let tpsR = [ for tp in tps -> FSharpGenericParameter(cenv,tp) ]
450452
let env = ExprTranslationEnv.Empty.BindTypars (Seq.zip tps tpsR |> Seq.toList)
451453
let env = env.BindCurriedVals tmvs
452454
let bodyR = ConvExpr cenv env body
453-
FSharpObjectExprOverride(tpsR, vslR, bodyR) ]
455+
FSharpObjectExprOverride(sgn, tpsR, vslR, bodyR) ]
454456
let overridesR = ConvertMethods overrides
455457
let iimplsR = List.map (fun (ty,impls) -> ConvType cenv ty, ConvertMethods impls) iimpls
456458

src/fsharp/vs/Exprs.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ and [<Sealed>] FSharpExpr =
5656

5757
/// Represents a checked method in an object expression, as seen by the F# language.
5858
and [<Sealed>] FSharpObjectExprOverride =
59+
/// The signature of the implemented abstract slot
60+
member Signature : FSharpAbstractSignature
5961
/// The generic parameters of the method
6062
member GenericParameters : FSharpGenericParameter list
6163
/// The parameters of the method

src/fsharp/vs/Symbols.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ and [<Class>] FSharpAbstractParameter =
312312

313313
/// Represents the signature of an abstract slot of a class or interface
314314
and [<Class>] FSharpAbstractSignature =
315+
internal new : Impl.cenv * SlotSig -> FSharpAbstractSignature
315316

316317
/// Get the arguments of the abstract slot
317318
member AbstractArguments : IList<IList<FSharpAbstractParameter>>

tests/service/ExprTests.fs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module Utils =
6464
| BasicPatterns.UnionCaseGet(obj,ty,uc,f1) -> printExpr 10 obj + "." + f1.Name
6565
| BasicPatterns.UnionCaseTest(obj,ty,f1) -> printExpr 10 obj + ".Is" + f1.Name
6666
| BasicPatterns.UnionCaseTag(obj,ty) -> printExpr 10 obj + ".Tag"
67-
| BasicPatterns.ObjectExpr(ty,basecall,overrides,iimpls) -> "{ new " + printTy ty + " with ... }"
67+
| BasicPatterns.ObjectExpr(ty,basecall,overrides,iimpls) -> "{ " + printExpr 10 basecall + " with " + printOverrides overrides + " " + printIimpls iimpls + " }"
6868
| BasicPatterns.TraitCall(tys,nm,argtys,tinst,args) -> "trait call " + nm + printTupledArgs args
6969
| BasicPatterns.Const(obj,ty) ->
7070
match obj with
@@ -84,7 +84,14 @@ module Utils =
8484
and printCurriedParams (vs: FSharpMemberOrFunctionOrValue list list) = String.concat " " (List.map printParams vs)
8585
and printTy ty = ty.Format(FSharpDisplayContext.Empty)
8686
and printTyargs tyargs = match tyargs with [] -> "" | args -> "<" + String.concat "," (List.map printTy tyargs) + ">"
87-
87+
and printOverrides ors = String.concat ";" (List.map printOverride ors)
88+
and printOverride o =
89+
match o.CurriedParameterGroups with
90+
| [t] :: a ->
91+
"member " + t.CompiledName + "." + o.Signature.Name + printCurriedParams a + " = " + printExpr 10 o.Body
92+
| _ -> failwith "wrong this argument in object expression override"
93+
and printIimpls iis = String.concat ";" (List.map printImlementation iis)
94+
and printImlementation (i, ors) = "interface " + printTy i + " with " + printOverrides ors
8895

8996
let rec printDeclaration (excludes:HashSet<_> option) (d: FSharpImplementationFileDeclaration) =
9097
seq {
@@ -428,8 +435,8 @@ let ``Test Declarations project1`` () =
428435
"member Method(x) (a,b) = 1 @ (106,37--106,38)";
429436
"member CurriedMethod(x) (a1,b1) (a2,b2) = 1 @ (107,63--107,64)";
430437
"let testFunctionThatCallsMultiArgMethods(unitVar0) = let m: M.MultiArgMethods = new MultiArgMethods(3,4) in Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (m.Method(7,8),fun tupledArg -> let arg00: Microsoft.FSharp.Core.int = tupledArg.Item0 in let arg01: Microsoft.FSharp.Core.int = tupledArg.Item1 in fun tupledArg -> let arg10: Microsoft.FSharp.Core.int = tupledArg.Item0 in let arg11: Microsoft.FSharp.Core.int = tupledArg.Item1 in m.CurriedMethod(arg00,arg01,arg10,arg11) (9,10) (11,12)) @ (110,8--110,9)";
431-
"let functionThatUsesObjectExpression(unitVar0) = { new Microsoft.FSharp.Core.obj with ... } @ (114,3--114,55)";
432-
"let functionThatUsesObjectExpressionWithInterfaceImpl(unitVar0) = { new Microsoft.FSharp.Core.obj with ... } :> System.IComparable @ (117,3--120,38)";
438+
"let functionThatUsesObjectExpression(unitVar0) = { Object..ctor () with member x.ToString(unitVar1) = Operators.ToString<Microsoft.FSharp.Core.int> (888) } @ (114,3--114,55)";
439+
"let functionThatUsesObjectExpressionWithInterfaceImpl(unitVar0) = { Object..ctor () with member x.ToString(unitVar1) = Operators.ToString<Microsoft.FSharp.Core.int> (888) interface System.IComparable with member x.CompareTo(y) = 0 } :> System.IComparable @ (117,3--120,38)";
433440
"let testFunctionThatUsesUnitsOfMeasure(x) (y) = Operators.op_Addition<Microsoft.FSharp.Core.float<'u>,Microsoft.FSharp.Core.float<'u>,Microsoft.FSharp.Core.float<'u>> (x,y) @ (122,70--122,75)";
434441
"let testFunctionThatUsesAddressesAndByrefs(x) = let mutable w: Microsoft.FSharp.Core.int = 4 in let y1: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = x in let y2: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = &w in let arr: Microsoft.FSharp.Core.int Microsoft.FSharp.Core.[] = [| ... |] in let r: Microsoft.FSharp.Core.int Microsoft.FSharp.Core.ref = Operators.Ref<Microsoft.FSharp.Core.int> (3) in let y3: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = [I_ldelema (NormalAddress,false,ILArrayShape [(Some 0, null)],TypeVar 0us)](arr,0) in let y4: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = &r.contents in let z: Microsoft.FSharp.Core.int = Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (x,y1),y2),y3) in (w <- 3; (x <- 4; (y2 <- 4; (y3 <- 5; Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (z,x),y1),y2),y3),y4),IntrinsicFunctions.GetArray<Microsoft.FSharp.Core.int> (arr,0)),r.contents))))) @ (125,16--125,17)";
435442
"let testFunctionThatUsesStructs1(dt) = dt.AddDays(3) @ (139,57--139,72)";

0 commit comments

Comments
 (0)