HISE Logo Forum
    • Categories
    • Register
    • Login

    Namespace variable bug

    Scheduled Pinned Locked Moved Bug Reports
    9 Posts 2 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey
      last edited by

      I have a script with a const var called width. I also have a library I'm including, that library has a namespace ui inside the namespace is a function that uses a var called width. This is causing a conflict and producing an already declared error.

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        const var width = 2;
        
        namespace D
        {
            const var width = 5;
            
            Console.print(width);
        }
        

        This works here (prints 5). Can you make a minimal example that's causing the error?

        1 Reply Last reply Reply Quote 1
        • d.healeyD
          d.healey
          last edited by d.healey

          const var width = 2;
          
          namespace D
          {
          	
              var width = 5;
              
              Console.print(width);
          }
          

          The error is Line 6, column 12: Identifier width is already defined as const variable Does this imply that in your version it is actually using the variable outside of the namespace?

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by Christoph Hart

            No, you can't declare simple var variables in a namespace (it will be ignored and just put into the root namespace where it clashes with the const var of the same name). Namespaces are only relevant for const var and reg slots. There's actually no reason to use a var type, except for when you need more than 32 mutable variables in one namespace (or in standard Javascript functions).

            And in my example it prints 5 because the member of the namespace has priority EVEN when the namespace is not explicitly defined (that's the way how C++ works).

            1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey
              last edited by d.healey

              Ah I understand now. I shall use a reg in my case then :)

              What's the advantage of using local with getComponent?

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart
                last edited by

                the scope of local is limited to the inline function, so it's better encapsulated (otherwise you would keep a reference to the widget around and it might cause subtle bugs if you use that name for multiple factory methods).

                1 Reply Last reply Reply Quote 1
                • d.healeyD
                  d.healey
                  last edited by

                  I get an error with this version too

                  const var width = 2;
                  
                  namespace D
                  {
                      reg width = 5;
                      
                      Console.print(width);
                  }
                  

                  Line 6, column 15: Identifier width is already defined as const variable

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  1 Reply Last reply Reply Quote 0
                  • Christoph HartC
                    Christoph Hart
                    last edited by

                    Hmm, it seems like this is an tiny oversight in the parsing code. Is this a real world problem, otherwise I'd like to ignore this edge-case :)

                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by

                      Well it came up in a real world project but I just changed the name of the variable so I think it's safe to acknowledge it and ignore it

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post

                      44

                      Online

                      1.7k

                      Users

                      11.7k

                      Topics

                      101.9k

                      Posts