Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty enum as haxe.Unit #11563

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src-json/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,13 @@
"platforms": ["flash"],
"internal": true
},
{
"name": "Nullable",
"metadata": ":nullable",
"doc": "Explicitly admits `null` as valid value for an enum, which affects null-safety",
"targets": ["TEnum"],
"links": ["https://haxe.org/manual/types-nullability.html"]
},
{
"name": "NullSafety",
"metadata": ":nullSafety",
Expand Down
2 changes: 2 additions & 0 deletions src/typing/nullSafety.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ let rec is_nullable_type ?(dynamic_is_nullable=false) = function
is_nullable_type (apply_typedef t tl)
| (TDynamic _) as t ->
dynamic_is_nullable && t == t_dynamic
| TEnum(en,_) ->
Meta.has Meta.Nullable en.e_meta
| _ ->
false
(*
Expand Down
29 changes: 29 additions & 0 deletions std/haxe/Unit.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package haxe;

/**
A unit type which can only be `null` at run-time.
**/
@:nullable
enum Unit {}
9 changes: 9 additions & 0 deletions tests/unit/src/unitstd/haxe/Unit.unit.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var u:haxe.Unit = null;
Reflect.isObject(u) == false;
Reflect.isEnumValue(u) == false;
Reflect.isFunction(u) == false;
Reflect.compare(u, null) == 0;
Reflect.compare(null, u) == 0;
Reflect.compare(u, u) == 0;
Type.getClass(u) == null;
Type.getEnum(u) == null;
Loading