`allows ref struct` type parameters accept `'T byref` arguments: `int byref seq` compiles on net9.0+ and fails with `TypeLoadException`
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- fsharp
- 領域
- compilers
調査の方向性
Read src/Compiler/Checking/PostInferenceChecks.fs, especially ByrefTypeCheck.VisitTyconRef and the PermitByRefType branches. Compare the byref and byref-like checks with the repro in the issue, then build the library targeting net9.0 and verify the expected FS3300 errors for f and g. Done when managed-pointer type arguments are rejected while byref-like structs remain permitted.
索引モデルが issue の本文から書いたものです。
説明
Since F# 9 (#17706, consuming allows ref struct generic parameters) the post-inference byref checks skip a type argument entirely when its type parameter is allows ref struct. That lets managed-pointer types through (byref<T>, inref<T>, outref<T>), not only byref-like structs. On .NET 9 and later IEnumerable<T>, IEnumerator<T>, Func<> and Action<> carry AllowByRefLike, so seq<byref<int>> type-checks, IL is emitted, and the runtime rejects it at type load.
Repro steps
module Lib
let f xs = for x: int byref in xs do () // inferred xs: seq<byref<int>>, no error
let g (xs: seq<byref<int>>) = () // no error
let h (xs: byref<int> list) = () // FS3300, as expected
- Put the file in a library project with
<TargetFramework>net9.0</TargetFramework>(same withnet10.0andnet11.0) and rundotnet build. Onlyhreports an error. - Reflect over
Lib.gin the built assembly:
System.TypeLoadException: The generic type 'System.Collections.Generic.IEnumerable`1' was used with an invalid instantiation in assembly 'System.Private.CoreLib, Version=11.0.0.0'
- In
dotnet fsi,let f xs = for x: int byref in xs do ()printsval f: xs: byref<int> seq -> unit. Any use offthen fails:
error FS0193: internal error: Unable to load one or more of the requested types.
The generic type 'System.Collections.Generic.IEnumerable`1' was used with an invalid instantiation
Expected behavior
The same errors as with net8.0, where the file reports FS3300 for f, g and h and FS0412 at the loop. allows ref struct permits byref-like structs such as Span<T>; it never permits managed pointers (ECMA-335 II.9.4).
Actual behavior
f and g compile on net9.0, net10.0, net11.0 and in fsi. The output fails at type load.
Cause
src/Compiler/Checking/PostInferenceChecks.fs, ByrefTypeCheck.VisitTyconRef: the guard if not (ctx.TyparAllowsRefStruct()) then wraps all four PermitByRefType branches, including the isByrefTyconRef test in the SpanLike branch and the byref part of isByrefLikeTyconRef in the other branches. The anti-constraint should relax only the byref-like test; a byref type argument must still be an error. Introduced in bb027e1378.
Known workarounds
None needed: the code cannot run. Found while writing fslang-design#845 (RFC FS-1348), whose compatibility section assumed this form is always a compile-time error.
Related information
- Windows 11, .NET SDK 11.0.100-rc.1.26420.103 and its F# compiler;
net8.0build of the same file reports the errors. - On .NET 11:
typedefof<seq<_>>.GetGenericArguments().[0].GenericParameterAttributes=Covariant, AllowByRefLike.
- 主要言語
- F#
- スター
- 4.3k
- フォーク
- 883
- 平均マージ
- 3日 4時間
- マージ済み PR(30日)
- 88
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/fsharp のほかの issue
-
Needs-Triage
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 2 日以内に返信
-
Semantic classification cache for opened documents is never populated (written to the unopened-documents cache)対応中かも @xperiandri が 64 日前に担当しました。 オープンNeeds-Triage
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 2 日以内に返信
-
Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/fsharp#20265 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Bug Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
Needs-Triage
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
JakeChampion/lang#14392 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
swc-project/swc-ai-issues#114 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
fable-compiler/Fable#5280 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
compiler: `void` inside a constant array or object literal throws in `PureFunctionConstant.keyOf`オープンarea: compiler
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信