Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 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
12 changes: 12 additions & 0 deletions src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ let load_array ctx =
with Exit ->
()

let load_unit ctx =
let m = TypeloadModule.load_module ctx (["haxe"],"Unit") null_pos in
List.iter (fun mt -> match mt with
| TEnumDecl en ->
(match snd en.e_path with
| "Unit" ->
ctx.m.import_resolution#add (module_type_resolution mt None null_pos);
| _ -> ())
| _ -> ()
) m.m_types

let load_enum_tools ctx =
let m = TypeloadModule.load_module ctx (["haxe"],"EnumTools") null_pos in
match m.m_types with
Expand Down Expand Up @@ -179,6 +190,7 @@ let create com macros =
load_string ctx;
load_std ctx;
load_any ctx;
load_unit ctx;
load_array ctx;
load_enum_tools ctx;
ignore(TypeloadModule.load_module ctx (["haxe"],"Exception") null_pos);
Expand Down
30 changes: 30 additions & 0 deletions std/haxe/Unit.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.
**/
enum Unit {
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 = Unit;
Reflect.isObject(u) == false;
Reflect.isEnumValue(u) == true;
Reflect.isFunction(u) == false;
Reflect.compare(u, Unit) == 0;
Reflect.compare(Unit, u) == 0;
Reflect.compare(u, u) == 0;
// Type.getClass(u) == null;
Type.getEnum(u) == haxe.Unit;
Loading