Fable icon indicating copy to clipboard operation
Fable copied to clipboard

TreatWarningsAsErrors does not treat warnings as errors

Open Wallace-Kelly opened this issue 4 years ago • 3 comments

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

Wallace-Kelly avatar Aug 27 '21 19:08 Wallace-Kelly

WarningsAsErrors doesn't seem to work anymore either.

inosik avatar Aug 28 '21 11:08 inosik

Treating warnings as errors was disabled for referenced projects, see #2288. But looks like this affects the actual project as well.

inosik avatar Aug 28 '21 11:08 inosik

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 🤔

alfonsogarciacaro avatar Sep 06 '21 01:09 alfonsogarciacaro