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
2 changes: 2 additions & 0 deletions src/Compiler/Checking/CheckFormatStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ let parseFormatStringInternal

// residue of hole "...{n}..." in interpolated strings become %P(...)
| 'P' when isInterpolated ->
let (code, message) = FSComp.SR.alwaysUseTypedStringInterpolation()
warning(DiagnosticWithText(code, message, m))
checkOtherFlags ch
let i = requireAndSkipInterpolationHoleFormat (i+1)
// Note, the fragCol doesn't advance at all as these are magically inserted.
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ type PhasedDiagnostic with
| 1182 -> false // chkUnusedValue - off by default
| 3180 -> false // abImplicitHeapAllocation - off by default
| 3186 -> false // pickleMissingDefinition - off by default
| 3366 -> false //tcIndexNotationDeprecated - currently off by default
| 3366 -> false // tcIndexNotationDeprecated - currently off by default
| 3517 -> false // optFailedToInlineSuggestedValue - off by default
| 3388 -> false // tcSubsumptionImplicitConversionUsed - off by default
| 3389 -> false // tcBuiltInImplicitConversionUsed - off by default
| 3390 -> false // xmlDocBadlyFormed - off by default
| 3395 -> false // tcImplicitConversionUsedForMethodArg - off by default
| 3559 -> false // typrelNeverRefinedAwayFromTop - off by default
| 3579 -> false // alwaysUseTypedStringInterpolation - off by default
| _ ->
match x.Exception with
| DiagnosticEnabledWithLanguageFeature (_, _, _, enabled) -> enabled
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1721,3 +1721,4 @@ featureAccessorFunctionShorthand,"underscore dot shorthand for accessor only fun
3577,tcOverrideUsesMultipleArgumentsInsteadOfTuple,"This override takes a tuple instead of multiple arguments. Try to add an additional layer of parentheses at the method definition (e.g. 'member _.Foo((x, y))'), or remove parentheses at the abstract method declaration (e.g. 'abstract member Foo: 'a * 'b -> 'c')."
featureUnmanagedConstraintCsharpInterop,"Interop between C#'s and F#'s unmanaged generic constraint (emit additional modreq)"
3578,chkCopyUpdateSyntaxInAnonRecords,"This expression is an anonymous record, use {{|...|}} instead of {{...}}."
3579,alwaysUseTypedStringInterpolation,"Prefer to use typed interpolated strings over untyped one."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this message. Maybe something like this would be a bit better?

Suggested change
3579,alwaysUseTypedStringInterpolation,"Prefer to use typed interpolated strings over untyped one."
3579,alwaysUseTypedStringInterpolation,"Consider using typed interpolated strings over untyped ones."

or

Suggested change
3579,alwaysUseTypedStringInterpolation,"Prefer to use typed interpolated strings over untyped one."
3579,alwaysUseTypedStringInterpolation,"Consider adding type identifiers to the interpolated string."

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace ErrorMessages

open Xunit
open FSharp.Test.Compiler

module ``Typed interpolated strings`` =

[<Fact>]
let ``Untyped interpolated strings produce warning``() =
FSharp """
let hello = "Hello World"
printf $"{hello}"
"""
|> withWarnOn 3579
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Warning 3579, Line 3, Col 8, Line 3, Col 18, "Prefer to use typed interpolated strings over untyped one.")

[<Fact>]
let ``Do not warn on untyped interpolated strings by default``() =
FSharp """
let hello = "Hello World"
printf $"{hello}"
"""
|> typecheck
|> shouldSucceed

[<Fact>]
let ``Typed interpolated strings over interpolated one``() =
FSharp """
let hello = "Hello World"
printf $"%s{hello}"
"""
|> withWarnOn 3579
|> typecheck
|> shouldSucceed
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<Compile Include="EmittedIL\Structure\Structure.fs" />
<Compile Include="EmittedIL\TestFunctions\TestFunctions.fs" />
<Compile Include="EmittedIL\Tuples\Tuples.fs" />
<Compile Include="ErrorMessages\TypedInterpolatedStringsTests.fs" />
<!--<Compile Include="EmittedIL\StructDefensiveCopy\StructDefensiveCopy.fs" />-->
<Compile Include="ErrorMessages\UnsupportedAttributes.fs" />
<Compile Include="ErrorMessages\TailCallAttribute.fs" />
Expand Down