HaxeFoundation / HaxeFoundation/haxe

Disallow usage of ignored `_` locals

Open
#8,182 2 comments 0 reactions 0 assignees View on GitHub
discussion enhancement
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

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

```haxe
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 https://github.com/HaxeFoundation/haxe/issues/4381.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.