Skip to content

Commit 512ae4d

Browse files
dbrattliclaude
andauthored
fix: add type specifiers to interpolated strings (#4646)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2ee30fc commit 512ae4d

17 files changed

Lines changed: 80 additions & 76 deletions

src/Fable.Compiler/ProjectCracker.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ let getFableLibraryPath (opts: CrackerOptions) (shouldCopy: bool) =
706706
|}
707707
|> Option.defaultWith (fun () ->
708708
Fable.FableError
709-
$"Cannot find [temp/]{buildDir} from {baseDir}.\nPlease, make sure you build {buildDir}"
709+
$"Cannot find [temp/]%s{buildDir} from %s{baseDir}.\nPlease, make sure you build %s{buildDir}"
710710
|> raise
711711
)
712712

@@ -786,7 +786,7 @@ let loadPrecompiledInfo (opts: CrackerOptions) otherOptions sourceFiles =
786786
// Check if precompiled compiler version and options match
787787
if info.CompilerVersion <> Literals.VERSION then
788788
Fable.FableError(
789-
$"Library was precompiled using Fable v{info.CompilerVersion} but you're using v{Literals.VERSION}. Please use same version."
789+
$"Library was precompiled using Fable v%s{info.CompilerVersion} but you're using v%s{Literals.VERSION}. Please use same version."
790790
)
791791
|> raise
792792

@@ -816,7 +816,7 @@ let loadPrecompiledInfo (opts: CrackerOptions) otherOptions sourceFiles =
816816
|> List.map (fun f -> " " + File.relPathToCurDir f)
817817
|> String.concat Log.newLine
818818
// TODO: This should likely be an error but make it a warning for now
819-
Log.warning ($"Detected outdated files in precompiled lib:{Log.newLine}{outdated}")
819+
Log.warning ($"Detected outdated files in precompiled lib:%s{Log.newLine}%s{outdated}")
820820
with er ->
821821
Log.warning ("Cannot check timestamp of precompiled files: " + er.Message)
822822

@@ -849,7 +849,7 @@ let getFullProjectOpts (resolver: ProjectCrackerResolver) (opts: CrackerOptions)
849849
if not isOlder then
850850
Log.verbose (
851851
lazy
852-
$"Cached project info ({cacheTimestamp}) will be discarded because {File.relPathToCurDir filePath} ({fileTimestamp}) is newer"
852+
$"Cached project info (%O{cacheTimestamp}) will be discarded because %s{File.relPathToCurDir filePath} (%O{fileTimestamp}) is newer"
853853
)
854854

855855
isOlder
@@ -911,7 +911,7 @@ let getFullProjectOpts (resolver: ProjectCrackerResolver) (opts: CrackerOptions)
911911
else
912912
"Debug"
913913

914-
$"Won't reuse compiled files because last compilation was for {otherMode} mode"
914+
$"Won't reuse compiled files because last compilation was for %s{otherMode} mode"
915915
)
916916

917917
isMostRecent

src/Fable.Compiler/Util.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,16 @@ module File =
316316
let creationTime = File.GetCreationTime(lockFile)
317317

318318
if (DateTime.Now - creationTime).TotalMilliseconds > float timeoutMs then
319-
Log.always $"Found old lock file {relPathToCurDir lockFile} ({creationTime})"
319+
Log.always $"Found old lock file %s{relPathToCurDir lockFile} (%O{creationTime})"
320320

321321
try
322322
File.Delete(lockFile)
323323
with _ ->
324324
()
325325
else
326-
Log.always $"Directory is locked, waiting for max {timeoutMs / 1000}s"
326+
Log.always $"Directory is locked, waiting for max %d{timeoutMs / 1000}s"
327327

328-
Log.always $"If compiler gets stuck, delete {relPathToCurDir lockFile}"
328+
Log.always $"If compiler gets stuck, delete %s{relPathToCurDir lockFile}"
329329
elif waitedMs >= timeoutMs then
330330
Fable.AST.Fable.FableError "LockTimeOut" |> raise
331331

