Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@

* Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816))
* Error on invalid declarations in type definitions.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813))
* Fix type erasure logic for `nativeptr<'T>` overloads to properly preserve element type differences during duplicate member checking. ([Issue #<ISSUE_NUMBER>](https://github.com/dotnet/fsharp/issues/<ISSUE_NUMBER>), [PR #<PR_NUMBER>](https://github.com/dotnet/fsharp/pull/<PR_NUMBER>))

### Changed
3 changes: 2 additions & 1 deletion src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ let rec stripTyEqnsAndErase eraseFuncAndTuple (g: TcGlobals) ty =
let reducedTy2 = addNullnessToTy nullness reducedTy
stripTyEqnsAndErase eraseFuncAndTuple g reducedTy2
elif tyconRefEq g tcref g.nativeptr_tcr && eraseFuncAndTuple then
stripTyEqnsAndErase eraseFuncAndTuple g g.nativeint_ty
// Regression fix (issue #<ISSUE_NUMBER>): nativeptr<'T> erases to ilsigptr<'T>, not nativeint
stripTyEqnsAndErase eraseFuncAndTuple g (TType_app(g.ilsigptr_tcr, args, nullness))
else
ty

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module NativePtrOverloads01
open Microsoft.FSharp.NativeInterop
#nowarn "9"

type P =
static member Do(p: nativeptr<int>) = 1
static member Do(p: nativeptr<int64>) = 2

let _invoke (pi: nativeptr<int>) (pl: nativeptr<int64>) = P.Do pi + P.Do pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module NativePtrOverloads02
open Microsoft.FSharp.NativeInterop
#nowarn "9"

type Q =
static member M(p: nativeptr<int>) = 0
static member M(p: nativeptr<int>) = 1 // expect duplicate member error
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module NativePtrOverloads03
open Microsoft.FSharp.NativeInterop
#nowarn "9"
// Regression test for issue #<ISSUE_NUMBER>

type R =
static member F(p: nativeptr<uint16>) = 0us
static member F(p: nativeptr<int64>) = 0L
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module NativePtrOverloads04
open Microsoft.FSharp.NativeInterop
#nowarn "9"
[<Measure>] type kg
[<Measure>] type m

type S =
static member H(p: nativeptr<int<kg>>) = 1
static member H(p: nativeptr<int<m>>) = 2 // expect duplicate member error
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,49 @@ module MemberDefinitions_OverloadingMembers =
compilation
|> verifyCompileAndRun
|> shouldSucceed

// Native pointer overload tests for regression fix

// NativePtrOverloads01.fs - distinct native pointer element types should compile
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NativePtrOverloads01.fs"|])>]
let ``NativePtrOverloads01_fs`` compilation =
compilation
|> asLibrary
|> withOptions ["--nowarn:9"]
|> compile
|> shouldSucceed

// NativePtrOverloads02.fs - duplicate exact signatures should fail
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NativePtrOverloads02.fs"|])>]
let ``NativePtrOverloads02_fs`` compilation =
compilation
|> asLibrary
|> withOptions ["--nowarn:9"]
|> compile
|> shouldFail
|> withDiagnostics [
(Error 438, Line 6, Col 19, Line 6, Col 20, "Duplicate method. The method 'M' has the same name and signature as another method in type 'Q'.")
(Error 438, Line 7, Col 19, Line 7, Col 20, "Duplicate method. The method 'M' has the same name and signature as another method in type 'Q'.")
]

// NativePtrOverloads03.fs - regression test, previously failing overloads should now compile
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NativePtrOverloads03.fs"|])>]
let ``NativePtrOverloads03_fs`` compilation =
compilation
|> asLibrary
|> withOptions ["--nowarn:9"]
|> compile
|> shouldSucceed

// NativePtrOverloads04.fs - erased differences via measures should still fail
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NativePtrOverloads04.fs"|])>]
let ``NativePtrOverloads04_fs`` compilation =
compilation
|> asLibrary
|> withOptions ["--nowarn:9"]
|> compile
|> shouldFail
|> withDiagnostics [
(Error 438, Line 8, Col 19, Line 8, Col 20, "Duplicate method. The method 'H' has the same name and signature as another method in type 'S' once tuples, functions, units of measure and/or provided types are erased.")
(Error 438, Line 9, Col 19, Line 9, Col 20, "Duplicate method. The method 'H' has the same name and signature as another method in type 'S' once tuples, functions, units of measure and/or provided types are erased.")
]
Loading