Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,427 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend, compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
330
Fork
232
Merge medio
3g 5h
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di HaxeFoundation/hxcpp

Tutte le issue di HaxeFoundation/hxcpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.