-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Add error hint for incorrect stacked indexing #40934
Conversation
This is sort of blocked by #40986 unfortunately. OTOH, maybe we can also merge this like this, since we probably need to move these around in another PR anyways. |
I see a failure:
|
7e726cf
to
a9f34fa
Compare
I think we might also want to put this one in the REPL module? It feels undesirable to me to have too much complexity (and diagnostic hints) accumulating in this particular file. |
Also still showing failures on CI:
|
Where are you seeing that? I see all green checkmarks. |
a9f34fa
to
2faaccc
Compare
2faaccc
to
d0feaab
Compare
Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
Could #53241 be fixed together with this by just widening the cases where the error hint matches a bit? |
Pushed this with my own suggested message - will add the test once it's settled |
Restarting tests once again (apparently this was already done twice before, so maybe the additional failures are really caused by this PR? We'll see!) |
Seems like something else is going on, but I do still need to add tests for the other error hint - was waiting for feedback on if my solution needed any tweaks. |
I would rather merge this, once you have the other test written, than nit pick the wording until this gets forgotten for 3 more years. It does seem we should consider the tone eventually, but that shouldn't hold up this, since we can always rework it later (e.g. do we use questions or make statements, suggest changes to "you" or to "the code", and should the statements be about what you attempted or about what the code interpreted it as doing or what the alternatives are). Looking at the existing messages, we are inconsistent about the style of message, but maybe that is what is sensible anyways, since the reasoning is different for them. |
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
…k/julia into catch-wrong-indexing
Tests added so should be ready to go. |
A common entry level mistake is to try to index a matrix with two sets of brackets, e.g. `a = [1 2; 3 4]; a[1][2] = 5` This will lead to an error that `setindex!()` on the element type of `a` is missing. This PR adds an error hint for the case where a MethodError is raised when `setindex!` is called with a `Number` as the first argument. I considered going broader than numbers, but it seems more likely that this kind of mistake would happen when working with simple number arrays vs. something more advanced. Could also consider if it is possible to do the same for when `getindex()` is called on a `Number`, which emits a BoundsError. Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
A common entry level mistake is to try to index a matrix with two sets of brackets, e.g. `a = [1 2; 3 4]; a[1][2] = 5` This will lead to an error that `setindex!()` on the element type of `a` is missing. This PR adds an error hint for the case where a MethodError is raised when `setindex!` is called with a `Number` as the first argument. I considered going broader than numbers, but it seems more likely that this kind of mistake would happen when working with simple number arrays vs. something more advanced. Could also consider if it is possible to do the same for when `getindex()` is called on a `Number`, which emits a BoundsError. Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
A common entry level mistake is to try to index a matrix with two sets of brackets, e.g.
a = [1 2; 3 4]; a[1][2] = 5
This will lead to an error that
setindex!()
on the element type ofa
is missing.This PR adds an error hint for the case where a MethodError is raised when
setindex!
is called with aNumber
as the first argument.I considered going broader than numbers, but it seems more likely that this kind of mistake would happen when working with simple number arrays vs. something more advanced.
Could also consider if it is possible to do the same for when
getindex()
is called on aNumber
, which emits a BoundsError.