Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Turn unused value warnings on by default #10546

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions FSharpBuild.Directory.Build.props
Expand Up @@ -19,8 +19,8 @@
<SymStoreDirectory>$(ArtifactsDir)\SymStore</SymStoreDirectory>
<ProtoOutputPath>$(ArtifactsDir)\Bootstrap</ProtoOutputPath>
<ValueTupleImplicitPackageVersion>4.4.0</ValueTupleImplicitPackageVersion>
<WarningsAsErrors>1182;0025;$(WarningsAsErrors)</WarningsAsErrors>
<OtherFlags>$(OtherFlags) --nowarn:3384</OtherFlags>
<WarningsAsErrors>0025;$(WarningsAsErrors)</WarningsAsErrors>
<OtherFlags>$(OtherFlags) --warnaserror --nowarn:3384</OtherFlags>
</PropertyGroup>

<!-- nuget -->
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/CompilerDiagnostics.fs
Expand Up @@ -372,7 +372,6 @@ let warningOn err level specificWarnOn =
List.contains n specificWarnOn ||
// Some specific warnings are never on by default, i.e. unused variable warnings
match n with
| 1182 -> false // chkUnusedValue - off by default
| 3180 -> false // abImplicitHeapAllocation - off by default
| 3517 -> false // optFailedToInlineSuggestedValue - off by default
| _ -> level >= GetWarningLevel err
Expand Down
Expand Up @@ -19,7 +19,7 @@ type CreateFSharpManifestResourceName public () =
(linkFileName:string),
(rootNamespace:string), (* may be null *)
(dependentUponFileName:string), (* may be null *)
(binaryStream:System.IO.Stream) (* may be null *)) : string =
(_binaryStream:System.IO.Stream) (* may be null *)) : string =

// The Visual CSharp and XBuild CSharp toolchains transform resource names like this:
// SubDir\abc.resx --> SubDir.abc.resources
Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/FSharp.Build/FSharpEmbedResourceText.fs
Expand Up @@ -356,7 +356,7 @@ open Printf
printMessage (sprintf "Reading %s" filename)
let lines = File.ReadAllLines(filename)
|> Array.mapi (fun i s -> i,s) // keep line numbers
|> Array.filter (fun (i,s) -> not(s.StartsWith "#")) // filter out comments
|> Array.filter (fun (_,s) -> not(s.StartsWith "#")) // filter out comments

printMessage (sprintf "Parsing %s" filename)
let stringInfos = lines |> Array.map (fun (i,s) -> ParseLine filename i s)
Expand Down Expand Up @@ -391,7 +391,7 @@ open Printf

