Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

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

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

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

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
57/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
backend, compilers

調査の方向性

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.

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

説明

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.

主要言語
C++
スター
329
フォーク
230
平均マージ
2日 16時間
マージ済み PR(30日)
4

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

HaxeFoundation/hxcpp のほかの issue

HaxeFoundation/hxcpp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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