Skip to content

Commit

Permalink
Turn on unused warnings by default
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermp committed Jan 5, 2021
1 parent b23b2a0 commit ae20dc2
Show file tree
Hide file tree
Showing 31 changed files with 44 additions and 54 deletions.
3 changes: 1 addition & 2 deletions src/fsharp/CompilerDiagnostics.fs
Expand Up @@ -376,8 +376,7 @@ let warningOn err level specificWarnOn =
let n = GetDiagnosticNumber err
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
match n with
| 3180 -> false // abImplicitHeapAllocation - 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
4 changes: 1 addition & 3 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 @@ -556,7 +555,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 @@ -568,7 +566,7 @@ type public Fsc () as this =
| :? TargetInvocationException as tie when (match tie.InnerException with | :? Microsoft.Build.Exceptions.BuildAbortedException -> true | _ -> false) ->
fsc.Log.LogError(tie.InnerException.Message, [| |])
-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
| e -> reraise()
| _ -> reraise()

let baseCallDelegate = Func<int>(fun () -> fsc.BaseExecuteTool(pathToTool, responseFileCommands, commandLineCommands) )
try
Expand Down
11 changes: 1 addition & 10 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 @@ -305,7 +296,7 @@ type public Fsi () as this =
| :? TargetInvocationException as tie when (match tie.InnerException with | :? Microsoft.Build.Exceptions.BuildAbortedException -> true | _ -> false) ->
fsi.Log.LogError(tie.InnerException.Message, [| |])
-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
| e -> reraise()
| _ -> 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
1 change: 1 addition & 0 deletions tests/FSharp.Build.UnitTests/FSharp.Build.UnitTests.fsproj
Expand Up @@ -8,6 +8,7 @@
<OutputType>Library</OutputType>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<UnitTestType>nunit</UnitTestType>
<NoWarn>1182</NoWarn>
</PropertyGroup>

<ItemGroup>
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 @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1</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);3186;1104</NoWarn>
<NoWarn>$(NoWarn);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>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix'">netcoreapp3.1</TargetFrameworks>
<OutputType>Library</OutputType>
<NoWarn>1182</NoWarn>

<AssemblyName>FSharp.Core.UnitTests</AssemblyName>
<PackageId>Microsoft.FSharp.Core.UnitTests</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/FSharpSuite.Tests.fsproj
Expand Up @@ -13,7 +13,7 @@
<Tailcalls>false</Tailcalls>
<OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags>
<UnitTestType>nunit</UnitTestType>
<NoWarn>3186</NoWarn>
<NoWarn>3186;1182</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net472</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<OutputType>Library</OutputType>
<NoWarn>$(NoWarn);3005</NoWarn>
<NoWarn>$(NoWarn);3005;1182</NoWarn>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<UsePackageTargetFallbackHack>true</UsePackageTargetFallbackHack>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
Expand Down
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<OtherFlags>--nowarn:3390 --nowarn:3218</OtherFlags>
<OtherFlags>--nowarn:3390 --nowarn:3218 --nowarn:1182</OtherFlags>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion vsintegration/tests/Salsa/VisualFSharp.Salsa.fsproj
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<NoWarn>$(NoWarn);45;47;52;58;75</NoWarn>
<NoWarn>$(NoWarn);45;47;52;58;75;1182</NoWarn>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
<DefaultValueTuplePackageVersion>$(SystemValueTupleVersion)</DefaultValueTuplePackageVersion>
Expand Down
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net472</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<OutputType>Library</OutputType>
<NoWarn>$(NoWarn);44;58;75;3005</NoWarn>
<NoWarn>$(NoWarn);44;58;75;3005;1182</NoWarn>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
<DefaultValueTuplePackageVersion>$(SystemValueTupleVersion)</DefaultValueTuplePackageVersion>
Expand Down

0 comments on commit ae20dc2

Please sign in to comment.