Skip to content

Proposal: Add must-use to functions that have no purpose being called without handling the return #24

@WolfGangS

Description

@WolfGangS

An "error/smell" allot of linters track is Unused return variable, this is a little similar to pure, but not quite as it doesn't really care about undesirable side effects such as errors, more that the function has no purpose being called if you aren't making use of the returned value.

So adding a concept of must-use or intended-side-effect or similar, would allow for generation of this kind of linting spec.

For instance, llAcos is impure because it can cause an error, but it should probably be marked as must-use: true as there really is no reason to call it, if you don't want the resulting value.

Also useful for more aggressive optimization routines, as they can nix out calls that have no desirable side effect, and who's return values aren't being used.

Proposed addition

diff --git a/lsl_definitions.yaml b/lsl_definitions.yaml
index 96c50a0..c7008bf 100644
--- a/lsl_definitions.yaml
+++ b/lsl_definitions.yaml
@@ -4736,32 +4736,33 @@ events:
 functions:
 
 #  <key>: is the LSL name for the function.
 #    energy: Script energy consumed by the function. (When in doubt just use 10.0)
 #    sleep: Additional sleep time imposed by the script after this function completes.
 #    return: Return type of the function.
 #    arguments: An array of maps of maps describing the parameters to this function.
 #    tooltip: A brief description of this function. Map of maps is used to retain ordering.
 #    func-id: The LSO function identifier, (See comment at the top of this file.)
 #    private: Should this function be omitted from the generated documentation.
 #    deprecated: Has this function been deprecated.
 #    pure: Is the function guaranteed to have no side effects.
 #    native: If true, this function must use a native implementation for non-LSO VMs.
 #    god-mode: If true, this function can only be executed in god mode.
 #    experience: If true, this function requires an experience to be set for the script to compile.
 #    linden-experience: If true, this function requires a linden-owned experience.
+#    must-use: If true, this functions return value should be used, as there is no other reason to call the function
   llAbs:

If this is deemed desirable I'll make a PR with the changes.


This repo is using Opire - what does it mean? 👇
💵 Everyone can add rewards for this issue commenting /reward 100 (replace 100 with the amount).
🕵️‍♂️ If someone starts working on this issue to earn the rewards, they can comment /try to let everyone know!
🙌 And when they open the PR, they can comment /claim #24 either in the PR description or in a PR's comment.

🪙 Also, everyone can tip any user commenting /tip 20 @WolfGangS (replace 20 with the amount, and @WolfGangS with the user to tip).

📖 If you want to learn more, check out our documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions