Null<UInt> compared with null gives wrong results (null is cast to 0 by UInt's == / != overloads)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 57/100
調査の方向性
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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
HaxeFoundation/hxcpp のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
HaxeFoundation/hxcpp#1217 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
HaxeFoundation/hxcpp#1415 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 47/100
HaxeFoundation/hxcpp#1414 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
HaxeFoundation/hxcpp#1396 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
HaxeFoundation/hxcpp#1391 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
HaxeFoundation/hxcpp の issue をすべて見る
似ている issue
-
P2: A timed rotation maneuver does nothing on a ship that had an earlier timed lateral maneuverオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
scp-fs2open/fs2open.github.com#7914 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
eclipse-score/inc_someip_gateway#356 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
HarperFast/rocksdb-js#945 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信