Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/Fable.Transforms/Dart/Fable2Dart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ module Util =

match entRef.FullName, genArgs with
| Types.enum_, _ -> Integer
// F# Quotation types are modelled dynamically by the quotation runtime,
// so map them to `dynamic` (the runtime returns plain tagged objects).
| Types.fsharpExpr, _
| Types.fsharpExprGeneric, _
// The NewUnionCase active pattern's first slot is typed as UnionCaseInfo in
// F#, but Dart's quotation runtime exposes it as a plain (type-name) string,
// so map the type to `dynamic` to keep the generated annotations valid.
| "Microsoft.FSharp.Reflection.UnionCaseInfo", _
// Likewise the Call/PropertyGet active patterns type their member slot as
// MethodInfo/PropertyInfo, but the quotation runtime exposes those as plain
// (member-name) strings, so map them to `dynamic` too.
| "System.Reflection.MethodInfo", _
| "System.Reflection.PropertyInfo", _
| Types.fsharpVar, _ -> Dynamic
// List without generics is same as List<dynamic>
| Types.array, _ -> List Dynamic
| "System.Tuple`1", _ -> transformTupleType com ctx genArgs
Expand Down Expand Up @@ -1570,13 +1584,30 @@ module Util =
]

let transformSwitch (com: IDartCompiler) ctx returnStrategy evalExpr cases defaultCase =
// An empty (unit) branch can only be removed if falling through to the default
// does nothing, otherwise a matching case would wrongly run the default body
// (e.g. `match ... with A -> () | _ -> failwith "..."`). Note that when no
// explicit default is given the last case is promoted to default below, so
// that promoted case is what an removed branch would fall through to.
let effectiveDefault =
match defaultCase with
| Some expr -> Some expr
| None -> cases |> List.tryLast |> Option.map snd

let canRemoveEmptyBranches =
match effectiveDefault with
| None
| Some(Fable.Value(Fable.UnitConstant, _)) -> true
| Some _ -> false

let cases =
cases
|> List.choose (fun (guards, expr) ->
// Remove empty branches
match returnStrategy, expr, guards with
| (Return(isVoid = true) | Ignore), Fable.Value(Fable.UnitConstant, _), _
| _, _, [] -> None
| (Return(isVoid = true) | Ignore), Fable.Value(Fable.UnitConstant, _), _ when canRemoveEmptyBranches ->
None
| _, _, guards ->
// Switch is only activated when guards are literals so we can ignore the statements
let guards = guards |> List.map (transformAndCaptureExpr com ctx >> snd)
Expand Down Expand Up @@ -2192,9 +2223,10 @@ module Util =
],
None

| Fable.Quote _ ->
addError com [] None "Quotations are not yet supported for Dart target"
[], None
| Fable.Quote(body, _isTyped, _r) ->
// Lower the quoted body to runtime calls that build the quotation AST,
// then transform like any other expression (mirrors PHP/Python/JS).
transform com ctx returnStrategy (QuotationEmitter.emitQuotedExpr com body)

let getLocalFunctionGenericParams
(_com: IDartCompiler)
Expand Down
3 changes: 2 additions & 1 deletion src/Fable.Transforms/Dart/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4110,7 +4110,8 @@ let tryCall (com: ICompiler) (ctx: Context) r t (info: CallInfo) (thisArg: Expr
getTypeName com ctx loc exprType |> StringConstant |> makeValue r |> Some
| c -> Helper.LibCall(com, "Reflection", "name", t, [ c ], ?loc = r) |> Some
| _ -> None
| _ -> None
// F# Quotations (Expr static methods, Var members, Patterns active patterns, EvaluateQuotation)
| typeName -> Quotations.tryQuotationCall "quotation" com ctx r t info thisArg args typeName

let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy<Type list>) genArgs args =
match ent.FullName with
Expand Down
1 change: 1 addition & 0 deletions src/fable-library-dart/Fable.Library.Dart.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Content Include="String.dart" />
<Content Include="Types.dart" />
<Content Include="Util.dart" />
<Content Include="quotation.dart" />
<Content Include="analysis_options.yaml" />
<Content Include="pubspec.lock" />
<Content Include="pubspec.yaml" />
Expand Down
Loading
Loading