Skip to content

Disallow usage of ignored _ locals #8182

Description

@Gama11

I'm proposing that the following code should throw "ignored variables cannot be used" errors.

class Main {
	static function main() {
		for (_ in 0...16) {
			trace(_); // error
		}
	}

	static function foo(_) {
		trace(_); // error
	}
}

I think it's a weird situation that _ has special semantics in pattern matching, bind(), and now even diagnostics mode for locals (#8147), but that you can still use them as if they were regular vars. The common convention for this is already that they're "ignored", so actually using a _ var would be considered bad style anyway. If an error is introduced, _ can be properly documented as a laguage feature for locals.

I know that at least Flambe uses _ as an identifer, but that's only on field level I think? So shouldn't be impacted by this.

This might also allow to revisit #4381.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions