2

次のコードは、それぞれでフォーマット警告をトリガーしますlet(「誤ったインデントの可能性」)。

module UtilTests =
    [<Test>] let simpleWithNth ()= true |> should be True
    [<Test>] let negIndex () = true |> should be True
    [<Test>] let tooBigIndex () = true |> should be True
    [<Test>] let lastIndex () = true |> should be True

以下はしません:

module UtilTests =
    [<Test>] let simpleWithNth ()= true |> should be True
     [<Test>] let negIndex () = true |> should be True
      [<Test>] let tooBigIndex () = true |> should be True
       [<Test>] let lastIndex () = true |> should be True

letそれぞれがその上のものよりもインデントされているのはなぜですか?(Visual Studio 2012を自動フォーマットする方法はありますか?)

4

1 に答える 1

5

ブライアンがコメントで述べたように、let関数に属性を適用する通常の方法は、letバインディングの前の行に属性を書き込むことです。関数の本体が同じ行にあるので、あなたが書いたコードが機能することも期待しますが、どうやらコンパイラはそうは思わないのです...。

letただし、例でうまく機能する関数に属性を適用する別の方法があります。

module UtilTests = 
  let [<Test>] simpleWithNth ()= true |> should be True 
  let [<Test>] negIndex () = true |> should be True 
  let [<Test>] tooBigIndex () = true |> should be True 
  let [<Test>] lastIndex () = true |> should be True 

このスタイルは、再帰関数を記述している場合に必要です。その場合、前の行の属性は機能せず、を記述する必要がありますlet rec [<Foo>] foo () = ... and [<Bar>] bar () = ...

于 2012-06-03T11:21:23.013 に答える