From d14c5f596d788f7d7ebbe8025ab0f33b3c6262b6 Mon Sep 17 00:00:00 2001 From: ncave <777696+ncave@users.noreply.github.com> Date: Thu, 23 May 2024 01:34:00 -0700 Subject: [PATCH] Fixed #3566 --- src/Fable.Cli/CHANGELOG.md | 1 + src/Fable.Transforms/FSharp2Fable.Util.fs | 2 +- tests/Js/Main/TypeTests.fs | 10 +++++++++- tests/Python/TestType.fs | 22 ++++++++++++++++++++++ tests/Rust/tests/src/ByRefTests.fs | 2 +- tests/Rust/tests/src/TypeTests.fs | 9 +++++++++ 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index 77c3a72709..4bb6c47a69 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -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 diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index 57b2db9c5a..39752d0e70 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -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 -> diff --git a/tests/Js/Main/TypeTests.fs b/tests/Js/Main/TypeTests.fs index 5e314bdfa9..585524b216 100644 --- a/tests/Js/Main/TypeTests.fs +++ b/tests/Js/Main/TypeTests.fs @@ -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. +[] +type ITesting = + static member Testing x = x + type TypeWithByRefMember() = - static member DoubleIntByRef (x: byref) : unit = x <- 2 * x + static member DoubleIntByRef (x: byref) : unit = x <- 2 * x let inline doubleIntByRef (x: ^a) (input: int) : int = let mutable value = input @@ -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" diff --git a/tests/Python/TestType.fs b/tests/Python/TestType.fs index f8e68a989f..0c6a03285f 100644 --- a/tests/Python/TestType.fs +++ b/tests/Python/TestType.fs @@ -549,6 +549,15 @@ type MangledAbstractClass5(v) = 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 + member _.Item with get (v2: float) = float v + v2 / 2. + +[] +type ITesting = + static member Testing x = x + // TODO: This test produces different results in Fable and .NET // See Fable.Transforms.FSharp2Fable.TypeHelpers.makeTypeGenArgs // [] @@ -558,6 +567,19 @@ type ConcreteClass1() = // |> fun fi -> fi.PropertyType.GetGenericArguments().Length // |> equal 1 +[] +let ``test Indexed properties work`` () = + let f = IndexedProps(5) + f[4] |> equal 9 + f[3] <- "6" + f[4] |> equal 13 + f[4.] |> equal 11 + +[] +let ``test Static interface members work`` () = + let a = ITesting.Testing 5 + a |> equal 5 + [] let ``test Types can instantiate their parent in the constructor`` () = let t = Type9Test() diff --git a/tests/Rust/tests/src/ByRefTests.fs b/tests/Rust/tests/src/ByRefTests.fs index 9839418b59..bec84c0b82 100644 --- a/tests/Rust/tests/src/ByRefTests.fs +++ b/tests/Rust/tests/src/ByRefTests.fs @@ -127,7 +127,7 @@ let ``pass obj by ref using ByRef attr works`` () = // TODO: See #3328 // type TypeWithByRefMember() = -// static member DoubleIntByRef (x: byref) : unit = x <- 2 * x +// static member DoubleIntByRef (x: byref) : unit = x <- 2 * x // let inline doubleIntByRef (x: ^a) (input: int) : int = // let mutable value = input diff --git a/tests/Rust/tests/src/TypeTests.fs b/tests/Rust/tests/src/TypeTests.fs index ae624d0d70..376fccb104 100644 --- a/tests/Rust/tests/src/TypeTests.fs +++ b/tests/Rust/tests/src/TypeTests.fs @@ -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. +// [] +// type ITesting = +// static member Testing x = x + // // TODO: This test produces different results in Fable and .NET // // See Fable.Transforms.FSharp2Fable.TypeHelpers.makeTypeGenArgs // // [] @@ -495,6 +499,11 @@ let ``Indexed properties work`` () = f[4] |> equal 13 f[4.] |> equal 11 +// [] +// let ``Static interface members work`` () = +// let a = ITesting.Testing 5 +// a |> equal 5 + // [] // let ``Types can instantiate their parent in the constructor`` () = // let t = TestType9()