problem with invert operator expression

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

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

Đánh giá

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

Hướng nghiên cứu

Start with the provided Python sample and compare the two generated JavaScript forms in a Firefox 133 environment. Trace how the compiler handles ~(obj) versus the __invert__() method call; done means the operator expression dispatches correctly without the reported TypeError and the behavior has a regression check.

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

Mô tả

IS: bug?

Expression with invert operator of an class instance causes error.

Error occurs with iobj = ~(obj) expression.
Browser error: Uncaught TypeError: Function.prototype.toString called on incompatible object.
Worked properly with iobj = obj.__invert__() expression.

python code:

class Obj:
    def __init__(self, x):
        self.x = x
    def __invert__(self):
        return ~self.x

# __pragma__ ('opov')
def op_invert():
    obj = Obj(42)
    if False:
        iobj = ~(obj)
# __pragma__ ('noopov')

op_invert()

compiled javascript code with ~(obj):

export var op_invert = function () {
	var obj = __call__ (Obj, null, 10);
	var iobj = ~(obj);
};

compiled javascript code with obj.__invert__():

export var op_invert = function () {
	var obj = __call__ (Obj, null, 10);
	var iobj = (function () {
		var __accu0__ = obj;
		return __call__ (__accu0__.__invert__, __accu0__);
	}) ();
};

env: Python3.9 venv with pip install Transcrypt
testing: Firefox version 133 in Linux

Ngôn ngữ chính
Python
Star
2.9k
Fork
218
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

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 TranscryptOrg/Transcrypt

Tất cả issue của TranscryptOrg/Transcrypt

Issue tương tự

Thêm issue về Python

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.