Skip to content

Commit

Permalink
Create better error message for assignment on immutable - fixes dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed May 3, 2016
1 parent ce687a4 commit 550bf30
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ let MatchIncomplete2E() = DeclareResourceString("MatchIncomplete2","%s")
let MatchIncomplete3E() = DeclareResourceString("MatchIncomplete3","%s")
let MatchIncomplete4E() = DeclareResourceString("MatchIncomplete4","")
let RuleNeverMatchedE() = DeclareResourceString("RuleNeverMatched","")
let ValNotMutableE() = DeclareResourceString("ValNotMutable","")
let ValNotMutableE() = DeclareResourceString("ValNotMutable","%s")
let ValNotLocalE() = DeclareResourceString("ValNotLocal","")
let Obsolete1E() = DeclareResourceString("Obsolete1","")
let Obsolete2E() = DeclareResourceString("Obsolete2","%s")
Expand Down Expand Up @@ -1212,7 +1212,7 @@ let OutputPhasedErrorR (os:System.Text.StringBuilder) (err:PhasedError) =
if isComp then
os.Append(MatchIncomplete4E().Format) |> ignore
| PatternMatchCompilation.RuleNeverMatched _ -> os.Append(RuleNeverMatchedE().Format) |> ignore
| ValNotMutable _ -> os.Append(ValNotMutableE().Format) |> ignore
| ValNotMutable(_,valRef,_) -> os.Append(ValNotMutableE().Format(valRef.DisplayName)) |> ignore
| ValNotLocal _ -> os.Append(ValNotLocalE().Format) |> ignore
| ObsoleteError (s, _)
| ObsoleteWarning (s, _) ->
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@
<value>This rule will never be matched</value>
</data>
<data name="ValNotMutable" xml:space="preserve">
<value>This value is not mutable</value>
<value>Values are immutable by default. If you wish to mutate this value, you must explicitly declare it as a mutable variable using the mutable keyword: 'let mutable {0} = expression'.</value>
</data>
<data name="ValNotLocal" xml:space="preserve">
<value>This value is not local</value>
Expand Down
7 changes: 7 additions & 0 deletions tests/fsharpqa/Source/Warnings/AssingmentOnImmutable.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// #Warnings
//<Expects status="Error" span="(5,1)" id="FS0027">Values are immutable by default. If you wish to mutate this value, you must explicitly declare it as a mutable variable using the mutable keyword: 'let mutable x = expression'.</Expects>

let x = 10
x <- 20

exit 0
1 change: 1 addition & 0 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOURCE=AssingmentOnImmutable.fs # AssingmentOnImmutable.fs
1 change: 1 addition & 0 deletions tests/fsharpqa/Source/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Misc01 Libraries\Core\NativeInterop\stackalloc
Misc01 Libraries\Core\Operators
Misc01 Libraries\Core\Reflection
Misc01 Libraries\Core\Unchecked
Misc01 Warnings

Misc02 Libraries\Portable
Misc02 Misc
Expand Down

0 comments on commit 550bf30

Please sign in to comment.