Skip to content

Commit

Permalink
Fix calling an attached parametrized getter fails in transpiled javas…
Browse files Browse the repository at this point in the history
…cript

Fix #3494
  • Loading branch information
Maxime Mangel committed Aug 12, 2023
1 parent 3662dfc commit a0f79ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
"stopAtEntry": true,
"console": "internalConsole"
},
{
"name": "Quicktest - JavaScript",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": ["src/quicktest", "--exclude", "Fable.Core", "--noCache"],
"cwd": "${workspaceFolder}",
"console": "internalConsole"
},
{
"name": "Attach to Node",
"port": 9229,
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Cli/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Unreleased

* Fix #3480: Function decorated with `[<NamedParams>]` without arguments provided should take an empty object
* Fix #3494: Calling an attached parametrized getter fails in transpiled javascript

### 4.1.4

Expand Down
10 changes: 9 additions & 1 deletion src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,11 +1832,19 @@ module Util =
let arg = callInfo.Args |> List.tryHead |> Option.defaultWith makeNull
Fable.Set(callee, Fable.FieldSet(info.name), membType, arg, r)
else
// If the entity is decorated with AttachMembers, we need to remove the get/set prefix
// See https://github.com/fable-compiler/Fable/issues/3494
let membName =
if isAttachMembersEntity com entity then
Naming.removeGetSetPrefix info.name
else
info.name

let entityGenParamsCount = entity.GenericParameters.Count
let callInfo =
if callInfo.GenericArgs.Length < entityGenParamsCount then callInfo
else { callInfo with GenericArgs = List.skip entityGenParamsCount callInfo.GenericArgs }
getField callee info.name |> makeCall r typ callInfo
getField callee membName |> makeCall r typ callInfo

let failReplace (com: IFableCompiler) ctx r (info: Fable.ReplaceCallInfo) (thisArg: Fable.Expr option) =
let msg =
Expand Down
4 changes: 4 additions & 0 deletions tests/Js/Main/JsInteropTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ type ClassWithAttachments(v, ?sign) =
static member GreetingFormat = "Hello {0}"
static member GetGrettingEnding(times, sign) = String.replicate times sign
member _.WithSecretSauce(food) = $"{food} with lots of {secretSauce}"
member this.Add
with get(added : int) = x + added

type ClassWithAttachmentsChild() =
inherit ClassWithAttachments(3, "?")
Expand Down Expand Up @@ -320,6 +322,8 @@ let tests =
equal 2 x.Times
x.Times <- 3
x.SaySomethingTo("Tanaka") |> equal "Hello Tanaka!!!!!"
// See https://github.com/fable-compiler/Fable/issues/3494
x.Add 2 |> equal 7

testCase "Class with attached members can have static constructors" <| fun _ ->
let x = ClassWithAttachments(2)
Expand Down

0 comments on commit a0f79ec

Please sign in to comment.