开发者

Disable compiler warnings per line

Is it possible to disable compiler warnings for specific lines?

In C#, this works:

[Obsolete]
class Old { }

#pragma warning disable 612
    var oldWi开发者_如何学运维thoutWarning = new Old();
#pragma warning restore 612
    var oldWithWarning = new Old();

This would be very useful for disabling incomplete pattern matches warnings, especially when a function accepts a particular case of a DU.


No, the warnings are turned off per-file (or possibly 'from here to the bottom of the file') when using #nowarn. (Or per compilation/project when using project properties / --nowarn command-line.)


Since everything is an expression in F# it's not hard to pull out a line or a part of a line and put it in it's own file.

Example of my issue, where :: pattern matching warned about empty list possiblity, but my state passed to Seq.fold always has a list with at least one item.

module FoldBookmarks
#nowarn "25"

let foldIntoBookmarks: (string * int * int) seq -> XamlReport.PDF.Bookmark seq = 
        Seq.fold (fun ((tl,pl,acc)::l) (t,p,_) -> (t,acc,p+acc)::((tl,pl,acc)::l)) [("",0,1)]
        >> Seq.map(fun (x,y,_) -> PDF.Bookmark(Title=x, PageNumber= System.Nullable(y)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