Skip to content

Commit 03511ed

Browse files
committed
fix recognizing get_Tag from IL, add test
1 parent 26725b2 commit 03511ed

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/fsharp/vs/Exprs.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ module FSharpExprConvert =
778778
else
779779
failwith "Failed to recognize record type member"
780780
elif enclosingEntity.IsUnionTycon then
781-
if vName = "GetTag" then
781+
if vName = "GetTag" || vName = "get_Tag" then
782782
let objR = ConvExpr cenv env callArgs.Head
783783
E.UnionCaseTag(objR, typR)
784784
elif vName.StartsWith("New") then

tests/service/ExprTests.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ let ``Check use of type provider that provides calls to F# code`` () =
877877
for line in d |> printDeclaration None do
878878
yield line ]
879879

880+
results |> List.iter (printfn "%s")
881+
880882
results |> shouldEqual
881883
["type TestProject"; "type AssemblyInfo"; "type TestProject"; "type T";
882884
"""type Class1""";
@@ -896,6 +898,7 @@ let ``Check use of type provider that provides calls to F# code`` () =
896898
"""member get_X13(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in G`1<Microsoft.FSharp.Core.int>.DoNothingOneArg (3) @ (18,22--18,55)"""
897899
"""member get_X14(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in G`1<Microsoft.FSharp.Core.int>.DoNothingTwoArg (new C(),3) @ (19,22--19,55)"""
898900
"""member get_X15(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in let matchValue: Microsoft.FSharp.Core.Option<Microsoft.FSharp.Core.int> = FSharpOption`1<Microsoft.FSharp.Core.int>.Some (1) in (if Operators.op_Equality<Microsoft.FSharp.Core.int> (matchValue.Tag,1) then let x: Microsoft.FSharp.Core.int = matchValue.get_Value() in x else 0) @ (20,22--20,54)"""
901+
"""member get_X16(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in let matchValue: Microsoft.FSharp.Core.Choice<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.obj> = Choice1Of2(1) in (if Operators.op_Equality<Microsoft.FSharp.Core.int> (matchValue.Tag,0) then 1 else 0) @ (21,22--21,54)"""
899902
"""member get_X17(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in let r: TestTP.Helper.R = {A = 1; B = 0} in (r.B <- 1; r.A) @ (22,22--22,60)"""
900903
"""member get_X18(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in Helper.doNothingTwoArg (3,4) @ (23,22--23,43)"""
901904
"""member get_X19(this) (unitVar1) = let this: Microsoft.FSharp.Core.obj = ("My internal state" :> Microsoft.FSharp.Core.obj) :> ErasedWithConstructor.Provided.MyType in Helper.doNothingTwoArgCurried (3,4) @ (24,22--24,50)"""
@@ -926,6 +929,8 @@ let ``Check use of type provider that provides calls to F# code`` () =
926929
let members =
927930
[ for f in res.AssemblyContents.ImplementationFiles do yield! printMembersOfDeclatations f.Declarations ]
928931

932+
members |> List.iter (printfn "%s")
933+
929934
members |> shouldEqual
930935
[
931936
".ctor: Microsoft.FSharp.Core.unit -> TestProject.Class1"
@@ -972,6 +977,9 @@ let ``Check use of type provider that provides calls to F# code`` () =
972977
"matchValue: Microsoft.FSharp.Core.Option<Microsoft.FSharp.Core.int>"
973978
"get_Value: Microsoft.FSharp.Core.unit -> 'T"
974979
"x: Microsoft.FSharp.Core.int"
980+
"get_X16: TestProject.Class1 -> Microsoft.FSharp.Core.unit -> Microsoft.FSharp.Core.int"
981+
"op_Equality<'T when 'T : equality>: 'T -> 'T -> Microsoft.FSharp.Core.bool"
982+
"matchValue: Microsoft.FSharp.Core.Choice<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.obj>"
975983
"get_X17: TestProject.Class1 -> Microsoft.FSharp.Core.unit -> Microsoft.FSharp.Core.int"
976984
"r: TestTP.Helper.R"
977985
"r: TestTP.Helper.R"

tests/service/data/TestProject/Library.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Class1() =
1818
member this.X13 = T().GenericClassDoNothingOneArg()
1919
member this.X14 = T().GenericClassDoNothingTwoArg()
2020
member this.X15 = T().OptionConstructionAndMatch()
21-
// member this.X16 = T().ChoiceConstructionAndMatch()
21+
member this.X16 = T().ChoiceConstructionAndMatch()
2222
member this.X17 = T().RecordConstructionAndFieldGetSet()
2323
member this.X18 = T().DoNothingTwoArg()
2424
member this.X19 = T().DoNothingTwoArgCurried()

tests/service/data/TestTP/Library.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ type BasicProvider (config : TypeProviderConfig) as this =
225225
myType.AddMember(someMethod)
226226

227227
let someMethod = ProvidedMethod("ChoiceConstructionAndMatch", [], typeof<int>,
228-
InvokeCode = fun args -> <@@ match Choice1Of2 1 with Choice2Of2 _ -> 0 | Choice1Of2 x -> x @@>)
228+
InvokeCode = fun args -> <@@ match Choice1Of2 1 with Choice2Of2 _ -> 0 | Choice1Of2 _ -> 1 @@>)
229+
// TODO: fix type checker to recognize union generated subclasses coming from TPs
230+
// InvokeCode = fun args -> <@@ match Choice1Of2 1 with Choice2Of2 _ -> 0 | Choice1Of2 x -> x @@>)
229231
myType.AddMember(someMethod)
230232

231233
let someMethod = ProvidedMethod("RecordConstructionAndFieldGetSet", [], typeof<int>,

0 commit comments

Comments
 (0)