# Building Functions using private types in a macro

**URL:** <https://community.haxe.org/t/building-functions-using-private-types-in-a-macro/3473>\
**Category:** Haxe\
**Tags:** macro\
**Created:** [February 19, 2022, 4:51pm UTC](https://community.haxe.org/t/building-functions-using-private-types-in-a-macro/3473 "2022-02-19T16:51:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EliteMasterEric](https://community.haxe.org/user_avatar/community.haxe.org/elitemastereric/32/1772_2.png) [@EliteMasterEric](https://community.haxe.org/u/EliteMasterEric)\
**Post date:** [February 19, 2022, 4:51pm UTC](https://community.haxe.org/t/building-functions-using-private-types-in-a-macro/3473/1 "2022-02-19T16:51:45Z")

</div>

I am working on a macro which builds overrides to the functions of the target’s superclasses by recursively creating adding new functions with the AOverride access for each function in the parent classes. This works for normal functions so far, but breaks upon hitting a parent function which utilizes a private class. The macro completes but I get a `Type not found : Listener` error just after (referring to `openfl.events.EventDispatcher.Listener`.

It appears that the error occurs when calling `Context.toComplexType(t:haxe.macro.Type)` when the target type is a private class.

In researching this issue, I found the following issue that suggests the problem is unresolved: [missing a way to provide access to private types through a macro · Issue #3589 · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/issues/3589)

Is there a way to use these values properly given that I have access to the corresponding `haxe.macro.Type`?

---

<div class="post-metadata">

**Author:** ![EliteMasterEric](https://community.haxe.org/user_avatar/community.haxe.org/elitemastereric/32/1772_2.png) [@EliteMasterEric](https://community.haxe.org/u/EliteMasterEric)\
**Post date:** [February 19, 2022, 5:44pm UTC](https://community.haxe.org/t/building-functions-using-private-types-in-a-macro/3473/2 "2022-02-19T17:44:04Z")

</div>

Did some more testing. It appears calling just `Context.toComplexType(t)` calls it on the type `Listener`, which it fails to find. Checking for a private type and calling:

```haxe
Context.toComplexType(Context.getType('${t.module}.${t.name}'));

```

will perform a type query on `openfl.events.EventDispatcher.Listener` but that gives a `Cannot access private type Listener in module openfl.events.EventDispatcher`

---

<div class="post-metadata">

**Author:** ![EliteMasterEric](https://community.haxe.org/user_avatar/community.haxe.org/elitemastereric/32/1772_2.png) [@EliteMasterEric](https://community.haxe.org/u/EliteMasterEric)\
**Post date:** [February 19, 2022, 6:18pm UTC](https://community.haxe.org/t/building-functions-using-private-types-in-a-macro/3473/3 "2022-02-19T18:18:29Z")

</div>

I’ve come to the conclusion that private classes are completely inaccessible outside the module they are defined in.

This thankfully means that, for my use case, I can simply skip functions that use these, so the topic of the thread is a moot point.
