You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/FSharp.Compiler.ComponentTests/Language/FixedExpressionTests.fs
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -367,3 +367,45 @@ let pinIt (thing: RefField<'T>) =
367
367
(Warning 9, Line 11, Col 9, Line 11, Col 12,"""Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'.""")
368
368
(Warning 9, Line 12, Col 5, Line 12, Col 18,"""Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'.""")
369
369
]
370
+
371
+
[<Fact>]
372
+
let``Pin type with private method GetPinnableReference -illegal`` ()=
373
+
Fsx """
374
+
open Microsoft.FSharp.NativeInterop
375
+
376
+
type StrangeType<'T>(_value) =
377
+
let mutable _value = _value
378
+
member private this.GetPinnableReference() : byref<'T> = _value
379
+
380
+
let pinIt (thing: StrangeType<'T>) =
381
+
use ptr = fixed thing
382
+
NativePtr.get ptr 0
383
+
"""
384
+
|> ignoreWarnings
385
+
|> typecheck
386
+
|> shouldFail
387
+
|> withDiagnostics [
388
+
(Warning 9, Line 9, Col 9, Line 9, Col 12,"""Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'.""")
389
+
(Error 3207, Line 9, Col 9, Line 9, Col 12,"""Invalid use of 'fixed'. 'fixed' may only be used in a declaration of the form 'use x = fixed expr' where the expression is an array, the address of a field, the address of an array element or a string'""")
390
+
]
391
+
392
+
[<Fact>]
393
+
let``Pin type with static method GetPinnableReference -illegal`` ()=
394
+
Fsx """
395
+
open Microsoft.FSharp.NativeInterop
396
+
397
+
type StrangeType<'T>(_value) =
398
+
let mutable _value = _value
399
+
static member GetPinnableReference() : byref<'T> = Unchecked.defaultof<'T>
400
+
401
+
let pinIt (thing: StrangeType<'T>) =
402
+
use ptr = fixed thing
403
+
NativePtr.get ptr 0
404
+
"""
405
+
|> ignoreWarnings
406
+
|> typecheck
407
+
|> shouldFail
408
+
|> withDiagnostics [
409
+
(Warning 9, Line 9, Col 9, Line 9, Col 12,"""Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'.""")
410
+
(Error 3207, Line 9, Col 9, Line 9, Col 12,"""Invalid use of 'fixed'. 'fixed' may only be used in a declaration of the form 'use x = fixed expr' where the expression is an array, the address of a field, the address of an array element or a string'""")
0 commit comments