diff --git a/msbuild/WebSharper.FSharp.Internal.targets b/msbuild/WebSharper.FSharp.Internal.targets index 757996b6..57224955 100644 --- a/msbuild/WebSharper.FSharp.Internal.targets +++ b/msbuild/WebSharper.FSharp.Internal.targets @@ -36,6 +36,7 @@ $(MSBuildProjectDirectory)/wsconfig.json True True + False $(NoWarn);3366;3370 diff --git a/src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs b/src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs index e5aaee5a..36bdcf76 100644 --- a/src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs +++ b/src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs @@ -44,7 +44,7 @@ type private N = NotResolvedMemberKind type private SourceMemberOrEntity = | SourceMember of FSMFV * list> * FSharpExpr | SourceEntity of FSharpEntity * ResizeArray - | SourceInterface of FSharpEntity + | SourceInterface of FSharpEntity * ResizeArray | InitAction of FSharpExpr let annotForTypeOrFile name (annot: A.TypeAnnotation) = @@ -84,10 +84,9 @@ let rec private collectTypeAnnotations (d: Dictionary + | SourceEntity (ent, nmembers) + | SourceInterface (ent, nmembers) -> collectTypeAnnotations d t sr annot ent nmembers - | SourceInterface ent -> - collectTypeAnnotations d t sr annot ent Seq.empty | _ -> () let private getConstraints (genParams: seq) (sr: CodeReader.SymbolReader) tparams = @@ -481,7 +480,7 @@ let rec private transformClass (sc: Lazy<_ * StartupCode>) (comp: Compilation) ( | _ -> error "Only methods can be defined Remote" | _ -> () - if isThisInterface && not isNotWSInterface && clsMembers.Count = 0 then None else + if isThisInterface && not isNotWSInterface && clsMembers.Count = 0 && members.Count = 0 then None else let fsharpSpecificNonException = cls.IsFSharpUnion || cls.IsFSharpRecord || cls.IsValueType @@ -978,10 +977,10 @@ let rec private transformClass (sc: Lazy<_ * StartupCode>) (comp: Compilation) ( | _ -> error "JavaScript attribute on parameter is only allowed on methods and constructors" | SourceEntity (ent, nmembers) -> transformClass sc comp ac sr classAnnots isInterface false recMembers ent nmembers |> Option.iter comp.AddClass - | SourceInterface i -> + | SourceInterface (i, nmembers) -> let intf, isNotWSInterface = transformInterface sr classAnnots i intf |> Option.iter comp.AddInterface - transformClass sc comp ac sr classAnnots isInterface isNotWSInterface recMembers i (ResizeArray()) |> Option.iter comp.AddClass + transformClass sc comp ac sr classAnnots isInterface isNotWSInterface recMembers i nmembers |> Option.iter comp.AddClass | InitAction expr -> transformInitAction sc comp sr annot recMembers expr @@ -1684,7 +1683,13 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co | FSIFD.Entity (a, b) -> if not a.IsFSharpAbbreviation then if a.IsInterface then - parentMembers.Add (SourceInterface a) + let ms = ResizeArray() + parentMembers.Add (SourceInterface (a, ms)) + try + types.Add (a, ms) + with _ -> + comp.AddError(Some (CodeReader.getRange a.DeclarationLocation), SourceError "Duplicate type definition") + //b |> List.iter (getTypesWithMembers ms) elif isILClass a then let ms = ResizeArray() parentMembers.Add (SourceEntity (a, ms)) @@ -1699,14 +1704,7 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co let m = SourceMember(a, b, c) match a.DeclaringEntity with | Some e -> - match types.TryGetValue(e) with - | true, t -> t.Add(m) - | _ -> - // interface might not have type generated for statics - let ms = ResizeArray() - ms.Add(m) - parentMembers.Add (SourceEntity (e, ms)) - types.Add (e, ms) + types[e].Add(m) | _ -> let i = Id.New(a.LogicalName) recMembers.Add(a, (i, c)) @@ -1721,8 +1719,8 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co match t with | SourceEntity (c, m) -> collectTypeAnnotations classAnnotations typeImplLookup sr rootTypeAnnot c m - | SourceInterface i -> - collectTypeAnnotations classAnnotations typeImplLookup sr rootTypeAnnot i Seq.empty + | SourceInterface (i, m) -> + collectTypeAnnotations classAnnotations typeImplLookup sr rootTypeAnnot i m | _ -> () // register all proxies for signature redirection @@ -1737,10 +1735,10 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co | InitAction _ -> failwith "impossible: top level init action" | SourceEntity (c, m) -> transformClass sc comp argCurrying sr classAnnotations isInterface false recMembers c m |> Option.iter comp.AddClass - | SourceInterface i -> + | SourceInterface (i, m) -> let intf, isNotWSInterface = transformInterface sr classAnnotations i intf |> Option.iter comp.AddInterface - transformClass sc comp argCurrying sr classAnnotations isInterface isNotWSInterface recMembers i [||] |> Option.iter comp.AddClass + transformClass sc comp argCurrying sr classAnnotations isInterface isNotWSInterface recMembers i m |> Option.iter comp.AddClass let getStartupCodeClass (def: TypeDefinition, sc: StartupCode) = diff --git a/src/stdlib/WebSharper.Main.Proxies/RuntimeHelpers.fs b/src/stdlib/WebSharper.Main.Proxies/RuntimeHelpers.fs index adab7f00..052a0662 100644 --- a/src/stdlib/WebSharper.Main.Proxies/RuntimeHelpers.fs +++ b/src/stdlib/WebSharper.Main.Proxies/RuntimeHelpers.fs @@ -56,6 +56,41 @@ let EnumerateUsing<'T1,'T2,'T3 when 'T1 :> System.IDisposable else false +[] +let EnumerateTryWith (s: seq<'T>) (f: exn -> int) (h: exn -> seq<'T>) : seq<'T> = + Enumerable.Of <| fun () -> + let mutable enum = null + let mutable orig = true + Enumerator.NewDisposing () (fun _ -> safeDispose enum) <| fun e -> + try + if enum = null then + enum <- Enumerator.Get s + if enum.MoveNext() then + e.Current <- enum.Current + true + else + false + with err when orig && f err = 1 -> + orig <- false + safeDispose enum + enum <- Enumerator.Get (h err) + if enum.MoveNext() then + e.Current <- enum.Current + true + else + false + +[] +let EnumerateFromFunctions (c: unit -> 'T) (n: 'T -> bool) (v: 'T -> 'U) : seq<'U> = + Enumerable.Of <| fun () -> + let st = c() + Enumerator.New st <| fun e -> + if n st then + e.Current <- v st + true + else + false + [] let EnumerateWhile (f: unit -> bool) (s: seq<'T>) : seq<'T> = Enumerable.Of (fun () -> diff --git a/src/stdlib/WebSharper.Main.Proxies/WebSharper.Main.Proxies.fsproj b/src/stdlib/WebSharper.Main.Proxies/WebSharper.Main.Proxies.fsproj index 71c431ec..5705b48e 100644 --- a/src/stdlib/WebSharper.Main.Proxies/WebSharper.Main.Proxies.fsproj +++ b/src/stdlib/WebSharper.Main.Proxies/WebSharper.Main.Proxies.fsproj @@ -4,7 +4,6 @@ Library True false - False None