Skip to content

Commit ceeb6bc

Browse files
authored
Fix for issue #517 (#518)
This fixes two minor codegen bugs for generative type providers, as described in issue #517 . The 4 commits in this PR add a failing test for the first bug, fix the first bug to make the test pass, add a failing test for the second bug, and fix the second bug to make the test pass.
1 parent a54d92b commit ceeb6bc

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎src/ProvidedTypes.fs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14641,6 +14641,7 @@ namespace ProviderImplementation.ProvidedTypes
1464114641
| LessThan(None, [t1], [a1; a2]) ->
1464214642
emitExpr ExpectedStackState.Value a1
1464314643
emitExpr ExpectedStackState.Value a2
14644+
let t1 = if t1.IsEnum then t1.GetEnumUnderlyingType() else t1
1464414645
match t1 with
1464514646
| Bool | SByte | Char
1464614647
| Double | Single
@@ -14659,6 +14660,7 @@ namespace ProviderImplementation.ProvidedTypes
1465914660
| GreaterThan(None, [t1], [a1; a2]) ->
1466014661
emitExpr ExpectedStackState.Value a1
1466114662
emitExpr ExpectedStackState.Value a2
14663+
let t1 = if t1.IsEnum then t1.GetEnumUnderlyingType() else t1
1466214664
match t1 with
1466314665
| Bool | SByte | Char
1466414666
| Double | Single
@@ -14677,6 +14679,7 @@ namespace ProviderImplementation.ProvidedTypes
1467714679
| LessThanOrEqual(None, [t1], [a1; a2]) ->
1467814680
emitExpr ExpectedStackState.Value a1
1467914681
emitExpr ExpectedStackState.Value a2
14682+
let t1 = if t1.IsEnum then t1.GetEnumUnderlyingType() else t1
1468014683
match t1 with
1468114684
| Bool | SByte | Char
1468214685
| Int16 | Int32 | Int64 ->
@@ -14703,6 +14706,7 @@ namespace ProviderImplementation.ProvidedTypes
1470314706
| GreaterThanOrEqual(None, [t1], [a1; a2]) ->
1470414707
emitExpr ExpectedStackState.Value a1
1470514708
emitExpr ExpectedStackState.Value a2
14709+
let t1 = if t1.IsEnum then t1.GetEnumUnderlyingType() else t1
1470614710
match t1 with
1470714711
| Bool | SByte | Char
1470814712
| Int16 | Int32 | Int64 ->
@@ -14728,6 +14732,7 @@ namespace ProviderImplementation.ProvidedTypes
1472814732
| Equals(None, [t1], [a1; a2]) ->
1472914733
emitExpr ExpectedStackState.Value a1
1473014734
emitExpr ExpectedStackState.Value a2
14735+
let t1 = if t1.IsEnum then t1.GetEnumUnderlyingType() else t1
1473114736
match t1 with
1473214737
| Bool | SByte | Char
1473314738
| Double | Single
@@ -14743,6 +14748,7 @@ namespace ProviderImplementation.ProvidedTypes
1474314748
| NotEquals(None, [t1], [a1; a2]) ->
1474414749
emitExpr ExpectedStackState.Value a1
1474514750
emitExpr ExpectedStackState.Value a2
14751+
let t1 = if t1.IsEnum then t1.GetEnumUnderlyingType() else t1
1474614752
match t1 with
1474714753
| Bool | SByte | Char
1474814754
| Double | Single
@@ -16046,9 +16052,12 @@ namespace ProviderImplementation.ProvidedTypes
1604616052

1604716053
let methLocals = Dictionary<Var, ILLocalBuilder>()
1604816054

16049-
let expectedState = if (transType minfo.ReturnType = ILType.Void) then ExpectedStackState.Empty else ExpectedStackState.Value
16055+
let retType = transType minfo.ReturnType
16056+
let retUnit = retType = ILType.Void || retType.QualifiedName = (transType (convTypeToTgt typeof<unit>)).QualifiedName
16057+
let expectedState = if retUnit then ExpectedStackState.Empty else ExpectedStackState.Value
1605016058
let codeGen = CodeGenerator(assemblyMainModule, genUniqueTypeName, implicitCtorArgsAsFields, convTypeToTgt, transType, transFieldSpec, transMeth, transMethRef, transCtorSpec, ilg, methLocals, parameterVars)
1605116059
codeGen.EmitExpr (expectedState, expr)
16060+
if retUnit then ilg.Emit(I_ldnull)
1605216061
ilg.Emit I_ret
1605316062
| _ -> ()
1605416063

‎tests/GeneratedCodeTests.fs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,12 @@ let ``typeof``() =
182182
<@
183183
typeof<DateTime>.Name
184184
@> "DateTime"
185-
]
185+
]
186+
187+
[<Fact>]
188+
let ``try-finally with a unit-returning method``() =
189+
testProvidedAssembly
190+
[
191+
(<@@ try ResizeArray<int>().Clear() finally ResizeArray<int>().Clear() @@>),
192+
(fun _ -> ()) // just checking for InvalidProgramException
193+
]

‎tests/GeneratedOpTests.fs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,3 +1121,15 @@ let ``bitwise not execute correctly``() =
11211121
checkExpr <@ ~~~1234us @>
11221122
checkExpr <@ ~~~12uy @>
11231123
]
1124+
1125+
[<Fact>]
1126+
let ``equality on enums``() =
1127+
testProvidedAssembly
1128+
[
1129+
check <@ DateTimeKind.Utc = DateTimeKind.Local @> false
1130+
check <@ DateTimeKind.Utc <> DateTimeKind.Local @> true
1131+
check <@ DateTimeKind.Utc < DateTimeKind.Local @> true
1132+
check <@ DateTimeKind.Utc <= DateTimeKind.Local @> true
1133+
check <@ DateTimeKind.Utc > DateTimeKind.Local @> false
1134+
check <@ DateTimeKind.Utc >= DateTimeKind.Local @> false
1135+
]

0 commit comments

Comments
 (0)