TreatWarningsAsErrors does not treat warnings as errors
Description
When the property <TreatWarningsAsErrors>true</TreatWarningsAsErrors> is included in the fsproj file, the Fable compiler still issues warnings instead of errors.
Repro code
Test.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include="Library.fs" />
</ItemGroup>
</Project>
Library.fs
module WarnAsErrorTest
type Message = Load | Save | Exit
let message =
function
| Load -> printfn "Loading"
| Save -> printfn "Saving"
Expected and actual results
Expected
Running dotnet fable should print an error message.
Actual
Running dotnet build does print an error message.
Running dotnet fable does not print an error message.
Related information
- Fable version:
dotnet fable --version: 3.2.12 - Operating system: Windows
WarningsAsErrors doesn't seem to work anymore either.
Treating warnings as errors was disabled for referenced projects, see #2288. But looks like this affects the actual project as well.
I've sent #2527 to fix this. This ignores TreatWarningsAsErrors if set in a project reference (or package) and only takes it into account if set into the main project. However the tricky part is Fable collects all sources (including project references and package sources) into a single project, so setting TreatWarningsAsErrors in the main project will turn warnings into errors in project references and packages as well, which is likely breaking. In fact, Fable currently ignores warnings from packages.
Not sure what's the best solution here, Fable could ignore errors from packages too, but this will likely produce false negatives 🤔