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

Typo #12170

Closed
matthieugomez opened this issue Jul 15, 2015 · 4 comments
Closed

Typo #12170

matthieugomez opened this issue Jul 15, 2015 · 4 comments

Comments

@matthieugomez
Copy link
Contributor

I often write

for i in length(x)

when really I want to write

for i in 1:length(x)

This typo is surprisingly easy to do and hard to spot. Would it be possible to return a warning or an error in the first case?

@ScottPJones
Copy link
Contributor

Does Lint.jl catch that?

@yuyichao
Copy link
Contributor

See #11769

@jakebolewski
Copy link
Member

Unfortunately no, numbers are iterable so for i=length(x) is perfectly valid. Lint.jl can't catch it because all Lint can do is look at the AST, and it can't infer the type that length will return.

@Ken-B
Copy link
Contributor

Ken-B commented Jul 16, 2015

For your information, the NEWS section for v0.4 says "Array iteration should generally be written as for i in eachindex(A) ... end rather than for i = 1:length(A) ... end. (#8432)"

I would think this will fix your typo issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants