配列を匿名手順で並べ替える

投稿者:shogo314 投稿日:2025/05/16(Fri) 11:03:56 No.2477

2.0.1318のコンパイラで以下のコードが実行時にエラーになります。

```
一覧は{「bb」,「ccc」,「a」}
一覧を『
  それを{左,右}とみなす
  左の文字数が右の文字数より小さいなら
    -1を返す
  他で左の文字数が右の文字数より大きいなら
    1を返す
  そうでなければ
    0を返す
  そして
』で並べ替える
一覧を表示する
```

出力
```
エラーが発生しました。
予期しないエラーが発生しました。申し訳ありません。
原因:InvalidOperationException
Failed to compare two elements in the array.


at System.Collections.Generic.ArraySortHelper`1[T].Sort (T[] keys, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer`1[T] comparer) [0x0003c] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Array.Sort[T] (T[] array, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer`1[T] comparer) [0x0004d] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.List`1[T].Sort (System.Int32 index, System.Int32 count, System.Collections.Generic.IComparer`1[T] comparer) [0x0002b] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.List`1[T].Sort (System.Collections.Generic.IComparer`1[T] comparer) [0x00008] in <d636f104d58046fd9b195699bcb1a744>:0
at Produire.CoreLibrary.配列`1[T].5[0] (System.Collections.Generic.IComparer`1[T] 0) [0x0001b] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at Produire.CoreLibrary.配列`1[T].並べ替える (Produire.PDelegate 比較手順, Produire.IScope scope) [0x00008] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at Main.広域種類.MainCode () [0x0004a] in <824db43bc73d48d9bf70ac7300e600df>:0
at Main.メイン種類.起動 () [0x0000b] in <824db43bc73d48d9bf70ac7300e600df>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Failed to compare two elements in the array. ---> System.NullReferenceException: Object reference not set to an instance of an object
at Produire.RdrCallSite.3 (System.Object& 0) [0x00039] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at Produire.RdrCallSite.GetValue (System.Object target, System.String memberName) [0x00000] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at Main.広域種類+Block_1.Invoke[T] (Produire.IScope , System.Object[] args) [0x00004] in <824db43bc73d48d9bf70ac7300e600df>:0
at Produire.RdrCustomComparer`1[T].Compare (T x, T y) [0x00000] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at System.Collections.Generic.ArraySortHelper`1[T].SwapIfGreater (T[] keys, System.Comparison`1[T] comparer, System.Int32 a, System.Int32 b) [0x00004] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.ArraySortHelper`1[T].IntroSort (T[] keys, System.Int32 lo, System.Int32 hi, System.Int32 depthLimit, System.Comparison`1[T] comparer) [0x00028] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.ArraySortHelper`1[T].IntrospectiveSort (T[] keys, System.Int32 left, System.Int32 length, System.Comparison`1[T] comparer) [0x00013] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.ArraySortHelper`1[T].Sort (T[] keys, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer`1[T] comparer) [0x0001c] in <d636f104d58046fd9b195699bcb1a744>:0
--- End of inner exception stack trace ---
at System.Collections.Generic.ArraySortHelper`1[T].Sort (T[] keys, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer`1[T] comparer) [0x0003c] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Array.Sort[T] (T[] array, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer`1[T] comparer) [0x0004d] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.List`1[T].Sort (System.Int32 index, System.Int32 count, System.Collections.Generic.IComparer`1[T] comparer) [0x0002b] in <d636f104d58046fd9b195699bcb1a744>:0
at System.Collections.Generic.List`1[T].Sort (System.Collections.Generic.IComparer`1[T] comparer) [0x00008] in <d636f104d58046fd9b195699bcb1a744>:0
at Produire.CoreLibrary.配列`1[T].5[0] (System.Collections.Generic.IComparer`1[T] 0) [0x0001b] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at Produire.CoreLibrary.配列`1[T].並べ替える (Produire.PDelegate 比較手順, Produire.IScope scope) [0x00008] in <10e5d7ba84e2472a81af39cdd3a57a8a>:0
at Main.広域種類.MainCode () [0x0004a] in <824db43bc73d48d9bf70ac7300e600df>:0
at Main.メイン種類.起動 () [0x0000b] in <824db43bc73d48d9bf70ac7300e600df>:0
at Main.メイン種類.Main () [0x00000] in <824db43bc73d48d9bf70ac7300e600df>:0
```

修正しました(2.0.1319)

投稿者:ゆうと 投稿日:2025/05/17(Sat) 01:45:33 No.2478

こんにちは お世話になっております。

> 2.0.1318のコンパイラで以下のコードが実行時にエラーになります。

こちら現象再現できました。
早速ですが2.0.1319にて修正反映しました。
ありがとうございます。

▲ページの先頭へ

- WebForum -