Closed SchlenkR closed 2 years ago
@RonaldSchlenker I can't reproduce with this simplified version, seems to compile fine.
Can you please see what is missing and/or see if you can narrow it down to a self-contained repro? Thanks!
I think I know more now. It's in this stripped-down branch: https://github.com/RonaldSchlenker/Vide/tree/FABLE_ERROR
The code is this:
module Vide.Core
open System.Runtime.CompilerServices
type NodeBuilder() = class end
[<Extension>]
type NodeBuilderExtensions() =
[<Extension>]
static member inline attrCond(this: #NodeBuilder, value: unit) =
()
[<Extension>]
type HTMLAnchorElementBuilderExtensions() =
[<Extension>]
static member inline href(this: #NodeBuilder, value) =
// this is caising the exception on "npm start"
//
this.attrCond(value)
// this is working
//NodeBuilderExtensions.attrCond(this, "href", ?value = value)
Now: The error only occurs if both this
args are flexible types (i.e. #NodeBuilder
instead of NodeBuilder
).
The Fable-Packages that are used:
<PackageReference Include="Fable.Core" Version="3.7.1" />
<PackageReference Include="Fable.Browser.Dom" Version="2.10.0" />
P.S.: You can also just compile that single file to get the error:
PS C:\Users\ronal\source\repos\github\vide\src> dotnet fable .\core.fs
Fable: F# to JS compiler 3.7.17
Thanks to the contributor! @coolya
Stand with Ukraine! https://standwithukraine.com.ua/
Parsing core.fs...
Unhandled exception. System.Exception: Unsupported project type: .fs
at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)
at Fable.Cli.ProjectCracker.retry@489(CrackerOptions opts, DateTime retryUntil, Unit unitVar0) in C:\Users\alfon\repos\Fable\src\Fable.Cli\ProjectCracker.fs:line 491
at Fable.Cli.ProjectCracker.retryGetCrackedProjects(CrackerOptions opts) in C:\Users\alfon\repos\Fable\src\Fable.Cli\ProjectCracker.fs:line 500
at Fable.Cli.ProjectCracker.getFullProjectOpts(CrackerOptions opts) in C:\Users\alfon\repos\Fable\src\Fable.Cli\ProjectCracker.fs:line 692
at Fable.Cli.Main.Init@403.Invoke(Unit unitVar0) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Main.fs:line 404
at Fable.Cli.Performance.measure[a](FSharpFunc`2 f) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Util.fs:line 723
at Fable.Cli.Main.ProjectCracked.Init(CliArgs cliArgs) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Main.fs:line 403
at Fable.Cli.Main.compilationCycle@768.Invoke(Unit unitVar) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Main.fs:line 773
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 508
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 112
--- End of stack trace from previous location ---
at Microsoft.FSharp.Control.AsyncResult`1.Commit() in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 453
at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1133
at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1160
at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1504
at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
at Fable.Cli.Entry.startCompilation@276-16(CliArgs cliArgs, FSharpOption`1 watchDelay, Unit unitVar0) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Entry.fs:line 277
at Fable.Cli.Entry.Run@208-2.Invoke(Unit _arg4) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Entry.fs:line 284
at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
at Fable.Cli.Entry.main@360.Invoke(Tuple`2 _arg2) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Entry.fs:line 366
at Fable.Cli.Entry.main(String[] argv) in C:\Users\alfon\repos\Fable\src\Fable.Cli\Entry.fs:line 358
PS C:\Users\ronal\source\repos\github\vide\src>
@RonaldSchlenker Thank you, looks like it's this issue, seems already resolved upstream, but not released yet (you can still see it when you compile with F# .NET 6.0.400). Since it was already fixed in latest FCS, it will be resolved next time we refresh FCS in Fable. I'll leave it open until then, in the mean time you can try older versions of Fable that don't have that issue.
in the mean time you can try older versions of Fable that don't have that issue.
or as a workaround: invoke as static function instead of extension method.
Thank you @ncave
@ncave Would it be possible to update the FCS fork. I'm seeing another issue where the parameter attributes are not reflected by FCS and I'm not sure if this is also a regression.
UPDATE: Hmm, it maybe related to this, which doesn't seem to be fixed yet :/ https://github.com/dotnet/fsharp/issues/13759
@alfonsogarciacaro OK, I'll wait for the Bat signal then.
@ncave Actually, the problem reported in my previous comment was not a regression, but a bug/limitation of FCS that hadn't surfaced until now. I've reported it here: https://github.com/dotnet/fsharp/issues/13786
When invoking an extension method from within another extension method, an exception is thrown during fable compilation.
Basically, this is the code:
The exception in the CLI is this:
I played around with optional arguments, etc, but without success. Indeed, the only workaround (and good hint to what might cause the exception) is changing the invocation from extension method style to static function invocation (see comments in the code above).
Repo / Reproduction
Running
npm start
on this repo and branch triggers the exception.It's in this file: https://github.com/RonaldSchlenker/Vide/blob/f79bb10e016c41f08d12395615fef58bd244af33/src/fable.fs#L171
It is possible to compile correctly the code without fable.
Related information
Thank you!