Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Null<UInt> compared with null gives wrong results (null is cast to 0 by UInt's == / != overloads)

Đang mở
#1,427 1 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
1-2 ngày
Mức phù hợp với người mới
57/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend, compilers

Hướng nghiên cứu

Start with std/UInt.hx and inspect the == and != overloads described in the issue; reproduce the case on the cpp target using Haxe 4.3.7 and hxcpp 4.3.2. Compare the generated C++ with the Null<Int> behavior and check whether the null literal reaches the overload. Done means Null<UInt> comparisons with null and 0 match the expected results on cpp.

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

Mô tả

Haxe 4.3.7, hxcpp 4.3.2, Windows 11 (MSVC)

On the cpp target, comparing a Null<UInt> that holds null against null gives the wrong result. The value also compares equal to 0. HashLink, JS and eval give the expected results.

class Main {
	static function get():Null<UInt> return null;

	static function main() {
		var u:Null<UInt> = get();
		trace(u == null); // expected true
		trace(u != null); // expected false
		trace(u == 0);    // expected false
		trace((u : Dynamic) == null); // true
	}
}
cpp hl / js / inter
u == null false true
u != null true false
u == 0 true false
(u : Dynamic) == null true true

Cause: on cpp, UInt is the non-core abstract UInt(Int) from std/UInt.hx. u == null resolves to the @:commutative @:op(A == B) equalsInt<T:Int>(a:UInt, b:T) overload, a.toInt() == b. The inline toInt() becomes a C++ cast that unboxes the null to 0 before comparing:

::hx::IsEq( ( (int)(u) ),b )      // u == null
::hx::IsNotEq( ( (int)(u) ),b1 )  // u != null

Null<Int> isn't affected, since it has no overloads and compiles to ::hx::IsNull(i).

Expected: comparing a Null<UInt> with null should be a null check, as on the other targets. For example, the ==/!= overloads shouldn't apply when the other operand is the null literal, or the generated code should test for null before the (int) cast.

Workaround: compare through Dynamic: (u : Dynamic) == null.

Impact: any API returning Null<UInt> for an absent value can't be null-checked in the obvious way on cpp, and an absent value is indistinguishable from 0. Found while generating FlatBuffers accessors for optional uint fields.

Ngôn ngữ chính
C++
Star
330
Fork
232
Merge trung bình
3 ngày 5 giờ
Pull request đã merge (30 ngày)
3

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 HaxeFoundation/hxcpp

Tất cả issue của HaxeFoundation/hxcpp

Issue tương tự

Thêm issue về C++

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.