Skip to content

Commit b2e38f0

Browse files
committed
Add tests
1 parent 682384b commit b2e38f0

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Conformance.Expressions.CEExtensionMethodCapture
2+
3+
open Xunit
4+
open FSharp.Test.Compiler
5+
6+
[<Fact>]
7+
let ``Use binding doesn't capture an extension method with generic type``() =
8+
FSharp """
9+
open System
10+
open System.Runtime.CompilerServices
11+
12+
type FooClass() = class end
13+
14+
type Disposable() =
15+
interface IDisposable with
16+
member _.Dispose() = ()
17+
18+
[<Extension>]
19+
type PublicExtensions =
20+
[<Extension>]
21+
static member inline Dispose(this: #FooClass) =
22+
this
23+
24+
let foo() =
25+
use a = new Disposable()
26+
()
27+
28+
foo()
29+
"""
30+
|> asExe
31+
|> compile
32+
|> shouldSucceed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
module Conformance.Expressions.CEExtensionMethodCapture
2+
3+
open Xunit
4+
open FSharp.Test.Compiler
5+
6+
[<Fact>]
7+
let ``CE doesn't capture an extension method beyond the access domain``() =
8+
FSharp """
9+
open System.Runtime.CompilerServices
10+
11+
type AsyncSeq<'T>(i: 'T) =
12+
class
13+
let l = [i]
14+
member this.Data = l
15+
end
16+
17+
type AsyncSeqBuilder() =
18+
member _.Yield(x: 'T) : AsyncSeq<'T> =
19+
AsyncSeq(x)
20+
21+
[<Extension>]
22+
type PrivateExtensions =
23+
[<Extension>]
24+
static member inline private Run(this: AsyncSeqBuilder) =
25+
this
26+
27+
let asyncSeq = AsyncSeqBuilder()
28+
29+
let xs : AsyncSeq<int> =
30+
asyncSeq {
31+
yield 1
32+
}
33+
"""
34+
|> asExe
35+
|> compile
36+
|> shouldSucceed
37+
38+
[<Fact>]
39+
let ``CE doesn't capture an extension method with generic type``() =
40+
FSharp """
41+
open System.Runtime.CompilerServices
42+
43+
type FooClass = class end
44+
45+
type AsyncSeq<'T>(i: 'T) =
46+
class
47+
let l = [i]
48+
member this.Data = l
49+
end
50+
51+
type AsyncSeqBuilder() =
52+
member _.Yield(x: 'T) : AsyncSeq<'T> =
53+
AsyncSeq(x)
54+
55+
[<Extension>]
56+
type PrivateExtensions =
57+
[<Extension>]
58+
static member inline Run(this: #FooClass) =
59+
this
60+
61+
let asyncSeq = AsyncSeqBuilder()
62+
63+
let xs : AsyncSeq<int> =
64+
asyncSeq {
65+
yield 1
66+
}
67+
"""
68+
|> asExe
69+
|> compile
70+
|> shouldSucceed
71+
72+
// Deliberately trigger an error to ensure that a method is captured
73+
[<Fact>]
74+
let ``CE captures a public extension method and procudes an error due to invalid args``() =
75+
FSharp """
76+
open System.Runtime.CompilerServices
77+
78+
type AsyncSeq<'T>(i: 'T) =
79+
class
80+
let l = [i]
81+
member this.Data = l
82+
end
83+
84+
type AsyncSeqBuilder() =
85+
member _.Yield(x: 'T) : AsyncSeq<'T> =
86+
AsyncSeq(x)
87+
88+
[<Extension>]
89+
type PublicExtensions =
90+
[<Extension>]
91+
static member inline Run(this: AsyncSeqBuilder, invalidArg: string) =
92+
this
93+
94+
let asyncSeq = AsyncSeqBuilder()
95+
96+
let xs : AsyncSeq<int> =
97+
asyncSeq {
98+
yield 1
99+
}
100+
"""
101+
|> asExe
102+
|> compile
103+
|> shouldFail

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Compile Include="Conformance\BasicGrammarElements\ValueRestriction\ValueRestriction.fs" />
7777
<Compile Include="Conformance\BasicGrammarElements\UseBindings\UseBindings.fs" />
7878
<Compile Include="Conformance\BasicGrammarElements\UseBindings\UseBangBindings.fs" />
79+
<Compile Include="Conformance\BasicGrammarElements\UseBindings\UseBindingsAndExtensionMembers.fs" />
7980
<Compile Include="Conformance\Constraints\Unmanaged.fs" />
8081
<Compile Include="Conformance\GeneratedEqualityHashingComparison\Attributes\Diags\Attributes_Diags.fs" />
8182
<Compile Include="Conformance\GeneratedEqualityHashingComparison\Attributes\Legacy\Attributes_Legacy.fs" />
@@ -85,6 +86,7 @@
8586
<Compile Include="Conformance\Expressions\ApplicationExpressions\Ctor.fs" />
8687
<Compile Include="Conformance\Expressions\BindingExpressions\BindingExpressions.fs" />
8788
<Compile Include="Conformance\Expressions\ComputationExpressions\ComputationExpressions.fs" />
89+
<Compile Include="Conformance\Expressions\ComputationExpressions\CEExtensionMethodCapture.fs" />
8890
<Compile Include="Conformance\Expressions\ObjectExpressions\ObjectExpressions.fs" />
8991
<Compile Include="Conformance\Expressions\ObjectExpressions\StructObjectExpression.fs" />
9092
<Compile Include="Conformance\Expressions\ControlFlowExpressions\PatternMatching\PatternMatching.fs" />

0 commit comments

Comments
 (0)