printMessage (sprintf "Generating resource methods for %s" outFilename)
// gen each resource method
stringInfos |> Seq.iter (fun (lineNum, (optErrNum,ident), str, holes, netFormatString) ->
stringInfos |> Seq.iter (fun (lineNum, (optErrNum,ident), str, holes, _) ->
let formalArgs = new System.Text.StringBuilder()
let actualArgs = new System.Text.StringBuilder()
let mutable firstTime = true
Expand Down Expand Up @@ -428,14 +428,14 @@ open Printf
// gen validation method
fprintfn out " /// Call this method once to validate that all known resources are valid; throws if not"
fprintfn out " static member RunStartupValidation() ="
stringInfos |> Seq.iter (fun (lineNum, (optErrNum,ident), str, holes, netFormatString) ->
stringInfos |> Seq.iter (fun (_, (_,ident), _, _, _) ->
fprintfn out " ignore(GetString(\"%s\"))" ident
)
fprintfn out " ()" // in case there are 0 strings, we need the generated code to parse
// gen to resx
let xd = new System.Xml.XmlDocument()
xd.LoadXml(xmlBoilerPlateString)
stringInfos |> Seq.iter (fun (lineNum, (optErrNum,ident), str, holes, netFormatString) ->
stringInfos |> Seq.iter (fun (_, (_,ident), _, _, netFormatString) ->
let xn = xd.CreateElement("data")
xn.SetAttribute("name",ident) |> ignore
xn.SetAttribute("xml:space","preserve") |> ignore
Expand Down
6 changes: 2 additions & 4 deletions src/fsharp/FSharp.Build/Fsc.fs
Expand Up @@ -63,7 +63,6 @@ type public Fsc () as this =
let mutable tailcalls : bool = true
let mutable targetProfile : string = null
let mutable targetType : string = null
let mutable toolExe : string = "fsc.exe"
let defaultToolPath =
let locationOfThisDll =
try Some(Path.GetDirectoryName(typeof<Fsc>.Assembly.Location))
Expand Down Expand Up @@ -577,7 +576,6 @@ type public Fsc () as this =
match host with
| null -> base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands)
| _ ->
let sources = sources|>Array.map(fun i->i.ItemSpec)
let invokeCompiler baseCallDelegate =
try
let ret =
Expand All @@ -590,8 +588,8 @@ type public Fsc () as this =
// Do a string compare on the type name to do eliminate a compile time dependency on Microsoft.Build.dll
| :? TargetInvocationException as tie when not (isNull tie.InnerException) && (tie.InnerException).GetType().FullName = "Microsoft.Build.Exceptions.BuildAbortedException" ->
fsc.Log.LogError(tie.InnerException.Message, [| |])
-1
| e -> reraise()
-1 // ok, this is what happens when VS IDE cancels the build, no need to assert, just log the build-canceled error and return -1 to denote task failed
| _ -> reraise()

let baseCallDelegate = Func<int>(fun () -> fsc.BaseExecuteTool(pathToTool, responseFileCommands, commandLineCommands) )
try
Expand Down
13 changes: 2 additions & 11 deletions src/fsharp/FSharp.Build/Fsi.fs
Expand Up @@ -37,15 +37,12 @@ type public Fsi () as this =
let mutable provideCommandLineArgs = false
let mutable references : ITaskItem[] = [||]
let mutable referencePath : string = null
let mutable resources : ITaskItem[] = [||]
let mutable skipCompilerExecution = false
let mutable sources : ITaskItem[] = [||]
let mutable loadSources : ITaskItem[] = [||]
let mutable useSources : ITaskItem[] = [||]
let mutable tailcalls : bool = true
let mutable targetProfile : string = null
let mutable targetType : string = null
let mutable toolExe : string = "fsi.exe"
let mutable toolPath : string =
let locationOfThisDll =
try Some(Path.GetDirectoryName(typeof<Fsi>.Assembly.Location))
Expand Down Expand Up @@ -85,11 +82,6 @@ type public Fsi () as this =
for item in references do
builder.AppendSwitchIfNotNull("-r:", item.ItemSpec)

let referencePathArray = // create a array of strings
match referencePath with
| null -> null
| _ -> referencePath.Split([|';'; ','|], StringSplitOptions.RemoveEmptyEntries)

// NoWarn
match disabledWarnings with
| null -> ()
Expand Down Expand Up @@ -293,7 +285,6 @@ type public Fsi () as this =
match host with
| null -> base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands)
| _ ->
let sources = sources|>Array.map(fun i->i.ItemSpec)
let invokeCompiler baseCallDelegate =
try
let ret =
Expand All @@ -306,8 +297,8 @@ type public Fsi () as this =
// Do a string compare on the type name to do eliminate a compile time dependency on Microsoft.Build.dll
| :? TargetInvocationException as tie when not (isNull tie.InnerException) && (tie.InnerException).GetType().FullName = "Microsoft.Build.Exceptions.BuildAbortedException" ->
fsi.Log.LogError(tie.InnerException.Message, [| |])
-1
| e -> reraise()
-1 // ok, this is what happens when VS IDE cancels the build, no need to assert, just log the build-canceled error and return -1 to denote task failed
| _ -> reraise()

let baseCallDelegate = Func<int>(fun () -> fsi.BaseExecuteTool(pathToTool, responseFileCommands, commandLineCommands) )
try
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Build/MapSourceRoots.fs
Expand Up @@ -122,7 +122,7 @@ type MapSourceRoots () =

for root in mappedSourceRoots do
match root.GetMetadata SourceControl with
| HasValue v when isSourceControlled -> mapNestedRootIfEmpty root
| HasValue _ when isSourceControlled -> mapNestedRootIfEmpty root
| NullOrEmpty when not isSourceControlled -> mapNestedRootIfEmpty root
| _ -> ()

Expand Down
Expand Up @@ -37,7 +37,7 @@ type internal FSharpInteractiveServer() =
LifetimeServices.RenewOnCallTime <- TimeSpan(7,0,0,0);
LifetimeServices.SponsorshipTimeout <- TimeSpan(7,0,0,0);
ChannelServices.RegisterChannel(chan,false);
let objRef = RemotingServices.Marshal(server,"FSIServer")
RemotingServices.Marshal(server,"FSIServer") |> ignore
()

static member StartClient(channelName) =
Expand Down
Expand Up @@ -8,6 +8,7 @@
<OutputType>Library</OutputType>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<UnitTestType>nunit</UnitTestType>
<NoWarn>$(NoWarn);1182</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -20,6 +20,7 @@ type C() =
member _.G() = ()
"""
|> FSharp
|> withOptions ["--nowarn:1182"]
|> typecheck
|> shouldFail
|> withResults [
Expand Down
Expand Up @@ -70,7 +70,7 @@ let changeProperty() =
[<Fact>]
let ``Don't Warn If Property Without Setter``() =
FSharp """
type MyClass(property1 : int) =
type MyClass(_property1 : int) =
member val Property2 = "" with get

let x = MyClass(1)
Expand Down
Expand Up @@ -4,9 +4,9 @@

type R =
{ x: int }
member this.Equals(s:char) = true
member this.Equals(_:char) = true
// member this.Equals(s:R) = 1.
member this.Equals(?s:char) = true
member this.Equals(?_s:char) = true

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -3,9 +3,9 @@
// Overloading of GetHashCode()
type R =
{ x: int }
member this.GetHashCode(s:char) = 1
member this.GetHashCode(_s:char) = 1
//member this.GetHashCode() = 1.
member this.GetHashCode(?s:char) = 1
member this.GetHashCode(?_s:char) = 1

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -4,9 +4,9 @@

type R =
{ x: int }
member this.ToString(s:char) = true
member this.ToString(_s:char) = true
member this.ToString() = true
member this.ToString(?s:char) = true
member this.ToString(?_s:char) = true

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -3,9 +3,9 @@
// Overloading of Equals()

type DU = | A
member this.Equals(s:char) = true
member this.Equals(_s:char) = true
//member this.Equals(s:DU) = 1.
member this.Equals(?s:char) = true
member this.Equals(?_s:char) = true

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -3,9 +3,9 @@
// Overloading of GetHashCode()

type DU = | A
member this.GetHashCode(s:char) = 1
member this.GetHashCode(_s:char) = 1
//member this.GetHashCode() = 1.
member this.GetHashCode(?s:char) = 1
member this.GetHashCode(?_s:char) = 1

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -3,9 +3,9 @@
// Overloading of ToString()

type DU = | A
member this.ToString(s:char) = true
member this.ToString(_s:char) = true
member this.ToString() = true
member this.ToString(?s:char) = true
member this.ToString(?_s:char) = true

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -9,4 +9,4 @@
type ID<'T> =
static member id (x:'T) = x

let f x = ID<ID<int>>.id (* ok *)
let f _x = ID<ID<int>>.id (* ok *)
Expand Up @@ -9,4 +9,4 @@
type ID<'T> =
static member id (x:'T) = x

let f x = ID<ID<int>> .id (* ok *)
let f _x = ID<ID<int>> .id (* ok *)
Expand Up @@ -10,7 +10,7 @@ async {
return 5
}
)
let! b = a
for i in 1..10000 do
let! _b = a
for _ in 1..10000 do
()
} |> Async.RunSynchronously
Expand Up @@ -4,9 +4,9 @@

[<Struct>]
type S3 =
member this.Equals(s:char) = true
member this.Equals(_s:char) = true
//member this.Equals(s:S3) = 1.
member this.Equals(?s:char) = true
member this.Equals(?_s:char) = true

#if INTERACTIVE
;;
Expand Down
Expand Up @@ -4,9 +4,9 @@

[<Struct>]
type S2 =
member this.GetHashCode(s:char) = 1
member this.GetHashCode(_s:char) = 1
//member this.GetHashCode() = 1.
member this.GetHashCode(?s:char) = 1
member this.GetHashCode(?_s:char) = 1

#if INTERACTIVE
;;
Expand Down
Expand Up @@ -4,9 +4,9 @@

[<Struct>]
type S1 =
member this.ToString(s:char) = true
member this.ToString(_s:char) = true
member this.ToString() = true
member this.ToString(?s:char) = true
member this.ToString(?_s:char) = true

#if INTERACTIVE
exit 0;;
Expand Down
Expand Up @@ -18,7 +18,7 @@ let variance xs = let m = mean xs in meanMap (fun x -> sqr (x-m)) xs
let sdeviation xs = sqrt (variance xs)

let skewness xs =
let n = float (List.length xs)
let _n = float (List.length xs)
let m = mean xs
let s = sdeviation xs
meanMap (fun x -> cube(x-m)) xs / (cube s)
Expand Down
Expand Up @@ -5,7 +5,7 @@

type SC< [<Measure>] 'u>() = class end
type TC< [<Measure>] 'u>() = inherit SC<'u>()
let wff (x:SC<'u>) = ()
let wff (_x:SC<'u>) = ()


let wgg (x:TC<'v>) = wff x // OK
Expand Down
Expand Up @@ -8,6 +8,7 @@
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<UnitTestType>xunit</UnitTestType>
<ExcludeFromSourceBuild>true</ExcludeFromSourceBuild>
<NoWarn>$(NoWarn);1182</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -418,7 +418,7 @@ let y = 2
foundInner <- foundInner || name = "inner")
let code = @"
let x =
let inner = 1
let _inner = 1
()
"
script.Eval(code) |> ignoreValue
Expand Down
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFrameworks Condition="'$(OS)' != 'Unix'">net472;net5.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix'">net5.0</TargetFrameworks>
<NoWarn>$(NoWarn);44;75;</NoWarn>
<NoWarn>$(NoWarn);44;75;1182;</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateProgramFile>false</GenerateProgramFile>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
Expand Down
Expand Up @@ -9,7 +9,7 @@
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DefineConstants>$(DefineConstants);ASSUME_PREVIEW_FSHARP_CORE</DefineConstants>
<UnitTestType>xunit</UnitTestType>
<NoWarn>$(NoWarn);57;3186;1104</NoWarn>
<NoWarn>$(NoWarn);57;3186;1104;1182;</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/FSharp.Core.UnitTests.fsproj
Expand Up @@ -6,6 +6,7 @@
<TargetFrameworks>net5.0;net472</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix'">net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<NoWarn>$(NoWarn);1182</NoWarn>

<AssemblyName>FSharp.Core.UnitTests</AssemblyName>
<PackageId>Microsoft.FSharp.Core.UnitTests</PackageId>
Expand Down
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<NoWarn>$(NoWarn);1182</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions tests/benchmarks/MicroPerf/MicroPerf.fsproj
Expand Up @@ -11,6 +11,8 @@
<OtherFlags>$(OtherFlags) --langversion:preview</OtherFlags>
<OtherFlags>$(OtherFlags) --define:PREVIEW</OtherFlags>

<NoWarn>$(NoWarn);1182</NoWarn>

<!-- By default this project will compile with the proto compiler -->
<!-- Uncommenting this will build with a previous installed compiler -->
<!--
Expand Down
3 changes: 3 additions & 0 deletions tests/benchmarks/TaskPerf/TaskPerf.fsproj
Expand Up @@ -13,6 +13,9 @@
<OtherFlags>$(OtherFlags) --nowarn:3511 --nowarn:3513</OtherFlags>
<OtherFlags>$(OtherFlags) --langversion:preview</OtherFlags>
<OtherFlags>$(OtherFlags) --define:PREVIEW</OtherFlags>

<NoWarn>$(NoWarn);1182</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down