Skip to content

Commit 203d70e

Browse files
dsymeKevinRansom
authored andcommitted
show type of ignored expression (#4197)
* show type of ignored expression * fix tests * fix tests * fix test
1 parent 4f39f97 commit 203d70e

37 files changed

+190
-182
lines changed

src/fsharp/CompileOps.fs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,11 @@ let UseOfAddressOfOperatorE() = DeclareResourceString("UseOfAddressOfOperator",
532532
let DefensiveCopyWarningE() = DeclareResourceString("DefensiveCopyWarning", "%s")
533533
let DeprecatedThreadStaticBindingWarningE() = DeclareResourceString("DeprecatedThreadStaticBindingWarning", "")
534534
let FunctionValueUnexpectedE() = DeclareResourceString("FunctionValueUnexpected", "%s")
535-
let UnitTypeExpectedE() = DeclareResourceString("UnitTypeExpected", "")
536-
let UnitTypeExpectedWithEqualityE() = DeclareResourceString("UnitTypeExpectedWithEquality", "")
537-
let UnitTypeExpectedWithPossiblePropertySetterE() = DeclareResourceString("UnitTypeExpectedWithPossiblePropertySetter", "%s%s")
538-
let UnitTypeExpectedWithPossibleAssignmentE() = DeclareResourceString("UnitTypeExpectedWithPossibleAssignment", "%s")
539-
let UnitTypeExpectedWithPossibleAssignmentToMutableE() = DeclareResourceString("UnitTypeExpectedWithPossibleAssignmentToMutable", "%s")
535+
let UnitTypeExpectedE() = DeclareResourceString("UnitTypeExpected", "%s")
536+
let UnitTypeExpectedWithEqualityE() = DeclareResourceString("UnitTypeExpectedWithEquality", "%s")
537+
let UnitTypeExpectedWithPossiblePropertySetterE() = DeclareResourceString("UnitTypeExpectedWithPossiblePropertySetter", "%s%s%s")
538+
let UnitTypeExpectedWithPossibleAssignmentE() = DeclareResourceString("UnitTypeExpectedWithPossibleAssignment", "%s%s")
539+
let UnitTypeExpectedWithPossibleAssignmentToMutableE() = DeclareResourceString("UnitTypeExpectedWithPossibleAssignmentToMutable", "%s%s")
540540
let RecursiveUseCheckedAtRuntimeE() = DeclareResourceString("RecursiveUseCheckedAtRuntime", "")
541541
let LetRecUnsound1E() = DeclareResourceString("LetRecUnsound1", "%s")
542542
let LetRecUnsound2E() = DeclareResourceString("LetRecUnsound2", "%s%s")
@@ -1292,28 +1292,32 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
12921292
os.Append(DeprecatedThreadStaticBindingWarningE().Format) |> ignore
12931293

12941294
| FunctionValueUnexpected (denv, ty, _) ->
1295-
// REVIEW: consider if we need to show _cxs (the type parameter constraints)
12961295
let ty, _cxs = PrettyTypes.PrettifyType denv.g ty
1297-
os.Append(FunctionValueUnexpectedE().Format (NicePrint.stringOfTy denv ty)) |> ignore
1296+
let errorText = FunctionValueUnexpectedE().Format (NicePrint.stringOfTy denv ty)
1297+
os.Append errorText |> ignore
12981298

1299-
| UnitTypeExpected (_, _, _) ->
1300-
let warningText = UnitTypeExpectedE().Format
1299+
| UnitTypeExpected (denv, ty, _) ->
1300+
let ty, _cxs = PrettyTypes.PrettifyType denv.g ty
1301+
let warningText = UnitTypeExpectedE().Format (NicePrint.stringOfTy denv ty)
13011302
os.Append warningText |> ignore
13021303

1303-
| UnitTypeExpectedWithEquality (_) ->
1304-
let warningText = UnitTypeExpectedWithEqualityE().Format
1304+
| UnitTypeExpectedWithEquality (denv, ty, _) ->
1305+
let ty, _cxs = PrettyTypes.PrettifyType denv.g ty
1306+
let warningText = UnitTypeExpectedWithEqualityE().Format (NicePrint.stringOfTy denv ty)
13051307
os.Append warningText |> ignore
13061308

1307-
| UnitTypeExpectedWithPossiblePropertySetter (_, _, bindingName, propertyName, _) ->
1308-
let warningText = UnitTypeExpectedWithPossiblePropertySetterE().Format bindingName propertyName
1309+
| UnitTypeExpectedWithPossiblePropertySetter (denv, ty, bindingName, propertyName, _) ->
1310+
let ty, _cxs = PrettyTypes.PrettifyType denv.g ty
1311+
let warningText = UnitTypeExpectedWithPossiblePropertySetterE().Format (NicePrint.stringOfTy denv ty) bindingName propertyName
13091312
os.Append warningText |> ignore
13101313

1311-
| UnitTypeExpectedWithPossibleAssignment (_, _, isAlreadyMutable, bindingName, _) ->
1314+
| UnitTypeExpectedWithPossibleAssignment (denv, ty, isAlreadyMutable, bindingName, _) ->
1315+
let ty, _cxs = PrettyTypes.PrettifyType denv.g ty
13121316
let warningText =
13131317
if isAlreadyMutable then
1314-
UnitTypeExpectedWithPossibleAssignmentToMutableE().Format bindingName
1318+
UnitTypeExpectedWithPossibleAssignmentToMutableE().Format (NicePrint.stringOfTy denv ty) bindingName
13151319
else
1316-
UnitTypeExpectedWithPossibleAssignmentE().Format bindingName
1320+
UnitTypeExpectedWithPossibleAssignmentE().Format (NicePrint.stringOfTy denv ty) bindingName
13171321
os.Append warningText |> ignore
13181322

13191323
| RecursiveUseCheckedAtRuntime _ ->

src/fsharp/FSStrings.resx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,19 +886,19 @@
886886
<value>This expression is a function value, i.e. is missing arguments. Its type is {0}.</value>
887887
</data>
888888
<data name="UnitTypeExpected" xml:space="preserve">
889-
<value>The result of this expression is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.</value>
889+
<value>The result of this expression has type '{0}' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.</value>
890890
</data>
891891
<data name="UnitTypeExpectedWithEquality" xml:space="preserve">
892-
<value>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'.</value>
892+
<value>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'.</value>
893893
</data>
894894
<data name="UnitTypeExpectedWithPossiblePropertySetter" xml:space="preserve">
895-
<value>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '&lt;-' operator e.g. '{0}.{1} &lt;- expression'.</value>
895+
<value>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '&lt;-' operator e.g. '{1}.{2} &lt;- expression'.</value>
896896
</data>
897897
<data name="UnitTypeExpectedWithPossibleAssignment" xml:space="preserve">
898-
<value>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then mark the value 'mutable' and use the '&lt;-' operator e.g. '{0} &lt;- expression'.</value>
898+
<value>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then mark the value 'mutable' and use the '&lt;-' operator e.g. '{1} &lt;- expression'.</value>
899899
</data>
900900
<data name="UnitTypeExpectedWithPossibleAssignmentToMutable" xml:space="preserve">
901-
<value>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then use the '&lt;-' operator e.g. '{0} &lt;- expression'.</value>
901+
<value>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then use the '&lt;-' operator e.g. '{1} &lt;- expression'.</value>
902902
</data>
903903
<data name="RecursiveUseCheckedAtRuntime" xml:space="preserve">
904904
<value>This recursive use will be checked for initialization-soundness at runtime. This warning is usually harmless, and may be suppressed by using '#nowarn "21"' or '--nowarn:21'.</value>

src/fsharp/service/service.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,10 @@ module internal Parser =
15191519
if source.Length = 0 || not (source.[source.Length - 1] = '\n') then source + "\n" else source
15201520

15211521
let matchBraces(source, fileName, options: FSharpParsingOptions, userOpName: string) =
1522+
let delayedLogger = CapturingErrorLogger("matchBraces")
1523+
use _unwindEL = PushErrorLoggerPhaseUntilUnwind (fun _ -> delayedLogger)
1524+
use _unwindBP = PushThreadBuildPhaseUntilUnwind BuildPhase.Parse
1525+
15221526
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "matchBraces", fileName)
15231527

15241528
// Make sure there is an ErrorLogger installed whenever we do stuff that might record errors, even if we ultimately ignore the errors

src/fsharp/xlf/FSStrings.cs.xlf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,28 +1283,28 @@
12831283
<note />
12841284
</trans-unit>
12851285
<trans-unit id="UnitTypeExpected">
1286-
<source>The result of this expression is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |&gt; ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.</source>
1287-
<target state="translated">Výsledek tohoto výrazu se implicitně ignoruje. Zvažte možnost použít ignore, aby se tato hodnota explicitně zahodila, třeba expr |&gt; ignore, nebo let, aby se výsledek svázal s názvem, třeba let result = expr.</target>
1286+
<source>The result of this expression has type '{0}' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |&gt; ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.</source>
1287+
<target state="needs-review-translation">Výsledek tohoto výrazu se implicitně ignoruje. Zvažte možnost použít ignore, aby se tato hodnota explicitně zahodila, třeba expr |&gt; ignore, nebo let, aby se výsledek svázal s názvem, třeba let result = expr.</target>
12881288
<note />
12891289
</trans-unit>
12901290
<trans-unit id="UnitTypeExpectedWithEquality">
1291-
<source>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'.</source>
1292-
<target state="translated">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz.</target>
1291+
<source>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'.</source>
1292+
<target state="needs-review-translation">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz.</target>
12931293
<note />
12941294
</trans-unit>
12951295
<trans-unit id="UnitTypeExpectedWithPossiblePropertySetter">
1296-
<source>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '&lt;-' operator e.g. '{0}.{1} &lt;- expression'.</source>
1297-
<target state="translated">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz. Pokud jste chtěli nastavit hodnotu na vlastnost, použijte operátor &lt;-, např. {0}.{1} &lt;- výraz.</target>
1296+
<source>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '&lt;-' operator e.g. '{1}.{2} &lt;- expression'.</source>
1297+
<target state="needs-review-translation">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz. Pokud jste chtěli nastavit hodnotu na vlastnost, použijte operátor &lt;-, např. {1}.{2} &lt;- výraz.</target>
12981298
<note />
12991299
</trans-unit>
13001300
<trans-unit id="UnitTypeExpectedWithPossibleAssignment">
1301-
<source>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then mark the value 'mutable' and use the '&lt;-' operator e.g. '{0} &lt;- expression'.</source>
1302-
<target state="translated">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz. Pokud jste chtěli mutovat hodnotu, označte hodnotu jako mutable a použijte operátor &lt;-, např. {0} &lt;- výraz.</target>
1301+
<source>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then mark the value 'mutable' and use the '&lt;-' operator e.g. '{1} &lt;- expression'.</source>
1302+
<target state="needs-review-translation">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz. Pokud jste chtěli mutovat hodnotu, označte hodnotu jako mutable a použijte operátor &lt;-, např. {1} &lt;- výraz.</target>
13031303
<note />
13041304
</trans-unit>
13051305
<trans-unit id="UnitTypeExpectedWithPossibleAssignmentToMutable">
1306-
<source>The result of this equality expression is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then use the '&lt;-' operator e.g. '{0} &lt;- expression'.</source>
1307-
<target state="translated">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz. Pokud jste chtěli mutovat hodnotu, použijte operátor &lt;-, např. {0} &lt;- výraz.</target>
1306+
<source>The result of this equality expression has type '{0}' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then use the '&lt;-' operator e.g. '{1} &lt;- expression'.</source>
1307+
<target state="needs-review-translation">Výsledek tohoto výrazu rovnosti se implicitně zruší. Zvažte vytvoření vazby mezi výsledkem a názvem pomocí klíčového slova let, např. let výsledek = výraz. Pokud jste chtěli mutovat hodnotu, použijte operátor &lt;-, např. {1} &lt;- výraz.</target>
13081308
<note />
13091309
</trans-unit>
13101310
<trans-unit id="RecursiveUseCheckedAtRuntime">

0 commit comments

Comments
 (0)