Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
61afb60
Initial plan
Copilot Sep 17, 2025
a675546
Implement nativeptr type erasure fix and add regression tests
Copilot Sep 17, 2025
45454cc
Add release notes for nativeptr type erasure fix
Copilot Sep 17, 2025
c80d185
Update tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarE…
T-Gro Sep 17, 2025
51a01bc
Update tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarE…
T-Gro Sep 17, 2025
852392b
Fix test expectations to match actual compiler behavior for duplicate…
Copilot Sep 18, 2025
8106b4b
Restore both error expectations for duplicate method tests
Copilot Sep 19, 2025
21a836c
Merge branch 'main' into copilot/fix-24b59ebb-af21-49f7-96cf-02e1313f…
T-Gro Sep 19, 2025
b880750
Fix test expectations to expect only second duplicate method error
Copilot Sep 19, 2025
03fa74b
Merge branch 'main' into copilot/fix-24b59ebb-af21-49f7-96cf-02e1313f…
T-Gro Sep 22, 2025
da6ba12
Restore expecting both duplicate method errors as reported by compiler
Copilot Sep 22, 2025
7952397
Merge branch 'main' into copilot/fix-24b59ebb-af21-49f7-96cf-02e1313f…
T-Gro Sep 30, 2025
6ddbcb9
Merge branch 'main' into copilot/fix-24b59ebb-af21-49f7-96cf-02e1313f…
T-Gro Oct 16, 2025
fd49e47
adjust tests
T-Gro Oct 16, 2025
661149d
Reflect older tests
T-Gro Oct 17, 2025
5a32006
Merge branch 'main' into copilot/fix-24b59ebb-af21-49f7-96cf-02e1313f…
T-Gro Oct 17, 2025
225c9a8
release notes
T-Gro Oct 17, 2025
40fe55f
Merge branch 'copilot/fix-24b59ebb-af21-49f7-96cf-02e1313f6ac1' of ht…
T-Gro Oct 17, 2025
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/.FSharp.Compiler.Service/11.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Scripts: Fix resolving the dotnet host path when an SDK directory is specified. ([PR #18960](https://github.com/dotnet/fsharp/pull/18960))
* Fix excessive StackGuard thread jumping ([PR #18971](https://github.com/dotnet/fsharp/pull/18971))
* Adjust conservative method-overload duplicate detection rules for nativeptr types ([PR #18911](https://github.com/dotnet/fsharp/pull/18911))
* Fix name is bound multiple times is not reported in 'as' pattern ([PR #18984](https://github.com/dotnet/fsharp/pull/18984))
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))

Expand Down
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 @@ -799,7 +799,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 7, Col 19, Line 7, Col 20, "Duplicate method. The method 'M' has the same name and signature as another method in type 'Q'.")
(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'.")
]

// 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 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.")
(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.")
]
8 changes: 0 additions & 8 deletions tests/fsharp/typecheck/sigs/neg23.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ neg23.fs(28,21,28,24): typecheck error FS0438: Duplicate method. The method 'Foo

neg23.fs(26,21,26,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same name and signature as another method in type 'DuplicateOverloadUpToErasure3.SomeClass'.

neg23.fs(55,21,55,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same name and signature as another method in type 'DuplicateOverloadUpToErasure6.SomeClass' once tuples, functions, units of measure and/or provided types are erased.

neg23.fs(53,21,53,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same name and signature as another method in type 'DuplicateOverloadUpToErasure6.SomeClass' once tuples, functions, units of measure and/or provided types are erased.

neg23.fs(64,21,64,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same name and signature as another method in type 'DuplicateOverloadUpToErasure7.SomeClass' once tuples, functions, units of measure and/or provided types are erased.

neg23.fs(62,21,62,24): typecheck error FS0438: Duplicate method. The method 'Foo' has the same name and signature as another method in type 'DuplicateOverloadUpToErasure7.SomeClass' once tuples, functions, units of measure and/or provided types are erased.

neg23.fs(76,9,76,11): typecheck error FS0410: The type 'IA' is less accessible than the value, member or type 'IB' it is used in.

neg23.fs(83,18,83,20): typecheck error FS0439: The method 'X0' has curried arguments but has the same name as another method in type 'TestCurriedMemberRestrictions.C'. Methods with curried arguments cannot be overloaded. Consider using a method taking tupled arguments.
Expand Down
8 changes: 4 additions & 4 deletions tests/fsharp/typecheck/sigs/neg23.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ module DuplicateOverloadUpToErasure5 = begin
member this.Foo (x:System.Tuple<int,int,int,int,int,int,System.Tuple<int>>) = printfn "method 2"
end

module DuplicateOverloadUpToErasure6 = begin

module NotAnyMoreDuplicateOverloadUpToErasure6 = begin
// This is not the same IL type, not a duplicate
type SomeClass() =

member this.Foo (x:nativeptr<int>) = printfn "method 1"

member this.Foo (x:nativeint) = printfn "method 2"
end

module DuplicateOverloadUpToErasure7 = begin

module NotAnyMoreDuplicateOverloadUpToErasure7 = begin
// This is not the same IL type, not a duplicate
type SomeClass() =

member this.Foo (x:(int*int)*int*(int*nativeptr<int>)*int*int) = printfn "method 1"
Expand Down
Loading