Type name X is redefined from module Y

203 views
Skip to first unread message

T1m_

unread,
Aug 23, 2017, 8:43:16 AM8/23/17
to Haxe
Foo.hx
package;
class Foo
{
   
public function new()
   
{
       
new Foo.SubModule();
   
}
}
class SubModule
{
   
public function new (){}
}

Bar.hx
package;
class Bar
{
   
public function new()
   
{
       
new Bar.SubModule();
   
}
}
class SubModule
{
   
public function new(){}
}

Main.hx
package;

import js.Lib;

class Main
{
   
static function main()
   
{
       
new Foo();
       
new Bar(); // src/Main.hx:10: characters 6-9 : Type name SubModule is redefined from module Foo
   
}
}

Compile error:
src/Main.hx:10: characters 6-9 : Type name SubModule is redefined from module Foo

To avoid this I can rename one of the SubModule to something like SubModule2. But I'd like to know is it a haxe bug or I miss something? Error in both 3.4.2 stable and 3.4.2 (ada466c) nightly.

Dan Korostelev

unread,
Aug 23, 2017, 8:51:04 AM8/23/17
to Haxe
No, it's working as designed (even if a bit confusing) - types in Haxe are placed in packages, and modules (.hx files) contribute types to packages, so you can't have two types with the same name inside the same package, even if they are from different modules.
You can mark the type with `private` keyword tho, then it'll be placed in a special package generated for current module and will be accessible only from within this module.

среда, 23 августа 2017 г., 15:43:16 UTC+3 пользователь T1m_ написал:

T1m_

unread,
Aug 23, 2017, 9:16:07 AM8/23/17
to Haxe
Thanks for clarification! Also, finally I found info about this in manual. I had to read this in first.
Reply all
Reply to author
Forward
0 new messages