Null<UInt> compared with null gives wrong results (null is cast to 0 by UInt's == / != overloads)
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
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di HaxeFoundation/hxcpp
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
HaxeFoundation/hxcpp#1217 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
HaxeFoundation/hxcpp#1431 ·
I maintainer di solito rispondono entro 1 giorno
-
Set up clang formatAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
HaxeFoundation/hxcpp#1430 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
HaxeFoundation/hxcpp#1415 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
HXCPP_GC_MOVING crashesAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 47/100
HaxeFoundation/hxcpp#1414 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di HaxeFoundation/hxcpp
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement GUI maintainer-review
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
aethersdr/AetherSDR#6681 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add string concatenationAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno