Advertisement

Namespaces can not be resolved well in some cases

Started by May 10, 2018 10:28 AM
14 comments, last by y18a 6 years, 3 months ago

namespace A
{
    class X
    {
      X() { print("X()"); }
    }
}

void X()
{
  auto test = A::X();
}

void main()
{
  X();
}

When preparing and executing the above, we output the following.


>asrun.exe script2.as
script2.as (10, 1) : INFO : Compiling void X()
script2.as (12, 8) : ERR  : Data type can't be 'void'
script2.as (0, 0) : ERR  : Script failed to build

 


auto test = A::X();

The reason for doing this is because it really is `class@ X`. Also, if executed from another namespace as follows, it will be executed normally.


namespace A
{
    class X
    {
      X() { print("X()"); }
    }
}

namespace B
{
  void X()
  {
    auto test = A::X();
  }
}

 

Thanks for reporting the problem. 

I'll look into it as soon as I can.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

I've identified the root cause for this problem. Unfortunately the fix is not trivial, as I'll need to redesign how symbol names are looked up within namespaces. 

I'll fix it, but it will probably take a while.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've fixed this in revision 2522.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


namespace X {
  class A {
    void test() {
    }
  };
  class B : A {
    void test() {
      A::test();
    }
  };
}

Thank you for fixing it.
However, after this fix, the above code now causes a compile error.


script2.as (8, 7) : ERR  : No matching symbol 'A::test'

`X::A::test ()` will compile successfully.

Which revision of AngelScript did you try? I cannot reproduce the problem in revision 2523, which was checked in on Aug 1st. 

 

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

I am sorry, the code I presented was wrong.

If it is the following code it will result in an error.

 


namespace X {
  class A {
    void test() {
    }
  };
}
namespace Y {
  class B : X::A {
    void test() {
      A::test();
    }
  };
}

Previously, this was also successfully compiled.

Ok. I'll investigate it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've fixed this in revision 2524.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for fixing it.
Another problem is that if you run the following code in a debug build, it stops with an exception.


namespace X {
  class A {
    void test()
      {
      }
  };
}

X::A A;
/*
It is the same also as follows.

X::A __a;
X::A@ get_A()
{
  return __a;
}
*/

namespace X {
  class Test {
    void test()
      {
        A.test();
      }
  }
}

Assertion failed: false, file sdk\angelscript\source\as_compiler.cpp, line 9789

Previously, this was able to call `A::test ()`.
Also, if you indicate `::A.test()` in the global scope, you can compile normally.

 

This topic is closed to new replies.

Advertisement