HaxeFoundation / HaxeFoundation/haxe

How to compare nullable abstracts?

Open
#9,108 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

I've came across this while trying to use BigInt library: https://github.com/kevinresol/bigint/issues/3
How is it supposed to support nullability when implementing comparision operators in abstract?
Short example:
```haxe
class Foo {
var i: Int;
public function new(i: Int) this.i = i;
public function eq(f: Foo) return this.i == f.i;
}

abstract AFoo(Foo) from Foo {
@:op(A == B) public inline function eq(o:AFoo):Bool return this.eq(cast o);
}

class Main {
public static function main(): Void {
var i: Null = null;
trace(i == null); // this line works but analogous code here does not: https://github.com/kevinresol/bigint/issues/3
trace(i == new Foo(20)); // exception: Cannot read property 'eq' of null
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked BigInt issue and reproduce the supplied `Main.main` example involving `Null` and comparison operators. Determine the intended behavior for nullable abstracts and document or validate the resolution against the reported null exception.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.