Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #3566 #3823

Merged
merged 1 commit into from
May 23, 2024
Merged
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 src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [JS/TS] Fixed TimeSpan.FromMilliseconds (#3815) (by @ncave)
* [Python] Fixed quotation for union string cases (by @dbrattli)
* [Python] Fixed casing issues with identifiers and reflection info (#3811) (by @dbrattli)
* [JS/TS/Python] Fixed interface static members (#3566) (by @ncave)

## 4.17.0 - 2024-04-23

Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ module Util =

// Check if this is an interface or abstract/overriden method
| _, Some entity when
entity.IsInterface
entity.IsInterface && memb.IsInstanceMember
|| memb.IsOverrideOrExplicitInterfaceImplementation
|| memb.IsDispatchSlot
->
Expand Down
10 changes: 9 additions & 1 deletion tests/Js/Main/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,12 @@ type IndexedProps(v: int) =
member _.Item with get (v2: int) = v + v2 and set v2 (s: string) = v <- v2 + int s
member _.Item with get (v2: float) = float v + v2 / 2.

[<Interface>]
type ITesting =
static member Testing x = x

type TypeWithByRefMember() =
static member DoubleIntByRef (x: byref<int>) : unit = x <- 2 * x
static member DoubleIntByRef (x: byref<int>) : unit = x <- 2 * x

let inline doubleIntByRef (x: ^a) (input: int) : int =
let mutable value = input
Expand Down Expand Up @@ -526,6 +530,10 @@ let tests =
f[4] |> equal 13
f[4.] |> equal 11

testCase "Static interface members work" <| fun () ->
let a = ITesting.Testing 5
a |> equal 5

testCase "Types can instantiate their parent in the constructor" <| fun () ->
let t = TestType9()
t.Greet("Maxime") |> equal "Hello Maxime"
Expand Down
22 changes: 22 additions & 0 deletions tests/Python/TestType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,15 @@
type ConcreteClass1() =
inherit MangledAbstractClass5(2)

type IndexedProps(v: int) =
let mutable v = v
member _.Item with get (v2: int) = v + v2 and set v2 (s: string) = v <- v2 + int s

Check warning on line 554 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.11)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 554 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.12)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 554 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (ubuntu-latest, 3.10)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 554 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.12)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 554 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.10)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.

Check warning on line 554 in tests/Python/TestType.fs

View workflow job for this annotation

GitHub Actions / build-python (windows-latest, 3.11)

An indexed property's getter and setter must have the same type. Property 'Item' has getter of type 'int' but setter of type 'string'.
member _.Item with get (v2: float) = float v + v2 / 2.

[<Interface>]
type ITesting =
static member Testing x = x

// TODO: This test produces different results in Fable and .NET
// See Fable.Transforms.FSharp2Fable.TypeHelpers.makeTypeGenArgs
// [<Fact>]
Expand All @@ -558,6 +567,19 @@
// |> fun fi -> fi.PropertyType.GetGenericArguments().Length
// |> equal 1

[<Fact>]
let ``test Indexed properties work`` () =
let f = IndexedProps(5)
f[4] |> equal 9
f[3] <- "6"
f[4] |> equal 13
f[4.] |> equal 11

[<Fact>]
let ``test Static interface members work`` () =
let a = ITesting.Testing 5
a |> equal 5

[<Fact>]
let ``test Types can instantiate their parent in the constructor`` () =
let t = Type9Test()
Expand Down
2 changes: 1 addition & 1 deletion tests/Rust/tests/src/ByRefTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let ``pass obj by ref using ByRef attr works`` () =
// TODO: See #3328

// type TypeWithByRefMember() =
// static member DoubleIntByRef (x: byref<int>) : unit = x <- 2 * x
// static member DoubleIntByRef (x: byref<int>) : unit = x <- 2 * x

// let inline doubleIntByRef (x: ^a) (input: int) : int =
// let mutable value = input
Expand Down
9 changes: 9 additions & 0 deletions tests/Rust/tests/src/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ type IndexedProps(v: int) =
member _.Item with get (v2: int) = v + v2 and set v2 (s: string) = v <- v2 + int s
member _.Item with get (v2: float) = float v + v2 / 2.

// [<Interface>]
// type ITesting =
// static member Testing x = x

// // TODO: This test produces different results in Fable and .NET
// // See Fable.Transforms.FSharp2Fable.TypeHelpers.makeTypeGenArgs
// // [<Fact>]
Expand All @@ -495,6 +499,11 @@ let ``Indexed properties work`` () =
f[4] |> equal 13
f[4.] |> equal 11

// [<Fact>]
// let ``Static interface members work`` () =
// let a = ITesting.Testing 5
// a |> equal 5

// [<Fact>]
// let ``Types can instantiate their parent in the constructor`` () =
// let t = TestType9()
Expand Down
Loading