fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.9k stars 296 forks source link

Exception compiling valid F# code / ExtensionMethods #3073

Closed SchlenkR closed 2 years ago

SchlenkR commented 2 years ago

When invoking an extension method from within another extension method, an exception is thrown during fable compilation.

Basically, this is the code:

// ------
// This is an extension class - the extension method "attrCond" is called from the code below...
// ------
[<Extension>]
type NodeBuilderExtensions() =
    [<Extension>]
    static member inline attrCond(this: #NodeBuilder, name, ?value: string) =
        match value with
        | Some value -> do this.Attributes <- (name, Some value) :: this.Attributes
        | None -> ()
        this

// ...

[<Extension>]
type HTMLAnchorElementBuilderExtensions() =
    // ------
    // This is the extension method that calls the other extension method from above.
    // - When "attrCond" is invoked like an extension method, the compiler crashes.
    // - When is is invoked as a normal static method, the compiler works as expected.
    // ------
    [<Extension>]
    static member inline href(this: #HTMLAnchorElementBuilder, ?value: string) =
        // this is raising the exception on "npm start"
        this.attrCond("href", ?value = value)

        // this is working (exception during compilation)
        //NodeBuilderExtensions.attrCond(this, "href", ?value = value)

The exception in the CLI is this:

Started Fable compilation...
tcrefOfAppTy
   at FSharp.Compiler.TypedTreeOps.tcrefOfAppTy(TcGlobals g, TType ty) in /home/dev/Projects/fsharp/src/Compiler/TypedTree/TypedTreeOps.fs:line 877
   at FSharp.Compiler.AttributeChecking.CheckMethInfoAttributes[a](TcGlobals g, Range m, FSharpOption`1 tyargsOpt, MethInfo minfo) in /home/dev/Projects/fsharp/src/Compiler/Checking/AttributeChecking.fs:line 403
   at FSharp.Compiler.MethodCalls.MethInfoChecks[a](TcGlobals g, ImportMap amap, Boolean isInstance, FSharpOption`1 tyargsOpt, FSharpList`1 objArgs, AccessorDomain ad, Range m, MethInfo minfo) in /home/dev/Projects/fsharp/src/Compiler/Checking/MethodCalls.fs:line 1199
   at FSharp.Compiler.CheckExpressions.TcMethodApplication(Boolean isCheckingAttributeCall, TcFileState cenv, TcEnv env, UnscopedTyparEnv tpenv, FSharpOption`1 tyArgsOpt, FSharpList`1 objArgs, Range mMethExpr, Range mItem, String methodName, FSharpOption`1 objTyOpt, AccessorDomain ad, Mutates mut, Boolean isProp, FSharpList`1 calledMethsAndProps, AfterResolution afterResolution, ValUseFlag isSuperInit, FSharpList`1 curriedCallerArgs, OverallTy exprTy, FSharpList`1 delayed) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 9653
   at FSharp.Compiler.CheckExpressions.TcMethodApplicationThen(TcFileState cenv, TcEnv env, OverallTy overallTy, FSharpOption`1 objTyOpt, UnscopedTyparEnv tpenv, FSharpOption`1 callerTyArgs, FSharpList`1 objArgs, Range m, Range mItem, String methodName, AccessorDomain ad, Mutates mut, Boolean isProp, FSharpList`1 meths, AfterResolution afterResolution, ValUseFlag isSuperInit, FSharpList`1 args, ExprAtomicFlag atomicFlag, FSharpList`1 delayed) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 9163
   at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
   at FSharp.Compiler.CheckExpressions.TcExprThen@5396-1.Invoke(TcEnv env) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5400
   at FSharp.Compiler.CheckExpressions.TcNonControlFlowExpr(TcEnv env, FSharpFunc`2 f) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5574
   at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
   at FSharp.Compiler.CheckExpressions.TcExprNoRecover(TcFileState cenv, OverallTy ty, TcEnv env, UnscopedTyparEnv tpenv, SynExpr synExpr) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5276
   at FSharp.Compiler.CheckExpressions.TcExpr@5253.Invoke(Unit unitVar0) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5259
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.CheckExpressions.TcExpr@5253.Invoke(Unit unitVar0) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5264
   at FSharp.Compiler.DiagnosticsLogger.StackGuard.Guard[T](FSharpFunc`2 f) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 837
   at FSharp.Compiler.CheckExpressions.TcExpr(TcFileState cenv, OverallTy ty, TcEnv env, UnscopedTyparEnv tpenv, SynExpr synExpr) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5253
   at FSharp.Compiler.CheckExpressions.TcIteratedLambdas(TcFileState cenv, Boolean isFirst, TcEnv env, OverallTy overallTy, FSharpSet`1 takenNames, UnscopedTyparEnv tpenv, SynExpr e) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 6301
   at FSharp.Compiler.CheckExpressions.TcIteratedLambdas(TcFileState cenv, Boolean isFirst, TcEnv env, OverallTy overallTy, FSharpSet`1 takenNames, UnscopedTyparEnv tpenv, SynExpr e) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 6290
   at FSharp.Compiler.CheckExpressions.TcExprUndelayed(TcFileState cenv, OverallTy overallTy, TcEnv env, UnscopedTyparEnv tpenv, SynExpr synExpr) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5831
   at System.Runtime.CompilerServices.RuntimeHelpers.DispatchTailCalls(IntPtr callersRetAddrSlot, IntPtr callTarget, IntPtr retVal)
   at FSharp.Compiler.CheckExpressions.TcExprNoRecover(TcFileState cenv, OverallTy ty, TcEnv env, UnscopedTyparEnv tpenv, SynExpr synExpr) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5276
   at FSharp.Compiler.CheckExpressions.TcExpr@5253.Invoke(Unit unitVar0) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5259
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.CheckExpressions.TcExpr@5253.Invoke(Unit unitVar0) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5264
   at FSharp.Compiler.DiagnosticsLogger.StackGuard.Guard[T](FSharpFunc`2 f) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 837
   at FSharp.Compiler.CheckExpressions.TcExpr(TcFileState cenv, OverallTy ty, TcEnv env, UnscopedTyparEnv tpenv, SynExpr synExpr) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5253
   at FSharp.Compiler.CheckExpressions.TcExprThatCantBeCtorBody(TcFileState cenv, OverallTy overallTy, TcEnv env, UnscopedTyparEnv tpenv, SynExpr synExpr) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 5314
   at FSharp.Compiler.CheckExpressions.f@592-16(TcFileState cenv, FSharpOption`1 safeThisValOpt, SafeInitData safeInitInfo, SynPat pat, DebugPointAtBinding debugPoint, PrelimValReprInfo prelimValReprInfo, UnscopedTyparEnv tpenv, TcEnv envinner, Boolean isCtor, FSharpRef`1 rhsExpr, FSharpRef`1 overallExprTy, Unit unitVar0) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 10374
   at FSharp.Compiler.CheckExpressions.TcNormalizedBinding(DeclKind declKind, TcFileState cenv, TcEnv env, UnscopedTyparEnv tpenv, TType overallTy, FSharpOption`1 safeThisValOpt, SafeInitData safeInitInfo, FSharpList`1 enclosingDeclaredTypars, ExplicitTyparInfo explicitTyparInfo, NormalizedBinding bind) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 10347
   at FSharp.Compiler.CheckExpressions.TcLetrecBinding(TcFileState cenv, TcEnv envRec, Range scopem, FSharpList`1 extraGeneralizableTypars, FSharpOption`1 reqdThisValTyOpt, TcEnv envNonRec, FSharpList`1 generalizedRecBinds, FSharpList`1 preGeneralizationRecBinds, UnscopedTyparEnv tpenv, FSharpMap`2 uncheckedRecBindsTable, PreCheckingRecursiveBinding rbind) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckExpressions.fs:line 11458
   at FSharp.Compiler.CheckDeclarations.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization@1893-2.Invoke(Tuple`7 innerState, TyconBindingPhase2A defnA) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 2015
   at Microsoft.FSharp.Primitives.Basics.List.mapFoldToFreshConsTail[TResult,TState,T](FSharpList`1 cons, FSharpFunc`3 f, TState acc, FSharpList`1 xs) in /home/dev/Projects/fsharp/src/FSharp.Core/local.fs:line 377
   at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc`2 f, TState acc, FSharpList`1 xs) in /home/dev/Projects/fsharp/src/FSharp.Core/local.fs:line 393
   at Microsoft.FSharp.Collections.ListModule.MapFold[T,TState,TResult](FSharpFunc`2 mapping, TState state, FSharpList`1 list) in /home/dev/Projects/fsharp/src/FSharp.Core/list.fs:line 108
   at FSharp.Compiler.CheckDeclarations.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization$cont@1873(TcFileState cenv, Range scopem, TcGlobals g, TcEnv envForDecls, MutRecShape`3 defnsA, FSharpMap`2 uncheckedRecBindsTable, UnscopedTyparEnv tpenv, FSharpList`1 preGeneralizationRecBinds, FSharpList`1 generalizedRecBinds, TcEnv envNonRec, Unit unitVar) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 1893
   at FSharp.Compiler.CheckDeclarations.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization@1845.Invoke(Tuple`5 outerState, TcEnv envForDecls, MutRecShape`3 defnsA) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 1869
   at FSharp.Compiler.CheckDeclarations.MutRecShapes.mapFoldWithEnv@144.Invoke(a z, MutRecShape`3 x) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 147
   at Microsoft.FSharp.Primitives.Basics.List.mapFold[TState,T,TResult](FSharpFunc`2 f, TState acc, FSharpList`1 xs) in /home/dev/Projects/fsharp/src/FSharp.Core/local.fs:line 386
   at Microsoft.FSharp.Collections.ListModule.MapFold[T,TState,TResult](FSharpFunc`2 mapping, TState state, FSharpList`1 list) in /home/dev/Projects/fsharp/src/FSharp.Core/list.fs:line 108
   at FSharp.Compiler.CheckDeclarations.MutRecBindingChecking.TcMutRecBindings_Phase2B_TypeCheckAndIncrementalGeneralization(TcFileState cenv, UnscopedTyparEnv tpenv, TcEnv envInitial, TcEnv envMutRec, FSharpList`1 defnsAs, FSharpList`1 uncheckedRecBinds, Range scopem) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 1845
   at FSharp.Compiler.CheckDeclarations.MutRecBindingChecking.TcMutRecDefns_Phase2_Bindings(TcFileState cenv, TcEnv envInitial, UnscopedTyparEnv tpenv, Range bindsm, Range scopem, FSharpOption`1 mutRecNSInfo, TcEnv envMutRecPrelimWithReprs, FSharpList`1 mutRecDefns) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 2388
   at FSharp.Compiler.CheckDeclarations.TcMutRecDefns_Phase2(TcFileState cenv, TcEnv envInitial, Range bindsm, Range scopem, FSharpOption`1 mutRecNSInfo, TcEnv envMutRec, FSharpList`1 mutRecDefns) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 2569
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.CheckDeclarations.TcMutRecDefns_Phase2(TcFileState cenv, TcEnv envInitial, Range bindsm, Range scopem, FSharpOption`1 mutRecNSInfo, TcEnv envMutRec, FSharpList`1 mutRecDefns) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 2589
   at FSharp.Compiler.CheckDeclarations.TcDeclarations.TcMutRecDefinitions(TcFileState cenv, TcEnv envInitial, ParentRef parent, FSharpSet`1 typeNames, UnscopedTyparEnv tpenv, Range m, Range scopem, FSharpOption`1 mutRecNSInfo, FSharpList`1 mutRecDefns) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5037
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-1.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5492
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-13.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5477
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-13.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5662
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementsNonMutRec@5676-1.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5676
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElements@5804-5.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5804
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5570-11.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5570
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-13.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5477
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-13.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5662
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementsNonMutRec@5676-1.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5676
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElements@5804-5.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5804
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5630-12.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5630
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-13.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5477
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementNonMutRec@5477-13.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5662
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElementsNonMutRec@5676-1.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5676
   at FSharp.Compiler.CheckDeclarations.TcModuleOrNamespaceElements@5804-5.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 5804
   at FSharp.Compiler.CheckDeclarations.CheckOneImplFile@6030-1.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Checking/CheckDeclarations.fs:line 6030
   at FSharp.Compiler.ParseAndCheckInputs.CheckOneInput@1231-14.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Driver/ParseAndCheckInputs.fs:line 1231
   at FSharp.Compiler.ParseAndCheckInputs.CheckOneInput@1131-16.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Driver/ParseAndCheckInputs.fs:line 1131
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.ReraiseIfWatsonable(Exception exn) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 403
   at FSharp.Compiler.DiagnosticsLogger.DiagnosticsLoggerExtensions.DiagnosticsLogger.ErrorRecovery(DiagnosticsLogger x, Exception exn, Range m) in /home/dev/Projects/fsharp/src/Compiler/Facilities/DiagnosticsLogger.fs:line 454
   at FSharp.Compiler.ParseAndCheckInputs.CheckOneInput@1131-16.Invoke(CancellationToken ct) in /home/dev/Projects/fsharp/src/Compiler/Driver/ParseAndCheckInputs.fs:line 1131
   at Internal.Utilities.Library.Cancellable.runWithoutCancellation[T](Cancellable`1 comp) in /home/dev/Projects/fsharp/src/Compiler/Utilities/illib.fs:line 916
   at FSharp.Compiler.SourceCodeServices.ParseAndCheck.TypeCheckOneInputEntry(FSharpParseFileResults parseResults, TcResultsSink tcSink, TcState tcState, FSharpMap`2 moduleNamesDict, CompilerState compilerState) in /home/dev/Projects/fsharp/fcs/service_slim.fs:line 212
   at FSharp.Compiler.SourceCodeServices.ParseAndCheck.typeCheckOneInput@242[a](CompilerState compilerState, TcState tcState, FSharpMap`2 moduleNamesDict, FSharpParseFileResults parseRes, a _fileName) in /home/dev/Projects/fsharp/fcs/service_slim.fs:line 243
   at FSharp.Compiler.SourceCodeServices.ParseAndCheck.cachedTypeCheck@245-1.Invoke(String delegateArg0)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at FSharp.Compiler.SourceCodeServices.ParseAndCheck.cachedTypeCheck@240.Invoke(Tuple`2 tupledArg, FSharpParseFileResults parseRes) in /home/dev/Projects/fsharp/fcs/service_slim.fs:line 245
   at Microsoft.FSharp.Primitives.Basics.Array.mapFold[TState,T,TResult](FSharpFunc`2 f, TState acc, T[] array) in /home/dev/Projects/fsharp/src/FSharp.Core/local.fs:line 1049
   at Microsoft.FSharp.Collections.ArrayModule.MapFold[T,TState,TResult](FSharpFunc`2 mapping, TState state, T[] array) in /home/dev/Projects/fsharp/src/FSharp.Core/array.fs:line 464
   at FSharp.Compiler.SourceCodeServices.ParseAndCheck.TypeCheckClosedInputSet(FSharpParseFileResults[] parseResults, TcState tcState, CompilerState compilerState, FSharpOption`1 subscriber) in /home/dev/Projects/fsharp/fcs/service_slim.fs:line 257
   at <StartupCode$FSharp-Compiler-Service>.$Service_slim.ParseAndCheckProject@324-1.Invoke(CompilerState compilerState) in /home/dev/Projects/fsharp/fcs/service_slim.fs:line 344
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 525
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 112

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

If you need any kind of help or more info, please let me know.

Thank you!

ncave commented 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!

SchlenkR commented 2 years ago

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>
ncave commented 2 years ago

@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.

SchlenkR commented 2 years ago

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

alfonsogarciacaro commented 2 years ago

@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

ncave commented 2 years ago

@alfonsogarciacaro OK, I'll wait for the Bat signal then.

alfonsogarciacaro commented 2 years ago

@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