Null<UInt> compared with null gives wrong results (null is cast to 0 by UInt's == / != overloads)
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
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của HaxeFoundation/hxcpp
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
HaxeFoundation/hxcpp#1217 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
HaxeFoundation/hxcpp#1431 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Set up clang formatĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
HaxeFoundation/hxcpp#1430 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
HaxeFoundation/hxcpp#1415 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
HXCPP_GC_MOVING crashesĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 47/100
HaxeFoundation/hxcpp#1414 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của HaxeFoundation/hxcpp
Issue tương tự
-
[Docs] CONTRIBUTING still says FreeType 2.14.3 and TabLabel.h says ImGui 1.92.9b after the bumpsCó thể đã có người làm @mgradwohl đã nhận hôm nay. Đang mởagent:WSL documentation LOW
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
build sdl2 fail on ubuntuĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
finalburnneo/FBNeo#2820 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/ysql kind/enhancement priority/medium status/awaiting-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
yugabyte/yugabyte-db#35578 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
cudf-polars feature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 2 ngày
-
(S1 - Need confirmation)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
CleverRaven/Cataclysm-DDA#89212 ·
Maintainer thường phản hồi trong vòng 1 ngày