@@ -348,7 +348,7 @@ module File =
348348
if fileCreated then
349349
File.Delete(lockFile)
350350
with e ->
351-
Log.always $"Could not delete lock file: {lockFile} ({e.Message})"
351+
Log.always $"Could not delete lock file: %s{lockFile} (%s{e.Message})"
352352

353353
[<RequireQualifiedAccess>]
354354
module Process =
@@ -388,7 +388,7 @@ module Process =
388388
let findInPath (exec: string) =
389389
match tryFindInPath exec with
390390
| Some exec -> exec
391-
| None -> failwith $"Cannot find {exec} in PATH"
391+
| None -> failwith $"Cannot find %s{exec} in PATH"
392392

393393
let getCurrentAssembly () = typeof<TypeInThisAssembly>.Assembly
394394

@@ -413,7 +413,7 @@ module Process =
413413
// TODO: We should use cliArgs.RootDir instead of Directory.GetCurrentDirectory here but it's only informative
414414
// so let's leave it as is for now to avoid having to pass the cliArgs through all the call sites
415415
if not redirectOutput then
416-
Log.always $"""{File.relPathToCurDir workingDir}> {exePath} {String.concat " " args}"""
416+
Log.always $"""%s{File.relPathToCurDir workingDir}> %s{exePath} %s{String.concat " " args}"""
417417

418418
let psi = ProcessStartInfo(exePath)
419419

@@ -616,7 +616,7 @@ module Imports =
616616
let importPath = Path.Combine(projDir, importPath)
617617
let targetDir = Path.GetDirectoryName(targetPath)
618618
getRelativePath targetDir importPath
619-
| Some macro, _ -> failwith $"Unknown import macro: {macro}"
619+
| Some macro, _ -> failwith $"Unknown import macro: %s{macro}"
620620
| None, None ->
621621
if isAbsolutePath importPath then
622622
let sourceDir = Path.GetDirectoryName(sourcePath)
@@ -934,7 +934,7 @@ type PrecompiledInfoImpl(fableModulesDir: string, info: PrecompiledInfoJson) =
934934
IO.Path.Combine(fableModulesDir, "precompiled_info.json")
935935

936936
static member GetInlineExprsPath(fableModulesDir, index: int) =
937-
IO.Path.Combine(fableModulesDir, "inline_exprs", $"inline_exprs_{index}.json")
937+
IO.Path.Combine(fableModulesDir, "inline_exprs", $"inline_exprs_%d{index}.json")
938938

939939
static member Load(fableModulesDir: string) =
940940
try

