HISE Logo Forum
    • Categories
    • Register
    • Login

    Error: Can't declare var statement in inline function

    Scheduled Pinned Locked Moved General Questions
    4 Posts 3 Posters 319 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.
    • ?
      A Former User
      last edited by A Former User

      After the last commits, I get the below error in my project. It was working before. (The latest working version was built on the 6th September)

      Can't declare var statement in inline function
      

      My code structure is like the below:

      inline function myFunction()
      {
          if (......)
          {
              var myvariable1 = false;
              var myvariable2 = false;
          }
      }
      
      
      Matt_SFM 1 Reply Last reply Reply Quote 0
      • Matt_SFM
        Matt_SF @A Former User
        last edited by Matt_SF

        @Steve-Mohican indeed this happened in the latest commit, but you shouldn't use vars in in-line functions. Use locals instead.

        Develop branch
        Win10 & VS17 / Ventura & Xcode 14. 3

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

          Yes this is deliberate. If you're not using local variables, they will spill to the outside scope with very unpredictable side effects.

          inline function whatHappensInsideThisFunctionStaysInsideThisFunction()
          {
              var secret = 90;
          }
          
          whatHappensInsideThisFunctionStaysInsideThisFunction();
          
          Console.print(secret); // Ouch...
          
          ? 1 Reply Last reply Reply Quote 3
          • ?
            A Former User @Christoph Hart
            last edited by

            @Christoph-Hart @Matt_SF I'll fix this thank you.

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

            58

            Online

            1.7k

            Users

            11.7k

            Topics

            101.7k

            Posts