AttachMembers explicit constructors are skipped at call sites

Đang mở
#5,286 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
fsharp, javascript
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
F#
Star
3.2k
Fork
335
Merge trung bình
19 giờ 39 phút
Pull request đã merge (30 ngày)
158

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fable-compiler/Fable

Tất cả issue của fable-compiler/Fable

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.