src/Fable.Transforms/BabelPrinter.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ module PrinterExtensions =
450450
|> List.iter (
451451
function
452452
| _, NullOrUndefinedOrVoid -> ()
453-
| key, StringConstant value -> printProp (fun () -> printer.Print($"{key}=\"{value}\""))
453+
| key, StringConstant value -> printProp (fun () -> printer.Print($"%s{key}=\"%s{value}\""))
454454
| key, value ->
455455
printProp (fun () ->
456456
printer.Print(key + "={")

src/Fable.Transforms/Dart/Fable2Dart.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module Util =
180180
match transformAndCaptureExpr com ctx entRef with
181181
| [], IdentExpression ident -> Some ident
182182
| _ ->
183-
addError com [] None $"Unexpected, entity ref for {ent.FullName} is not an identifier"
183+
addError com [] None $"Unexpected, entity ref for %s{ent.FullName} is not an identifier"
184184

185185
None
186186
)
@@ -1956,17 +1956,17 @@ module Util =
19561956
match transformCallArgs com ctx (CallInfo info) with
19571957
| [], args -> args
19581958
| _, args ->
1959-
$"Rewrite base arguments for {classDecl.Entity.FullName} so they can be compiled as Dart expressions"
1959+
$"Rewrite base arguments for %s{classDecl.Entity.FullName} so they can be compiled as Dart expressions"
19601960
|> addWarning com [] e.Range
19611961

19621962
args
19631963
| Some(Fable.Value _ as e) ->
1964-
$"Ignoring base call for {classDecl.Entity.FullName}"
1964+
$"Ignoring base call for %s{classDecl.Entity.FullName}"
19651965
|> addWarning com [] e.Range
19661966

19671967
[]
19681968
| Some e ->
1969-
$"Unexpected base call for {classDecl.Entity.FullName}"
1969+
$"Unexpected base call for %s{classDecl.Entity.FullName}"
19701970
|> addError com [] e.Range
19711971

19721972
[]
@@ -2316,7 +2316,7 @@ module Util =
23162316
let name =
23172317
match p.Name with
23182318
| Some name -> name
2319-
| None -> $"arg{i}$"
2319+
| None -> $"arg%d{i}$"
23202320

23212321
let t = transformType com ctx p.Type
23222322
FunctionArg(makeImmutableIdent t name) // TODO, isOptional=p.IsOptional, isNamed=p.IsNamed)
@@ -2391,7 +2391,7 @@ module Util =
23912391
=
23922392
match implementsIterable, baseType with
23932393
| Some iterable, Some _ ->
2394-
$"Types implementing IEnumerable cannot inherit from another class: {classEnt.FullName}"
2394+
$"Types implementing IEnumerable cannot inherit from another class: %s{classEnt.FullName}"
23952395
|> addError com [] None
23962396

23972397
Some iterable

src/Fable.Transforms/Dart/Replacements.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ let tryEntityIdent (com: Compiler) entFullName =
640640
| BuiltinDefinition(FSharpReference _) -> makeImportLib com MetaType "FSharpRef" "Types" |> Some
641641
| BuiltinDefinition(FSharpResult _) -> makeImportLib com MetaType "FSharpResult$2" "Result" |> Some
642642
| BuiltinDefinition(FSharpChoice genArgs) ->
643-
let membName = $"FSharpChoice${List.length genArgs}"
643+
let membName = $"FSharpChoice$%d{List.length genArgs}"
644644
makeImportLib com MetaType membName "Choice" |> Some
645645
// | BuiltinDefinition BclGuid -> jsTypeof "string" expr
646646
| BuiltinDefinition(BclHashSet _)
@@ -1387,7 +1387,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt
13871387
| "GetEnumerator", Some c, _ -> stringToCharSeq c |> getEnumerator com r t |> Some
13881388
| ("Contains" | "StartsWith" | "EndsWith" as meth), Some c, arg :: _ ->
13891389
if List.isMultiple args then
1390-
addWarning com ctx.InlinePath r $"String.{meth}: second argument is ignored"
1390+
addWarning com ctx.InlinePath r $"String.%s{meth}: second argument is ignored"
13911391

13921392
Helper.InstanceCall(c, Naming.lowerFirst meth, t, [ arg ], ?loc = r) |> Some
13931393
| ReplaceName [ "ToUpper", "toUpperCase"
@@ -3158,7 +3158,7 @@ let random (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opti
31583158
| meth, Some thisArg ->
31593159
let meth =
31603160
if meth = "Next" then
3161-
$"Next{List.length args}"
3161+
$"Next%d{List.length args}"
31623162
else
31633163
meth
31643164

@@ -3273,7 +3273,7 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp
32733273
match thisArg, args with
32743274
| Some thisArg, args ->
32753275
if args.Length > 2 then
3276-
$"Regex.{meth} doesn't support more than 2 arguments"
3276+
$"Regex.%s{meth} doesn't support more than 2 arguments"
32773277
|> addError com ctx.InlinePath r
32783278

32793279
thisArg :: args |> Some
@@ -4194,6 +4194,6 @@ let tryType typ =
41944194
| FSharpMap(key, value) -> Some(Types.fsharpMap, maps, [ key; value ])
41954195
| FSharpSet genArg -> Some(Types.fsharpSet, sets, [ genArg ])
41964196
| FSharpResult(genArg1, genArg2) -> Some(Types.result, results, [ genArg1; genArg2 ])
4197-
| FSharpChoice genArgs -> Some($"{Types.choiceNonGeneric}`{List.length genArgs}", results, genArgs)
4197+
| FSharpChoice genArgs -> Some($"%s{Types.choiceNonGeneric}`%d{List.length genArgs}", results, genArgs)
41984198
| FSharpReference genArg -> Some(Types.refCell, refCells, [ genArg ])
41994199
| _ -> None

src/Fable.Transforms/FSharp2Fable.Util.fs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,16 +2595,19 @@ module Util =
25952595
let failReplace (com: IFableCompiler) ctx r (info: Fable.ReplaceCallInfo) (thisArg: Fable.Expr option) =
25962596
let msg =
25972597
if info.DeclaringEntityFullName.StartsWith("Fable.Core.", StringComparison.Ordinal) then
2598-
$"{info.DeclaringEntityFullName}.{info.CompiledName} is not supported, try updating fable tool"
2598+
$"%s{info.DeclaringEntityFullName}.%s{info.CompiledName} is not supported, try updating fable tool"
25992599
else
26002600
com.WarnOnlyOnce(
26012601
"Fable only supports a subset of standard .NET API, please check https://fable.io/docs/dotnet/compatibility.html. For external libraries, check whether they are Fable-compatible in the package docs."
26022602
)
26032603

2604-
$"""{info.DeclaringEntityFullName}.{info.CompiledName}{if Option.isSome thisArg then
2605-
""
2606-
else
2607-
" (static)"} is not supported by Fable"""
2604+
let staticSuffix =
2605+
if Option.isSome thisArg then
2606+
""
2607+
else
2608+
" (static)"
2609+
2610+
$"%s{info.DeclaringEntityFullName}.%s{info.CompiledName}%s{staticSuffix} is not supported by Fable"
26082611

26092612
msg |> addErrorAndReturnNull com ctx.InlinePath r
26102613

src/Fable.Transforms/FSharp2Fable.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ let private transformNewUnion com ctx r fsType (unionCase: FSharpUnionCase) (arg
111111
match argExprs with
112112
| [] -> transformStringEnum rule unionCase
113113
| _ ->
114-
$"StringEnum types cannot have fields: {tdef.TryFullName}"
114+
$"StringEnum types cannot have fields: %O{tdef.TryFullName}"
115115
|> addErrorAndReturnNull com ctx.InlinePath r
116116

117117
| OptionUnion(typ, isStruct) ->
@@ -723,7 +723,7 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) appliedGenArgs fs
723723
let! limit = transformExpr com ctx [] limit
724724
let! body = transformExpr com newContext [] body
725725
return makeForLoop r isUp ident start limit body
726-
| _ -> return failwithf $"Unexpected loop {r}: %A{fsExpr}"
726+
| _ -> return failwithf $"Unexpected loop %O{r}: %A{fsExpr}"
727727

728728
| FSharpExprPatterns.WhileLoop(guardExpr, bodyExpr, _) ->
729729
let! guardExpr = transformExpr com ctx [] guardExpr
@@ -1686,7 +1686,7 @@ let private applyJsPyDecorators
16861686
let parameters =
16871687
memb.CurriedParameterGroups
16881688
|> Seq.collect id
1689-
|> Seq.mapi (fun i p -> defaultArg p.Name $"arg{i}", makeType Map.empty p.Type)
1689+
|> Seq.mapi (fun i p -> defaultArg p.Name $"arg%d{i}", makeType Map.empty p.Type)
16901690
|> Seq.toList
16911691

16921692
Replacements.Api.makeMethodInfo com None name parameters returnType
@@ -2760,7 +2760,7 @@ type FableCompiler(com: Compiler) =
27602760
|> List.filter (fun (i, v) ->
27612761
if ctx.CapturedBindings.Contains(i.Name) && canHaveSideEffects com v then
27622762
if isIdentUsed i.Name resolved then
2763-
$"Inlined argument {i.Name} is being captured but is also used somewhere else. "
2763+
$"Inlined argument %s{i.Name} is being captured but is also used somewhere else. "
27642764
+ "There's a risk of double evaluation."
27652765
|> addWarning com [] i.Range
27662766

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,10 @@ module Annotation =
754754
| Replacements.Util.FSharpMap(key, value) ->
755755
makeFableLibImportTypeAnnotation com ctx [ key; value ] "Map" "FSharpMap"
756756
| Replacements.Util.FSharpResult(ok, err) ->
757-
$"FSharpResult$2{Util.UnionHelpers.UNION_SUFFIX}"
757+
$"FSharpResult$2%s{Util.UnionHelpers.UNION_SUFFIX}"
758758
|> makeFableLibImportTypeAnnotation com ctx [ ok; err ] "Result"
759759
| Replacements.Util.FSharpChoice genArgs ->
760-
$"FSharpChoice${List.length genArgs}{Util.UnionHelpers.UNION_SUFFIX}"
760+
$"FSharpChoice$%d{List.length genArgs}%s{Util.UnionHelpers.UNION_SUFFIX}"
761761
|> makeFableLibImportTypeAnnotation com ctx genArgs "Choice"
762762
| Replacements.Util.FSharpReference genArg ->
763763
if isInRefOrAnyType com typ then
@@ -772,7 +772,7 @@ module Annotation =
772772
| _ -> argTypes
773773
|> List.mapi (fun i argType ->
774774
FunctionTypeParam.functionTypeParam (
775-
Identifier.identifier ($"arg{i}"),
775+
Identifier.identifier ($"arg%d{i}"),
776776
makeTypeAnnotation com ctx argType
777777
)
778778
)
@@ -1034,7 +1034,7 @@ module Util =
10341034
if selector.StartsWith("*", StringComparison.Ordinal) then
10351035
selector
10361036
else
1037-
$"default as {selector}"
1037+
$"default as %s{selector}"
10381038

10391039
com.GetImportExpr(ctx, selector, path, r, noMangle = true) |> ignore
10401040

@@ -1631,7 +1631,7 @@ module Util =
16311631
Expression.callExpression (helperRef, values, typeArguments = typeParams)
16321632
| None -> callConstructor (Some case)
16331633
| None ->
1634-
$"Unmatched union case tag: {tag} for {ent.FullName}" |> addWarning com [] r
1634+
$"Unmatched union case tag: %d{tag} for %s{ent.FullName}" |> addWarning com [] r
16351635

16361636
callConstructor None
16371637
else
@@ -2676,7 +2676,8 @@ but thanks to the optimisation done below we get
26762676
match List.tryItem tag ent.UnionCases with
26772677
| Some case -> Some case.Name
26782678
| None ->
2679-
$"Unmatched union case tag: {tag} for {ent.FullName}" |> addWarning com [] range
2679+
$"Unmatched union case tag: %d{tag} for %s{ent.FullName}"
2680+
|> addWarning com [] range
26802681

26812682
None
26822683
| _ -> None
@@ -4742,7 +4743,7 @@ but thanks to the optimisation done below we get
47424743
let noConflict = ctx.UsedNames.RootScope.Add(alias)
47434744
47444745
if not noConflict then
4745-
com.WarnOnlyOnce($"Import {alias} conflicts with existing identifier in root scope")
4746+
com.WarnOnlyOnce($"Import %s{alias} conflicts with existing identifier in root scope")
47464747
47474748
alias
47484749
else

src/Fable.Transforms/FableTransforms.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ module private Transforms =
599599
match expr with
600600
| IdentExpr _ -> None, expr
601601
| arg ->
602-
let ident = makeTypedIdent argType $"anonRec{com.IncrementCounter()}"
602+
let ident = makeTypedIdent argType $"anonRec%d{com.IncrementCounter()}"
603603

604604
Some(ident, arg), IdentExpr ident
605605

src/Fable.Transforms/OverloadSuffix.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let rec private getTypeFastFullName (genParams: IDictionary<_, _>) (t: Fable.Typ
6060
let typeName = getTypeFastFullName genParams genArg
6161

6262
if isStruct then
63-
$"System.Nullable<{typeName}>"
63+
$"System.Nullable<%s{typeName}>"
6464
else
6565
// there is no overload distinction for nullable reference types,
6666
// so the name and overload suffix are the same as the inner type

0 commit comments

Comments
 (0)