wiremod / wire

Garry's Mod add-on that allows users to wire up components in order to make more elaborate automatic and user-controlled contraptions.
http://www.wiremod.com
Apache License 2.0
549 stars 333 forks source link

False warning when including a file with functions #3096

Closed deltamolfar closed 1 month ago

deltamolfar commented 2 months ago

Describe the bug If you have a function inside of lib file, and then include it in other E2 with @strict - you will get a warning in editor, that 'included file have n warnings', where n == amount of functions inside of included file. But you may have no warnings at all in the included file itself even with strict mode.

To Reproduce Steps to reproduce the behavior:

  1. Create a lib file with at least one function.
  2. Create general E2 with strict mode
  3. Include lib file into strict mode E2
  4. Press validate button on bottom of editor

Expected behavior No warnings lol

Screenshots 2024-07-15_16-18_1 2024-07-15_16-18

Iirc, right before Vurv left - he told that this might originate from strict-mode nested function warnings, as the contents of included file counts as nested code.

Vurv78 commented 1 month ago

Pretty easy fix. IIRC problem is include variables are stored in scope [1] rather than global scope [0] in the table.

Well, assuming having includes in the global scope isn't a problem.. then you'll just have to make that warning check nth_scope + 1 if it's in an included file, which that info should exist.

Edit: I already did this for events, wtf

        self:AssertW(self.scope:IsGlobalScope() or (self.include and self.scope:Depth() == 1), "Events cannot be nested inside of statements, they are compile time constructs. This will become a hard error in the future!", trace)
Vurv78 commented 1 month ago

https://github.com/wiremod/wire/blob/master/lua/entities/gmod_wire_expression2/base/compiler.lua#L682

-       if self.strict and not self.scope:IsGlobalScope() then
+       if self.strict and not (self.scope:IsGlobalScope() or (self.include and self.scope:Depth() == 1)) then