Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow usage of ignored _ locals #8182

Open
Gama11 opened this issue Apr 18, 2019 · 2 comments
Open

Disallow usage of ignored _ locals #8182

Gama11 opened this issue Apr 18, 2019 · 2 comments

Comments

@Gama11
Copy link
Member

Gama11 commented Apr 18, 2019

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.

@terurou
Copy link
Member

terurou commented Apr 18, 2019

I hope this proposal will be approved. (related #8076)

@Gama11
Copy link
Member Author

Gama11 commented Apr 18, 2019

@terurou Thanks, I had forgotten about that issue actually. So yeah, if the compiler was a bit stricter here, it could definitely help avoid some confusion.

@Simn Simn added this to the Design milestone May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants