AttachMembers explicit constructors are skipped at call sites

オープン
#5,286 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
fsharp, javascript
領域
compilers

調査の方向性

Start by tracing how [<AttachMembers>] explicit constructors are emitted and how constructor calls are resolved in the Fable compiler; the issue does not name source files or tests. Reproduce the example on the JS target, including the base class case, then inspect or add coverage for overloads and field initialization. Done means generated calls use the explicit constructors and overloads remain distinct.

索引モデルが issue の本文から書いたものです。

説明

With [<AttachMembers>], calls to explicit constructors skip the constructor body. .NET prints 2 5, Fable on JS prints 0 5:

[<Fable.Core.AttachMembers>]
type V =
    val mutable X: int
    new () = { X = 2 }
    new (x: int) = { X = x }
    member this.Get() = this.X

printfn "%d %d" ((V()).Get()) ((V(5)).Get())

Generated JS:

export class V {
    constructor(X) {
        this.X = (X | 0);
    }
    static ".ctor"() {
        return new V(2);
    }
    static ".ctor"(x) {
        return new V(x);
    }
    Get() {
        const this$ = this;
        return this$.X | 0;
    }
}

const arg = (new V()).Get() | 0;
const arg_1 = (new V(5)).Get() | 0;

Two problems:

  • The call sites use new V(...) with the F# arguments instead of the explicit constructor, so V() never sets X = 2. V(5) is only right because its argument happens to match the field.
  • Every overload is emitted as static ".ctor", so the last one replaces the others.

The same happens with a base class, for example new () = { inherit B(1); X = 2 } in an [<AttachMembers>] class.

Reproduces on main. I only checked JS.

主要言語
F#
スター
3.2k
フォーク
335
平均マージ
19時間 39分
マージ済み PR(30日)
158

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fable-compiler/Fable のほかの issue

fable-compiler/Fable の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。