HaxeFoundation / HaxeFoundation/haxe

Reflection on primitive types and values seems to be broken/inconsistent

Open
#5,202 11 comments 0 reactions 1 assignee Claimed by @jdonaldson View on GitHub
documentation priority-low strong-belgian-ale
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

1. Std.is() inconsistent when testing primitive types

The haxe doc states **basic types are no classes**: http://haxe.org/manual/types-basic-types.html
**However:**

```haxe
Std.is(Bool, Class); // returns false
Std.is(Int, Class); // returns true => should return false?
Std.is(Float, Class); // returns true => should return false?

Std.is(1, Int); // returns true
Std.is(1, Float); // returns true => should return false
Std.is(1.0, Float); // returns true
Std.is(1.0, Int); // returns true => should return false
```
2. Type.getClass() does not return null for primitive values

The haxedoc of Type.getClass() states:

> Returns the class of `o`, if `o` is a class instance. If `o` is null or of a different type, null is returned.

**However:**

```haxe
Type.getClass(true); // returns some Boolean{} object => should return null per haxedoc
Type.getClass(1); // returns some Number{} object => should return null per haxedoc
Type.getClass(1.0); // returns some Number{} object => should return null per haxedoc
```
3. Bool behaves like a broken enum

```haxe
Std.is(Bool, Enum); // returns true
Type.enumEq(true, true); // works
```

**However:**

```haxe
var e1:Enum = Bool; // doesn't compile
var e2:Enum = Bool; // doesn't compile

Type.allEnums(Bool); // doesn't compile
Type.enumIndex(true); // doesn't compile
Type.enumParameters(true); // doesn't compile
Type.getEnum(true); // doesn't compile
Type.getEnumName(Bool); // doesn't compile
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.