DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

Private constructor error without full information #289

Closed Neverbirth closed 6 years ago

Neverbirth commented 6 years ago

Try to instantiate some class with private constructor in Flow, the output is just:

hexdsl/1,0,0-alpha,2/src/hex/compiletime/factory/ClassInstanceFactory.hx:41: characters 28-56 : Cannot access private constructor
hexdsl/1,0,0-alpha,2/src/hex/compiletime/util/ContextUtil.hx:114: lines 114-118 : Defined in this class

No real indication of the Flow file and line.

FrancisBourre commented 6 years ago

This one will be tricky to cover. I'm even unable to catch the error: try var expr = macro new $typePath( $a { args } ) catch(e:Dynamic) trace('Catch it please!');

FrancisBourre commented 6 years ago

The only way I found is to handle it manually for now.

var t =  Context.getType( typePath.pack.join('.') + '.' + typePath.name );
switch( t )
{
    case TInst( t, params ): if ( !t.get().constructor.get().isPublic ) 
        Context.error( 'WTF, you try to instantiate a class with a private constructor!', t.get().constructor.get().pos );
    case _:
}